首页 > 解决方案 > 如何使css中文本的bg颜色跨越整个屏幕的宽度

问题描述

我从 html 和 css 开始,想知道如何给一行文本设置背景颜色。例如 :

#python-heading {
    font-family: 'Arvo', serif;
    position: absolute;
    bottom: 600px;
    left: 600px;
    background-color: #DEE0D9;
}
<body>
        <header>
            <span><h1 id="python-heading">Python</h1></span>
            <h2 id="python-subheading">Subtitle</h2>
        </header>
</body>

但我的文字不是文字后面的整个区域。我的意思是我想要这样:

连字符 => bg 颜色

- - - - - - - - - - - - - - - - - - - - - -文本 - - - --------------------------------------------------

但它是这样的:

                                      -text-

我需要更改/添加什么?

标签: htmlcss

解决方案


我认为您应该避免使用h1insidespan并简单地h1跟随代码更改。(如果我正确理解了您的问题,那么这可能会有所帮助)

#python-heading {
    background-color: #DEE0D9;
    text-align:center;
}
<header>
 <h1 id="python-heading">Python</h1>
 <h2 id="python-subheading">Subtitle</h2>
</header>


推荐阅读