我在想如何让文本后面跟着一个按钮,然后是更多的文本,都在同一行上?就像这样:
<h3>Some</h3>
<button>Text</button>
<h3>!</h3>
<h3>
都是块级元素,块级元素占据其父元素(容器)的整个空间。您可以通过将其重置为display: inline
、 display: inline-block
(建议使用)、display:inline-table
甚至使用 flexbox、float等多种方式进行修改。<h3>
,而是使用<span>
标签或纯文本会是更好的选择。
h3 {
display: inline-block;
margin: 0;
}
<h3>Some</h3>
<button>Text</button>
<h3>!</h3>
<hr>
<span>Some</span>
<button>Text</button>
<span>!</span>
<hr>
Some
<button>Text</button>
!
<h3>Hello <button>Say Hello</button> World</h3>
a
标签。例如,如果您使用了Bootstrap,则可以使用Some <a class="btn btn-primary">Text</a>!
。只要您不需要使用特定于button
标签的样式,这应该是有效的。试试这个:
.ele_inline {
display: inline
}
<h3 class="ele_inline">Some</h3>
<button class="ele_inline">Text</button>
<h3 class="ele_inline">!</h3>
display:inline
添加到块元素中,或者使用内联元素。或者将它们包装在span
中。 - Mike B