在 asp.net 中两个并排按钮之间放置空间的最简单方法是什么
我有两个并排的按钮,我想在它们之间放一些按钮。
以下代码将有 2 个彼此相邻的按钮。我尝试了 div 的边距,但无法在两者之间获得一些合适的空间。
<div style="text-align: center">
<asp:Button ID="btnSubmit" runat="server" Text="Submit" Width="89px" OnClick="btnSubmit_Click" />
<asp:Button ID="btnClear" runat="server" Text="Clear" Width="89px" OnClick="btnClear_Click" />
</div>
I have 2 buttons side by side, and I would like to have some inbetween them.
Following code will have 2 buttons right next to each other. I have tried margin for the div, and just couldn't get some nice space between the two.
<div style="text-align: center">
<asp:Button ID="btnSubmit" runat="server" Text="Submit" Width="89px" OnClick="btnSubmit_Click" />
<asp:Button ID="btnClear" runat="server" Text="Clear" Width="89px" OnClick="btnClear_Click" />
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(13)
创建一个分隔符类,如下所示:
然后将其附加到两个按钮之间的 div
这是最好的方法,因为它避免了盒模型,这对于旧浏览器来说可能是一个痛苦,并且不会添加任何会被选取的额外字符由屏幕阅读器显示,因此可读性更好。
对于某些场景来说,拥有许多此类类型的 div 是件好事(我最常用的是 vert5spacer,与此类似,但放置了一个高度为 5 且宽度为 auto 的块 div,用于分隔表单中的项目等。
create a divider class as follows:
Then attach this to a div between the two buttons
This is the best way as it avoids the box model, which can be a pain on older browsers, and doesn't add any extra characters that would be picked up by a screen reader, so it is better for readability.
It's good to have a number of these types of divs for certain scenarios (my most used one is vert5spacer, similar to this but puts a block div with height 5 and width auto for spacing out items in a form etc.
在它们之间添加一个空格
(或更多,具体取决于您的偏好)
Add a space
between them (or more depending on your preference)
或者向按钮添加一个类并具有:
这可以实现这一点 - http://jsfiddle.net/QU93w/
Or add a class to the buttons and have:
This achieves this - http://jsfiddle.net/QU93w/
老帖子,但我想说最干净的方法是向周围的 div 添加一个类,并在每个按钮上添加一个按钮类,以便您的 CSS 规则对更多用例有用:
Old post, but I'd say the cleanest approach would be to add a class to the surrounding div and a button class on each button so your CSS rule becomes useful for more use cases:
尝试将以下类放在您的第二个按钮上
编辑:
如果您希望第一个按钮与 div 以及第二个按钮间隔开,则将该类应用于您的第一个按钮也是。
Try putting the following class on your second button
Edit:
If you want your first button to be spaced from the div as well as from the second button, then apply this class to your first button also.
我使用了
并且它工作正常。你可以尝试一下。
您不需要使用引号
I used
and it is working fine. You could try it.
You do not need to use the quotation marks
如果您使用 bootstrap,请将 ml-3 添加到第二个按钮:
If you are using bootstrap, add ml-3 to your second button:
还有另一种方法:
您可以使用 width 属性调整空间量。
你的代码是:
There is another way of doing so:
<span style="width: 10px"></span>
You can adjust the amount of space using the width property.
Your code would be:
你能只吃一些
吗?
Can you just just some
?
如果您希望样式全局应用,您可以使用 css 中的相邻同级组合器。
这是一个小提琴: https://jsfiddle.net/caeLosby/10/
它类似于一些现有的答案,但它没有设置第一个按钮的边距。
例如,在这种情况下,
只有
btn2
将获得边距。有关更多信息,请参阅 https://developer.mozilla.org/en- US/docs/Web/CSS/Adjacent_sibling_combinator
If you want the style to apply globally you could use the adjacent sibling combinator from css.
Here is a fiddle: https://jsfiddle.net/caeLosby/10/
It is similar to some of the existing answers but it does not set the margin on the first button.
For example in the case
only
btn2
will get the margin.For further information see https://developer.mozilla.org/en-US/docs/Web/CSS/Adjacent_sibling_combinator
您可以使用
btnSubmit::before { margin-left: 20px; }
you can use
btnSubmit::before { margin-left: 20px; }
通过引导 CSS,我们有一个“btn-toolbar”类。
https://getbootstrap.com/docs/4.0/components/button -group/#button-toolbar
With the bootstrap CSS, we have a 'btn-toolbar' class.
https://getbootstrap.com/docs/4.0/components/button-group/#button-toolbar