-1

I have two div which exist in a container div of both in my html page and I want align all content exist in a sub div corresponding to contents of another div. Is it possible to do this by CSS rules only?

<div class="container">
    <div class="subDiv1">
        some content here (with 400px height)
    </div>
    <div class="subDiv2">
        some content here (with 270px height)
    </div>
</div>

Edit: First content is an image with variable height and second content is a label variable text length and I want align center both of them into same horizontal line vertically.

2 Answers2

0

If you want to have the same CSS for .subDiv1 and .subDiv2, why not just use the exact same CSS code for both of them?

Vertically aligning content within a div can be done with the following CSS:

.container {
margin-left:auto;
margin-right:auto;
}
0

.container{
display: table;
width:100%;
}
.subDiv1,.subDiv2{
  padding: 10px;
  display: table-row;
}
.subDiv1{
  background-color:silver;
}
.subDiv2{
   background-color:#a7a5a5;
}
.container span {
  display:inline-block;
  width: 100px;
  height: 100px;
  background: gray;
  vertical-align: middle;
}
<div class="container">
    <div class="subDiv1">
        some content here <span>(with 400px height)</span>
    </div>
    <div class="subDiv2">
        some content here <span>(with 270px height)</span>
    </div>
</div>
Muhammad Usman
  • 357
  • 2
  • 14