給定以下HTML,是否可以使用CSS選擇器來定位標籤中的文本?使用CSS選擇器來定位html標籤文本
<fieldset class="sl">
<legend>
Text Inputs
</legend>
<label>
Text Input:
<input type="text" />
</label>
<label>
Read-only Text Input:
<input type="text" readonly value="this is read-only" />
</label>
</fieldset>
所以在上面的,我想要的目標「文本輸入」或「只讀文本輸入:」並設置寬度靠左位置文本框。
我能想到的唯一的作品就是將文本包裝在一個範圍內。
<label>
<span>Text Input:</span>
<input type="text" />
</label>
隨着CSS選擇:
fieldset.sl label span {
width: 200px;
display: inline-block;
}
FYI - 我在看使用CSS在同一行和單獨的行輸入上述標籤之間切換具有兩全其美 - ,而不必修改html結構 - 只對fieldset類進行調整,就像使用span中包裝的標籤中的文本一樣。