How can I place two headings next to each other using CSS?

风流意气都作罢 提交于 2021-02-04 22:10:03

问题


<h5>Category</h5><h6>auto</h6>

places Category and auto on separate lines, like this:

Category

auto

How can I place them both on the same line, like this?

Category auto


回答1:


h(n) elements are 'block' elements, which means they will grow to take all available horizontal space. This also means they will push anything "right" of them down to the next line.

One easy way to accomplish this is to set their display to inline:

<style>
    h5, h6 {display:inline;}
</style>

Note that inline-block is not supported in all browsers.

You can also float block elements, but that can become a sticky issue as floating can be fairly complex. Stick with inline for cases like this.




回答2:


<h5 style="display:inline-block;">Category</h5>
<h6 style="display:inline-block;">auto</h6>



回答3:


You must change the display mode of the elements. H tags are rendered as BLOCK elements by default. To override this behavior add the following style definitions to your website or CSS

h5,h6 { display: inline; } 

You can also decide to let them "float" next to each other you can do that via:

h5,h6 { float: left; } 

Please note that floating only works on block elements (so using both styles will perform no float because inline elements cannot float).



来源:https://stackoverflow.com/questions/1294328/how-can-i-place-two-headings-next-to-each-other-using-css

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!