将按钮放在中间位置
问题描述:
大家好,
我有一个要求,我连续5 td,每个td包含一个按钮。
但是我必须在某些条件下显示几个按钮。那么如何在行的中心显示按钮。我的意思是要安排按钮,使它们居中。假设两个按钮可见,那么它应该居中。
Hi All,
I have a requirement where in a row I have 5 td and each td contain a button.
but I have to show few buttons in certain conditions.so how can I show the buttons in the center of the row.I mean want to arrange the buttons so that they will be centered.suppose two buttons are visible then it should be centered.
<div>
<table style="width: 100%">
<tr>
<td align="center">
<table>
<tr>
<td style="width: 20%" id="tda" runat="server">
<asp:Button ID="btnA" Text="A" runat="server" Width="100px" />
</td>
<td style="width:1px">
</td>
<td style="width: 20%" id="tdb" runat="server">
<asp:Button ID="ButtonB" Text="B" runat="server" Width="100px" />
</td>
<td style="width:1px">
</td>
<td style="width: 20%" id="tdc" runat="server">
<asp:Button ID="ButtonC" Text="C" runat="server" Width="100px" />
</td>
<td style="width:1px">
</td>
<td style="width: 20%" id="tdd" runat="server">
<asp:Button ID="ButtonD" Text="D" runat="server" Width="100px" />
</td>
<td style="width:1px">
</td>
<td style="width: 20%" id="tde" runat="server">
<asp:Button ID="ButtonE" Text="E" runat="server" Width="100px" />
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="center">
<asp:Button id="btnX" runat="server" Text="check" onclick="btnX_Click"/>
</td>
</tr>
</table>
</div>
和我的aspx文件中的代码如下
And the code in my aspx file is as below
protected void btnX_Click(object sender, EventArgs e)
{
//on certain conditions i want only tda and tde should be visible
//but once i do this i get space between these two buttons
tda.Visible = true;
tdb.Visible = false;
tdc.Visible = false;
tdd.Visible = false;
tde.Visible = true;
}
答
你开始以错误的方式从一开始。请停止在HTML中使用style
和其他格式属性,将其全部移至CSS。
请参阅:
http://www.w3schools.com/css/css_align.asp [ ^ ],
http://www.w3schools.com/cssref/pr_text_text-align.asp [ ^ ],
http://www.w3.org/Style/Examples/007/center.en.html [ ^ ],
http://www.w3.org/TR/css3-align/ [ ^ ]。
此外,您的要求不明确。中心相对于什么?一排?如果你连续有一个以上的元素,那是不可能的,因为这意味着这些元素会在中心重叠,这是不会发生的,除非你想使用绝对定位(不推荐)。也许,每行只有一个元素,或者你的意思是其他东西,比如相对于td
的居中。但是不要澄清它。首先,尝试以正确的方式自己定义合适的样式,如果你真的遇到问题,可以提出另一个问题。-SA
You started working in a wrong way from the very beginning. Please stop usingstyle
and other formatting attributes in HTML, move it all to CSS.
Please see:
http://www.w3schools.com/css/css_align.asp[^],
http://www.w3schools.com/cssref/pr_text_text-align.asp[^],
http://www.w3.org/Style/Examples/007/center.en.html[^],
http://www.w3.org/TR/css3-align/[^].
Also, your requirement is not clear. Center relative to what? A row? If you have more then one element in a row, it's not possible, as it would mean that these elements would overlap at the center, which is not going to happen, unless you want to use absolute positioning (not recommended). Maybe, you have only one element per row, or you mean something else, such as centering relative totd
. But don't clarify it yet. First, try to defined proper styles in a right way by yourself and ask another question if you really face a problem.—SA
要在中心定位按钮,你可以使用这样的html中心标签。
For positioning the button on the center you can use html center tag like this.
<center><input type="button" /></center>