Issue
In this example, I'd like to vertically center "3" within the "list-li" element since the sibling element has a dynamic height. I tried using:
position: relative;
top: 50%;
..but it doesn't seem to work.
HTML:
<ul class="list-1">
<li>
<div class="list-1-num">
3
</div>
<div class="list-1-content list-1-content-signup">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur venenatis, lectus cursus cursus elementum.
</div>
</li>
</ul>
CSS:
.list-1 {
font-size: 20px;
list-style: none;
}
.list-1 li {
margin-bottom: 70px;
overflow: hidden;
text-align: left;
list-style: none;
}
.list-1-num {
float: left;
font-size: 25px;
margin-right: 20px;
}
.list-1-content {
background-position: 0 50%;
background-repeat: no-repeat;
background-size: 45px 40px;
float: left;
width: 300px;
line-height: 25px;
}
Codepen Demo: https://codepen.io/aguerrero/pen/OZevgJ
Solution
You could use Flexbox instead of float
and set align-items: center
on parent.
.list-1 {
font-size: 20px;
list-style: none;
}
.list-1 li {
margin-bottom: 70px;
overflow: hidden;
text-align: left;
list-style: none;
display: flex;
align-items: center;
}
.list-1-num {
font-size: 25px;
margin-right: 20px;
}
.list-1-content {
background-position: 0 50%;
background-repeat: no-repeat;
background-size: 45px 40px;
width: 300px;
line-height: 25px;
}
<ul class="list-1">
<li>
<div class="list-1-num">
3
</div>
<div class="list-1-content list-1-content-signup">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur venenatis, lectus cursus cursus elementum.
</div>
</li>
</ul>
Answered By - Nenad Vracar Answer Checked By - Gilberto Lyons (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.