我在文本下面有一个边框底部(下面的示例为“内部利益相关者通信”),并且单词break会导致边框对于新宽度而言太大。改进CSS实现的最佳实践是什么?
.cont {
width: 250px;
}
.tab-title {
border-bottom: 2px solid transparent;
margin-bottom: 0px;
padding-bottom: 3px;
color: #1573a4;
opacity: .89;
font-size: 18px;
line-height: .9;
letter-spacing: -.3px;
font-weight: 300;
}
.tab-title-active {
border-bottom: 2px solid #1573a4;
color: #1573a4;
opacity: 1;
font-weight: normal;
font-style: normal;
font-stretch: normal;
line-height: .9;
letter-spacing: -.3px;
}
.tabs-container div:last-child {
text-align: right;
}
.tabs-container {
width: 100%;
border-bottom: .5px solid #e0e0e0;
display: flex;
justify-content: space-between;
}
<div class="cont">
<div class="tabs-container">
<div><h3 class="tab-title">Tab 1</h3></div>
<div><h3 class="tab-title tab-title-active">Internal Stakeholder Communications</h3></div>
</div>
答案 0 :(得分:0)
您可以将max-width
分配给.tab-title-active
或tab-title
类,以确保宽度不超过中心值。
.cont {
width: 250px;
}
.tab-title {
border-bottom: 2px solid transparent;
margin-bottom: 0px;
padding-bottom: 3px;
color: #1573a4;
opacity: .89;
font-size: 18px;
line-height: .9;
letter-spacing: -.3px;
font-weight: 300;
}
.tab-title-active {
border-bottom: 2px solid #1573a4;
color: #1573a4;
opacity: 1;
font-weight: normal;
font-style: normal;
font-stretch: normal;
line-height: .9;
letter-spacing: -.3px;
max-width: 150px;
}
.tabs-container div:last-child {
text-align: right;
}
.tabs-container {
width: 100%;
border-bottom: .5px solid #e0e0e0;
display: flex;
justify-content: space-between;
}
<div class="cont">
<div class="tabs-container">
<div><h3 class="tab-title">Tab 1</h3></div>
<div><h3 class="tab-title tab-title-active">Internal Stakeholder Communications</h3></div>
</div>
答案 1 :(得分:-1)
.cont {
width: 250px;
}
.tab-title {
border-bottom: 2px solid transparent;
margin-bottom: 0px;
padding-bottom: 3px;
color: #1573a4;
opacity: .89;
font-size: 18px;
line-height: .9;
letter-spacing: -.3px;
font-weight: 300;
}
.tab-title-active {
border-bottom: 2px solid #1573a4;
color: #1573a4;
opacity: 1;
font-weight: normal;
font-style: normal;
font-stretch: normal;
line-height: .9;
letter-spacing: -.3px;
}
.tabs-container div:last-child {
text-align: right;
}
.tabs-container {
width: 100%;
border-bottom: .5px solid #e0e0e0;
display: flex;
justify-content: space-between;
}
&#13;
<div class="cont">
<div class="tabs-container">
<div><h3 class="tab-title">Tab 1</h3></div>
<div style="max-width: 57%;"><h3 class="tab-title tab-title-active">Internal Stakeholder Communications</h3></div>
</div>
&#13;