I have a form with two inputs. I want to select only the first input to add the radius in top-left and bottom-left but when I use CSS pseudo it applies to other (in my example second) input as well.
(in
CSS:
.my-stupid-form {
margin: 0 auto;
max-width: 70%;
}
.iconic-input {
margin: 1em 0;
display: flex;
font-size 1.4em;
}
.iconic-input__label {
background-color: yellow;
padding: .2em 1em;
line height: 2;
}
.iconic-input__input {
border: none;
padding: .2em;
font: inherit;
flex-grow: 1;
width: 100%;
}
form.my-stupid-form input:first-child {
border-top-left-radius: 10px;
border-bottom-left-radius: 10px;
}
.iconic-input__button {
background-color: yellow;
border: none;
font: inherit;
padding: .5em 1em;
}
HTML:
<form action="" class="my-stupid-form">
<div class="iconic-input">
<label class="iconic-input__label" for="input1">☺</label>
<input class="iconic-input__input" type="text">
</div>
<div class="iconic-input">
<label class="iconic-input__label" for="input2">☏</label>
<input class="iconic-input__input" type="text">
<button class="iconic-input__button">submit</button>
</div>
</form>
I tried these codes but both inputs are selected:
1)
form.my-stupid-form input:first-child {
border-top-left-radius: 10px;
border-bottom-left-radius: 10px;
}
form.my-stupid-form input:first-of-type {
border-top-left-radius: 10px;
border-bottom-left-radius: 10px;
}
2
Answers
Here is the fixed code :
I used an id because you used the
for
property in yourlabel
s.The first input is round at the left but the emoji is at the right but I guess it is because you only gave the necessary CSS and HTML to reproduce.
In fact you want the input of the first div child