2
A
답변
7
:after
이 이용 가능하다 : 가상 소자.
당신이 응답에 대한 백분율 단위로 div
의 width
을 설정하려면
div {
font-size: 15px;
width: 300px;
line-height: 30px;
}
span {
position: relative;
}
span:after {
position: absolute;
content: '2';
width: 100%;
height: 100%;
top: 100%;
left: 0;
border-top: 1px solid black;
text-align: center;
font-size: 9px;
line-height: 15px;
}
<div>over the <span>Triangle, a few months later,</span> another plane disappeared. A ship named the Sandra.</div>
white-space: pre
을 설정하여
span
에 줄 바꿈을 피할 수 있습니다. 아래 예에서
Fiddle
상기
width
는이를 보여 25%
로 설정되어있다. 또한
div {
font-size: 15px;
width: 25%;
line-height: 30px;
}
span {
position: relative;
white-space: pre;
}
span:after {
position: absolute;
content: '2';
width: 100%;
height: 100%;
top: 100%;
left: 0;
border-top: 1px solid black;
text-align: center;
font-size: 9px;
line-height: 15px;
}
<div>over the <span>Triangle, a few months later</span>, another plane disappeared. A ship named the Sandra.</div>
attr()
기능을 사용할 수 있습니다 : 의사 요소가 추가됩니다. @chipChocolates 당신이 CSS 스타일 블록에 첨자를 넣어하지 않으려면, 대답, 오히려 당신이 그들을 필요로 몸에서 사용할 사용
div {
font-size: 15px;
width: 50%;
line-height: 30px;
}
span {
position: relative;
white-space: pre;
}
span:after {
position: absolute;
content: attr(data-num);
width: 100%;
height: 100%;
top: 100%;
left: 0;
border-top: 1px solid black;
text-align: center;
font-size: 9px;
line-height: 15px;
}
<div>over the <span data-num="2">Triangle, a few months later</span>, another plane disappeared. A ship named the Sandra.</div>
2
...
div {
font-size: 15px;
width: 300px;
line-height: 30px;
}
span {
position: relative;
width: auto;
height: 15px;
}
span:after {
position: absolute;
content: attr(subscript-line);
width: 100%;
height: 100%;
top: 100%;
left: 0;
border-top: 1px solid black;
text-align: center;
font-size: 10px;
line-height: 10px;
}
<div>over the <span subscript-line="1">Triangle, a few months later</span>, another plane disappeared. A ship named the Sandra.</div>
<div>over the <span subscript-line="2">Triangle, a few months later</span>, another plane disappeared. A ship named the Sandra.</div>
<div>over the <span subscript-line="3">Triangle, a few months later</span>, another plane disappeared. A ship named the Sandra.</div>
+1
확실히 정답, CSS의 하드 코딩 컨텐트는 피할 수 있다면 좋지 않습니다. –
+1
비즈니스 규칙이 허용하는 경우 추상화를 추가로 수행하고 CSS 카운터를 사용하여 첨자 값을 가져올 수 있습니다. –
온라인 상태 인 곳이나 Word 또는 다른 텍스트 편집기에있는 링크가 있습니까? – Firedrake969