如何防止< H1>占用比他们需要更多的宽度 [英] How to prevent <H1>'s from taking up more width than they need

查看:86
本文介绍了如何防止< H1>占用比他们需要更多的宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我制作< 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.

这篇关于如何防止&lt; H1&gt;占用比他们需要更多的宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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