【发布时间】:2018-08-15 18:31:31
【问题描述】:
我想要一个带有双边框的 h2 元素。目前我有这个sn-p,HTML+CSS:
h2.titulo {
width: 100%;
margin: 10px 0;
padding: 10px 0;
text-transform: uppercase;
font-weight: 400;
font-size: 30px;
display: block;
color: #8c2638;
border-bottom: 1px solid #ccc;
font-size: 25px;
}
h2.titulo span {
padding: 11px 0;
font-size: 19px;
font-size: 25px;
border-bottom: 1px solid #8c2638;
}
<h2 class="titulo"><span>My title</span></h2>
我希望这个标题具有响应性,当我的标题很长时,我认为最好的方法是 text-overflow: ellipsis 和 overflow:hidden。我试过这个,但隐藏在 h2 上的溢出使红色边框底部消失:
h2.titulo {
width: 100%;
margin: 10px 0;
padding: 10px 0;
text-transform: uppercase;
font-weight: 400;
font-size: 30px;
display: block;
color: #8c2638;
border-bottom: 1px solid #ccc;
font-size: 25px;
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
}
h2.titulo span {
padding: 11px 0;
font-size: 19px;
font-size: 25px;
border-bottom: 1px solid #8c2638;
}
<h2 class="titulo"><span>A very very very very very very very very long long title</span></h2>
最接近的方法是这样,但红色边框与另一个边框不完全折叠:
h2.titulo {
border-bottom: 1px solid #ccc;
font-size: 25px;
width: 100%;
margin: 10px 0;
padding: 0;
text-transform: uppercase;
font-weight: 400;
font-size: 30px;
display: block;
color: #8c2638;
overflow-x: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
h2.titulo span {
display: inline-block;
line-height: 100%;
padding-bottom: 10px;
border-bottom: 1px solid #8c2638;
}
<h2 class="titulo"><span>Normal title</span></h2>
和margin-bottom:-1px;由于溢出,在跨度上不起作用。请问有什么办法吗?
【问题讨论】: