Based on the comment made by @andi:
input:disabled+label
means that the label is immediately AFTER the input. In your HTML, the label comes BEFORE the text input. (but there's no CSS for "before".)
He's absolutely right. But that shouldn't stop us being able to solve the problem with a little trickery!
First step: swap the HTML elements order so that the <label>
appears after the <input>
. This will allow the styling rules to work as desired.
Then for the fun bit: use CSS to position the labels for text inputs on the left hand side!
input:disabled {
background: #dddddd;
}
input:disabled+label {
color: #ccc;
}
input[type=text]+label {
float: left;
}
<input type="checkbox" disabled="disabled" id="check1">
<label for="check1">Check</label>
<br />
<input type="text" id="text1" disabled="disabled">
<label for="text1">Text</label>
<br />
<input type="checkbox" id="check2">
<label for="check2">Check</label>
<br />
<input type="text" id="text2">
<label for="text2">Text</label>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…