Issue
When multiple divs, some of them only 1 line text and other 2 with different line-height, positioned with inline-flex for content centering, they appear in different vertical positions. I know it's because of the line-height, when I put only 1 line text it doesn't happen. Need it without floats.
Here is the codepen: https://codepen.io/Sergio-Torres-the-reactor/pen/GRzvgpb
#juego {
text-align: center;
background-color: red;
margin: 0 auto;
padding: 20px 20px 40px;
width: 100%;
max-width: 320px;
font-size: 20px;
line-height: 22px;
font-family: Arial, sans-serif;
}
.juego_respuesta {
padding: 40px 0;
display: block;
}
.juego_respuesta_botones {
margin-bottom: 30px;
}
.juego_respuesta_buton {
display: inline-flex;
width: 120px;
height: 40px;
align-items: center;
justify-content: center;
font-size: 9px;
line-height: 11px;
color: #000000;
background-color: #ffffff;
border: 1px solid #000000;
margin: 10px 5px;
transition: 0.5s all;
cursor: pointer;
}
.juego_respuesta_buton span {
font-size: 7px;
}
.juego_respuesta_buton:hover {
color: #ffffff;
background-color: #000000;
}
.juego_respuesta_buton.activo {
color: #ffffff;
background-color: #000000;
cursor: default;
}
<div id="juego">
<div class="juego_respuesta">
<div class="juego_respuesta_botones">
<div class="juego_respuesta_buton activo">
<div>TEST 1</div>
</div>
<div class="juego_respuesta_buton">
<div>TEST 2</div>
</div>
<div class="juego_respuesta_buton">
<div>TEST 3<br> TEST 3</div>
</div>
<div class="juego_respuesta_buton">
<div>TEST 4<br>
<span>(TEST 4)</span></div>
</div>
<div class="juego_respuesta_buton">
<div>TEST 5<br>
<span>(TEST 5)</span></div>
</div>
<div class="juego_respuesta_buton">
<div>TEST 6</div>
</div>
<div class="juego_respuesta_buton">
<div>TEST 7</div>
</div>
<div class="juego_respuesta_buton">
<div>TEST 8<br>
<span>(TEST 8)</span></div>
</div>
<div class="juego_respuesta_buton">
<div>TEST 9</div>
</div>
</div>
</div>
</div>
Tried different heights/min-heights and display properties.
Solution
From my initial look, you should give the flex display to parent element so it controls the positioning of the children buttons.
I modified the CSS a little bit and it fixes the issue.
#juego {
text-align: center;
background-color: red;
margin: 0 auto;
padding: 20px 20px 40px;
width: 100%;
max-width: 320px;
font-size: 20px;
line-height: 22px;
font-family: Arial, sans-serif;
}
.juego_respuesta {
padding: 40px 0;
}
.juego_respuesta_botones {
margin-bottom: 30px;
display:flex;
justify-content:center;
align-items:center;
flex-wrap: wrap;
}
.juego_respuesta_buton {
display:flex;
justify-content:center;
align-items: center;
width: 120px;
height: 40px;
font-size: 9px;
line-height: 11px;
color: #000000;
background-color: #ffffff;
border: 1px solid #000000;
margin: 10px 5px;
transition: 0.5s all;
cursor: pointer;
}
.juego_respuesta_buton span {
align-self:center;
}
.juego_respuesta_buton:hover {
color: #ffffff;
background-color: #000000;
}
.juego_respuesta_buton.activo {
color: #ffffff;
background-color: #000000;
cursor: default;
}
<div id="juego">
<div class="juego_respuesta">
<div class="juego_respuesta_botones">
<div class="juego_respuesta_buton activo">
<div>TEST 1</div>
</div>
<div class="juego_respuesta_buton">
<div>TEST 2</div>
</div>
<div class="juego_respuesta_buton">
<div>TEST 3<br>
TEST 3</div>
</div>
<div class="juego_respuesta_buton">
<div>TEST 4<br>
<span>(TEST 4)</span></div>
</div>
<div class="juego_respuesta_buton">
<div>TEST 5<br>
<span>(TEST 5)</span></div>
</div>
<div class="juego_respuesta_buton">
<div>TEST 6</div>
</div>
<div class="juego_respuesta_buton">
<div>TEST 7</div>
</div>
<div class="juego_respuesta_buton">
<div>TEST 8<br>
<span>(TEST 8)</span></div>
</div>
<div class="juego_respuesta_buton">
<div>TEST 9</div>
</div>
</div>
</div>
</div>
Answered By - Haroon Ahmad
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.