html - 如何使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-
我需要更改/添加什么?
解决方案
我认为您应该避免使用h1
insidespan
并简单地h1
跟随代码更改。(如果我正确理解了您的问题,那么这可能会有所帮助)
#python-heading {
background-color: #DEE0D9;
text-align:center;
}
<header>
<h1 id="python-heading">Python</h1>
<h2 id="python-subheading">Subtitle</h2>
</header>
推荐阅读
- matlab - 有没有办法使用 Matlab 将多个文本文件中的列组合成一个文本文件?
- azure-ad-b2c - 为什么 SSO 对于 Azure AD B2C 自定义策略无法正常工作
- azure - 在 Azure Application Insights 中遇到异常时自动在 Azure 板中生成错误项
- firebase - 命令“npm run build”未在 VueJS 项目上创建正确的构建
- python - 使用漂亮的汤或python中的任何其他方法解析Autosar arxml
- java - 从对象获取信息时为什么会出现 StackOverflowError?
- laravel - 搜索laravel中的所有列得到错误的值
- javascript - 如何以更好的方式更新状态
- javascript - ReactJS:无法读取属性
- c# - Xamarin Button Click 事件失败与 Android 模拟器