Vertical Align Two Blocks Middle inside main block
Vertical Align Two Blocks Middle inside main block
I have this html Structure:
First Block Second Block Third Block Lopreum Ipsum Text Two Rows Main block has next styles: How can i vertically center two blocks, one below other? Any help? Stacking them vertically, wrapping them into a div and using relative position will do the tricks. they set the distance from the top of the wrapper to the outer box to be 50% of the outer box's height. While this transformation will translate the wrapper up by 50% of the wrapper's height. TE XT sdaf asdf asdf Add this to the CSS: Explaination: Doing this to all of your objects will give you full control of their positions, but make sure that everything is scalable (I recommend using the EDIT: I would recommend that you get used to Flexbox, check the complete guide here
</div>
</div>
</div>
</div>.main-block {
width: 20%;
max-width: 180px;
display: inline-block;
height: 135px;
position: relative;
}
I can't use method with flex
because it will break my inline style.
Also, looks like i can't use position: absolute
since i don't know img
height and width.flex
position: absolute
img
"I can't use method with flex because it will break my inline style." - Use inline-flex
then.
– Alohci
2 days ago
inline-flex
3 Answers
3
position: relative;
top: 50%;transform: translateY(-50%);
The combination of these two leads to the vertical position of the wrapper..main-block {
height: 400px;
background: silver;
}
.inner {
position: relative;
top: 50%;
transform: translateY(-50%);
}
p {
white-space: break-word;;
display: block;
width: 50px;
margin: 0;
padding: 0;
}
p:first-child{
background: yellow;
}
p:nth-child(2) {
background: red;
}
12 31 23 as df sd zv
</div>Postion: absolute;
Left: 0px;
Top: 0px;
Transform: translate(0vw, -4.5vh);}
This makes the object stuck in the top left corner. And then you move it around with Transform:
The formatting in Transform:
can be px,% and vw/vh
.Transform:
Transform:
px,% and vw/vh
vh/vw
formatting) :-)vh/vw
Also having the exact same class on each of the <div>
will make it hard to position objects, and Transform:
:-)<div>
Transform:
FYI the Transform: translate(0vw, -4.5vh)
is copy pasted from my own css, do not use those values :-)
– D3nj1
2 days ago
Transform: translate(0vw, -4.5vh)
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
can you provide your html code?
– Karthi Keyan
2 days ago