If I understand correctly, I believe you are trying to vertically align both the contunut and opac divs.
I was able to do this with the following solution:
.tot {
position: relative;
width: auto;
height: 900px; //change to whatever height fits your design
}
.abs-v-center {
margin: auto;
top: 0;
left: 0;
bottom: 0;
right:0;
}
.opac {
position: absolute;
background-color: #ededed;
height: 400px;
width: 400px;
opacity: 0.8;
}
.continut {
position: absolute;
height: 200px;
width: 200px;
}
By setting the wrapper div to position: relative
and giving it a fixed width and height you can then align its children accordingly to the wrapper div by adding position: absolute
.
I abstracted the positioning rules into a separate class called .abs-v-center
and applied it to both elements which should align each to the middle of the wrapper div.
Solution #2:
Alternatively, you can incorporate flexbox which makes vertical alignment a breeze.
.tot {
display: flex; // set wrapper to display flex
justify-content: center; // horizontally align children (like margin: 0 auto)
align-items: center; //vertically align children (flexbox goodness)
width: auto;
height: 900px;
}
.opac {
position: absolute; //set to aboslute to removed from the normal document flow so that elements are not placed next to each other.
background-color: #ededed;
height: 400px;
width: 400px;
opacity: 0.8;
z-index: -1; // set z-index to place opac div behind continut div
}
.continut {
height: 200px;
width: 200px;
}
If you are new to flexbox checkout this article