2
I have the code below:
.divCheckList .valorBool,
.divCheckList .divCheckBox {
height: 34px;
display: inline-block;
border:#CCC .1px solid;
vertical-align:middle;
}
.divCheckList .valorBool {
line-height: 34px;
}
.divCheckList .divCheckBox .checkBox {
display: none;
}
.divCheckList .labelCheckBox {
display:block;
width:60px;
height:34px;
background-color:#CCC;
border:none;
border-radius:34px;
}
.divCheckList .labelCheckBox:after {
display:block;
width:26px;
height:26px;
background-color:#FFF;
border:#000 .1px solid;
border-radius:50%;
content:"";
}
html
<div class="divCheckList">
<label class="valorBool">NÃO</label>
<div class="divCheckBox">
<input type="checkbox" name="cb" id="cb" class="checkBox">
<label for="cb" class="labelCheckBox"></label>
</div>
<label class="valorBool">SIM</label>
</div>
That shows the following picture:
However, I would like to center the white ball so that it is spaced in the corners and on top.
I tried with margin: 4px;
but the image distorts.
How to correct?
I was able to correct by placing position: relative in the most external div and position Absolute in the label with after. Is it the right way?
– Carlos Rocha
Will that button change position by clicking "YES"? You have to see how it will look with this.
– Sam
The way you are, adding
top: 10%; left: 5%; position: relative;
in the:after
was great.– Sam
I will continue the code with margin:4px; even. I’ll see if it will be a problem when placing the clickable button
– Carlos Rocha
Boto fé........
– Sam
other 2 things I could not understand is because both after and before, the created element is always on the left side of the creator object and because the white ball only appears if we add content: ""?
– Carlos Rocha
The left side is default if you do not arbitrarily position the element. "content" is the content of the element, which may or may not be empty. If you don’t put "content", CSS "understands" that the element doesn’t exist and does nothing.
– Sam
mean to align the element at right for example? In this case the ball goes right?
– Carlos Rocha
To align the ball to the right has several shapes.
– Sam
got it. Thanks. Just did not understand why before and after if any text placed in the div next to the element created for example as after, does not "push" the ball to the right. the text is as background.
– Carlos Rocha
It is because the ball has fixed size of 26px.
– Sam
and this makes the text stay deep in the div? Shouldn’t push the ball?
– Carlos Rocha
It is not in the bottom. It is inside the div. It does not push the ball because the size is fixed. When you specify a size for div, it doesn’t change even if you fill text inside it.
– Sam
That’s not what I meant no. Look at this: we have the div, right? so inside it I put the object before, a text and an after object. Okay? So, what is happening is that the text is appearing at the bottom of the div and the object before or after seems to be soibresai to the text. Do the following, take the code that is posted and put a text of 50 carcters for example <label for="cb" class="labelCheckBox">aaaaaaaaaaaaaaaa</label> and see what happens.
– Carlos Rocha
But there’s before there.
– Sam