1

I'm trying to align some DIVs and failing to succeed.

<div class="row">
    <div class="name"><h3>Some long name in here</h3></div>
    <div class="info">
        <div class="delete">X</div>
        <div class="price">1000.00</div>    
      </div>
</div>

This is what I did so far https://jsfiddle.net/uvo2xdxk/

How can I make the .info div to be vertically aligned inside the row?

Eugen
  • 2,934
  • 2
  • 26
  • 47

5 Answers5

2

You can achieve this by display: table-cell; Remove float from .name and .info and assign display: table-cell; vertical-align: middle; to them :)

.row {
  display: table;
  width: 450px;
  background-color: yellow;
  border: 1px solid blue;
}
.name {
  background-color: red;
  display: table-cell;
  vertical-align: middle;
}
.delete {
  background-color: green;
  display: inline;
  margin-right: 25px;
}
.price {
  background-color: blue;
  display: inline;
  margin-right: 5px;
}
.info {
  display: table-cell;
  width: 150px;
  vertical-align: middle;
  background-color: ccc;
  border: 1px solid green;
  text-align: right;
}
<div class="row">
  <div class="name">
    <h3>Some long name in here</h3>
  </div>
  <div class="info">
    <div class="delete">X</div>
    <div class="price">1000.00</div>
  </div>
</div>
w3debugger
  • 2,097
  • 19
  • 23
1

https://jsfiddle.net/uvo2xdxk/5/

try this one

.row {
    width: 450px;
    background-color: yellow;
    border: 1px solid blue;
    display:table;
}
.row {
    width: 450px;
    background-color: yellow;
    border: 1px solid blue;
    display:table;
}

assign row display:table; property and its child display:table-cell; and vertical-align:middle; and also remove the float:right; from child

Ahmad Asjad
  • 825
  • 1
  • 8
  • 29
0

You can check with the below link.

https://jsfiddle.net/uvo2xdxk/7/

      .name {
    background-color: red;
    display: inline;
    float: left;
}

.delete {
    background-color: green;
    display: inline;
     margin-right: 0px;
}

.price {
    background-color: blue;
    display: inline;
    margin-right: 5px;
}

.row {
    width: 450px;
    background-color: yellow;
    border: 1px solid blue;
    display:table;
}

.info {


    height:57px;
    display: table-cell;
    vertical-align:middle;
    background-color: ccc;
    border: 1px solid green;
    top: 25%;
}
Steevan
  • 826
  • 5
  • 8
0

Add to your .info:

.info{
//...
    position: absolute;              
    top: 50%;                        
    transform: translate(0, -50%)
}

And your .row should set:

position: relative;

I had updated your jsfiddle

Neo
  • 1,469
  • 3
  • 23
  • 40
0

I have modified your css please check here

.name {
background-color: red;
display: inline;
float: left;
}

.delete {
background-color: green;
display: inline;
 margin-right: 25px;
}

.price {
background-color: blue;
display: inline;
margin-right: 5px;
}

.row {
width: 450px;
background-color: yellow;
border: 1px solid blue;
height: auto;
vertical-align: middle;
overflow:hidden;
position:relative;
}

.info {
float: right;
display: inline-block;
background-color: ccc;
border: 1px solid green;
vertical-align: middle;
position:absolute;
right:0;
transform:translateY(-50%)   ;
top:50%;
}

Please check if it works for you.

user1162084
  • 462
  • 1
  • 6
  • 18