如何防止标题(< h1>)占用超出其所需宽度的宽度? [英] How to prevent headings (<h1>) from taking up more width than they need?

查看:111
本文介绍了如何防止标题(< h1>)占用超出其所需宽度的宽度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我定义一个标题,例如<h1>,则默认情况下其宽度设置为100%.

If I define a heading like <h1>, its width is set to 100% by default.

是否有办法确保其宽度设置为可能的最小值?

Is there a way to make sure its width is set to the smallest value possible?

推荐答案

您可以给它display: inline.这将使其表现得像任何文本元素一样-<h1>的默认值为display: block.

You can give it display: inline. This will make it behave like any text element - the default for <h1> is display: block.

还有其他方法:例如float: left,但我发现这是最简单的方法,副作用最少.

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>.

这篇关于如何防止标题(&lt; h1&gt;)占用超出其所需宽度的宽度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆