Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
Yeah yeah, in theory there are 200 ways to do this and actually we know them.
But there's always this case where you try your ass off and nothing does the job.😄 -
unknown18398yIn case you cant use flexbox, set a position relative, a top of 50% and a transform translateY(-50%).
-
Jappe29168yOr if you want to shit all over the page you use:
#element {
position: absolute;
top:0;
right:0;
bottom:0;
left:0;
margin:auto;
} -
meain45338yposition: relative;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
this works 90% of the time -
johnDoe32338yCSS is great. Write 5 lines, run it; didnt work. Rewire, run again; didn't work. Repeat 2 more times...
"Yes! The text stays within my margins!" -
.el{
display: table;
}
.el .em{
display: table-cell;
vertical-align: middle;
} -
aviv4278yLe me trying to center something :
Margin-left:auto
Margin-right:auto
Text-align:center
Please.center.please.please(text) -
align-items: center;
/* If flex isn't available: */
position: relative;
top: 50%;
transform: translateY(-50%);
/* You're welcome. */
Related Rants
Front-end developer's to-do list :
☑ Climb Everest
☑ Learn how to speak mandarin
☑ Become god
◻ Vertically center something in CSS
undefined
css
front-end
frontend
todo