hadivoice hadivoice - 1 month ago 15
HTML Question

How can I vertical align a div within another div?

i put to div with two different content in a parent div and i want set vertical align first div with second div

sorry for bad language



.title-pin {
position: relative;
}
.pin-icon {
position: absolute;
width: 50px;
height: 50px;
-webkit-border-radius: 25px;
-moz-border-radius: 25px;
border-radius: 25px;
text-align: center;
background-color: #333;
color: #fff;
}
.star {
font-size: 30px;
line-height: 50px;
}
.title-container {
padding-left: 60px;
width: 400px;
font-size: 24px;
}

<div class="title-pin">
<div class="pin-icon">
<span class="star">★</span>
</div>
<div class="title-container">
<h3>This title is unstable. This title is unstable. This title is unstable.`enter code here`</h3>
</div>
</div>




Answer

Many ways you can get this. In short I just add one line on your css class .pin-icon top: 25%

.title-pin {
    position:relative;
}
.pin-icon {
    position: absolute;
    width: 50px;
    height: 50px;
    -webkit-border-radius: 25px;
    -moz-border-radius: 25px;
    border-radius: 25px;
    text-align: center;
    background-color:#333;
    color:#fff;
    top:25%;

    
}
.star {
    font-size: 30px;
    line-height: 50px;
}
.title-container {
    padding-left: 60px;
    width:400px;
    font-size:24px;
}

  
<div class="title-pin">
  <div class="pin-icon">
    <span class="star">★</span>
  </div>
  <div class="title-container">
    <h3>This title is unstable. This title is unstable. This title is unstable.`enter code here`</h3>
  </div>
</div>