如何防止< H1>占用比他们需要更多的宽度 [英] How to prevent <H1>'s from taking up more width than they need
问题描述
如果我制作< h1>
标题,默认情况下,其宽度设置为100%。有没有办法确保将其宽度设置为尽可能最小的值?我需要这个来做特殊的CSS边框。
If I make an <h1>
title, its width is set to 100% by default. Is there a way to make sure its width is set to the smallest value possible? I need this to do special CSS stuff with borders.
推荐答案
你可以给它 display:inline
,这会使它表现得像任何文本元素一样( h1
的缺省值是 display:block
>)。还有其他一些方法 - 例如 float:left
- ,但我觉得这是最简单的方法,也是副作用最少的方法。
You can give it display: inline
, this will make it behave like any text element (The default for h1
is display: block
). There are other ways - float: left
for example - , but I find this the simplest and the one with the fewest side effects.
请注意,您可能需要添加< br>
以确保在h1之后换行。
Note that you will then probably have to add a <br>
to ensure a line break after the h1.
这篇关于如何防止< H1>占用比他们需要更多的宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!