h1背景颜色 [英] h1 background color

查看:280
本文介绍了h1背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


我正在使用CSS将背景应用于标题:


< h1>标题< / h1>


h1 {background-color:black;}


问题是背景颜色不仅适用于

文本但是对于h1的全长。

如何仅将其应用于标题文本?


谢谢,

Miguel

Hello,

I am using CSS to apply a background to a header:

<h1>Header</h1>

h1 {background-color: black;}

The problem is that the background color is applied not only to the
text but to the full lenght of the h1.
How to apply it only to the header text?

Thanks,
Miguel

推荐答案

shapper写道:
shapper wrote:

你好,


我使用CSS将背景应用于标题:


< h1>标题< / h1>


h1 {background-color:black;}


问题是背景颜色不仅适用于

文本,还适用于完整长度的h1。

如何仅将其应用于标题文本?


谢谢,

Miguel
Hello,

I am using CSS to apply a background to a header:

<h1>Header</h1>

h1 {background-color: black;}

The problem is that the background color is applied not only to the
text but to the full lenght of the h1.
How to apply it only to the header text?

Thanks,
Miguel



< h1>< span> Header< / span>< / h1& gt;

h1 span {background-color:black;}

<h1><span>Header</span></h1>
h1 span{background-color: black;}


shapper写道:
shapper wrote:

您好,


我正在使用CSS将背景应用于标题:


< h1>标题< / h1> ;


h1 {background-color:black;}


问题是背景颜色不仅适用于

文本但是对于h1的完整长度。

如何仅将其应用于标题文本?
Hello,

I am using CSS to apply a background to a header:

<h1>Header</h1>

h1 {background-color: black;}

The problem is that the background color is applied not only to the
text but to the full lenght of the h1.
How to apply it only to the header text?



默认情况下应该这样做。她是您的选择:


1)明确设置


h1 {color:white;背景颜色:黑色;宽度:3.25em; }


PROS:如果您使用ems,您希望跨浏览器设置宽度并且将与字体成比例。


缺点:必须根据内容的长度进行调整


2)使用浮动,将自动调整宽度:


h1 {color:white;背景颜色:黑色;向左飘浮; }


PROS:你希望用大多数浏览器做什么


缺点:改变文件流量,需要在H1之后清除浮动。

如果页面上还有其他漂浮的元素,可能会影响布局。

IE因浮标'抽搐'而臭名昭着


3)将表格更改为表格单元格...


h1 {color:white;背景颜色:黑色;显示:table-cell; }


PROS:完全符合您的要求,但让IE脱离图片


缺点:虽然这将是完美的解决方案在IE的市场上,这将是一个很难实现的案例(即使从设计师的角度来看,b b b b bb,生活也会很棒) IE会消失...)


-

保重,


Jonathan
-------------------

LITTLE WORKS STUDIO
http://www.LittleWorksStudio.com


Harris Kosmidhs写道:
Harris Kosmidhs wrote:

< h1>< span> Header< / span>< / h1>

h1 span {background-color:black;}
<h1><span>Header</span></h1>
h1 span{background-color: black;}



好​​一个!我想念那一个。我会指出那些不好的OP

练习设置背景而不设置前景。使用

默认前景色为黑色,上面的例子会给你一个

黑盒子。如果你做得恰到好处


h1 span {color:white;背景颜色:黑色; }


问题永远不会出现。


-

小心,


Jonathan

-------------------

小作品工作室
< a rel =nofollowhref =http://www.LittleWorksStudio.comtarget =_ blank> http://www.hittleWorksStudio.com


这篇关于h1背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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