html - 边框底部和标题一起移动
问题描述
在我的导航中,我用一些文本和一条水平线分隔我的部分。对于每个部分,这都会重复。我这样做如下所示:
.navSectionHeader {
font-size: 1em;
color: #fff;
margin-left: 5px;
margin-bottom: 10px;
font-family: "Roboto";
font-weight: 700 !important;
border-bottom: 2px solid #6c6c6c;
}
/*.navSectionHeader::after {
content: ' ';
display: block;
border: 2px solid;
border-color: #6c6c6c;
margin-left: 0px !important;
}*/
问题是,我的文本现在几乎粘在父 div 的左侧。它应该在左边有一些边距,同时保持底部边框从左边 0px 开始。当我尝试移动它时,margin-left: 5px;
它最终border-bottom
也会移动。我尝试了这个,::after
如注释中所示,添加!important
到最后但没有任何变化。我这样做是错误的吗?对不起,我是前端菜鸟!
编辑:<span>
如果它有所作为,则部分标题位于 a 中。
解决方案
使用padding
而不是margin
.
.navSectionHeader {
padding-left: 5px;
}
一个看到差异的例子,
div {
display: inline-block;
width: 100px;
height: 20px;
border-bottom: 1px solid black;
background: red;
color: white;
}
.padding {
padding-left: 5px;
}
.margin {
margin-left: 5px;
}
<div class="margin">margin</div><br>
<div class="padding">padding</div>
推荐阅读
- python - Apache Ignite C++ 结构到 Pyignite 对象不起作用
- google-apps-script - Google Apps Script Compare Active User to Array
- r - 如何更改 statebins 地图的颜色?
- symfony - Symfony 控制台部分未清除所有行
- python-3.x - How to print class variables in a list
- java - java中如何将一个对象映射到另一个对象
- c# - JSON写入文件问题如何删除引号
- android - Unity 中的 Android 插件 - 无返回值
- java - PostgreSQL '数据库不存在' - Java Spring Boot、Flyway、Docker/PostgreSQL
- java - 使用 Jackson 从 XML 创建自定义对象