html - 文本和下划线的 CSS 定位
问题描述
我正在尝试实现以下效果,但是在定位文本并使下划线转到屏幕末尾时遇到了一些麻烦。
.header {
height: 550px;
width: 100%;
background-color: #1F2041;
position: relative;
}
.header h1, .header h2{
color: white;
font-size: 52px;
text-transform: uppercase;
margin-bottom: 20px;
border-bottom: 1.5px solid currentColor;
line-height: 0.7;
position: absolute;
top: 210px;
}
.header p {
margin-top: 40px;
color: white;
}
<div class="header">
<h2>About</h2>
<h2>Nikola</h2>
<p>Simple. Modern. Yours.</p>
</div>
解决方案
尝试这样的事情,使用浮动和清除。根据需要调整 400px 的大小。也许这种方式 (float) 不是最好的方式,并且可能首选仅使用边距,但请尽量避免使用position: absolute
,否则元素可能会快速重叠。
.header {
height: 550px;
width: 100%;
background-color: #1F2041;
text-align: right;
}
.header * {
float: right;
clear: right;
width: 400px;
text-align: left;
color: white;
margin: 0 0 20px;
}
.header h1, .header h2{
color: white;
font-size: 52px;
text-transform: uppercase;
border-bottom: 1.5px solid currentColor;
}
<div class="header">
<h2>About</h2>
<h2>Nikola</h2>
<p>Simple. Modern. Yours.</p>
</div>
推荐阅读
- python - 为什么 Python 代码没有在 GPU 上实现?已安装 TensorFlow-gpu、CUDA、CUDANN
- python - Python 如何将正则表达式匹配的输出写入新的文本文件?
- java - 在 DynamoDB 中查询非主键属性
- amazon-web-services - lambda 中的 AWS SQS 操作在冷启动时花费的时间太长
- mongodb - 将外部硬盘上的 MongoDB 转储传输到谷歌云平台
- php - 搜索 meta_key 并在 stdclass 中获取它的 meta_value
- python - 当我安装了 2 个不同的 Python 版本时安装 Pygame
- java - 生成授权 ID
- python - 在 n 个时间序列中搜索相等值的区间
- awk - 按 4 列比较两个文件(通过不同的分隔符)并返回所需的输出