css h1 - 只与文本一样宽 [英] css h1 - only as wide as the text

查看:131
本文介绍了css h1 - 只与文本一样宽的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网站有H1样式:

.centercol h1 {
    color: #006bb6;
    font-weight: normal;
    font-size: 18px;
    padding:3px 3px 3px 6px;
    border-left:3px solid #c6c1b8;
    background:#f2efe9;
    display:block;
}

背景颜色跨越了centercol的整个宽度,500px ...

The background color spans the entire width of the centercol, 500px...

如何使H1只跨越H1的文本宽度?

How do I make this H1 only span the width of the text of the H1?

推荐答案

您可以使用inline-block值来显示,但是在这种情况下,您将松开h1的块特性,即如果它们是内联元素,兄弟元素将与h1并排显示(在这种情况下,您可以使用

You can use the inline-block value for display, however in this case you will loose the block feature of h1 i.e. the siblings will be displayed inline with h1 if they are inline elements(in which case you can use a line-break
).

display:inline-block; 

这篇关于css h1 - 只与文本一样宽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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