I want to center an object using CSS and no hacks, is this possible and how?
I have tried this, but than my p tag is gone.
.centered {
position: fixed;
top: 50%;
left: 50%;
}
I want to center an object using CSS and no hacks, is this possible and how?
I have tried this, but than my p tag is gone.
.centered {
position: fixed;
top: 50%;
left: 50%;
}
Use this for general purposes. Even span or div which is inside whatever :
late into the game, but have you tried with
display:flex
on the parent ?I have a useful class that is simple and works with all type of elements:
This is relatively new but supported at ~98% of major browsers.
However I suggest that you learn a bit about flexBox, it may seem complicated at first but it is very powerful for all type layouts !
HTML:
CSS:
Live example: http://jsfiddle.net/v3WL5/
Note that
margin: 0 auto;
will only have an effect if thediv
has a width.Use
margin: auto
like this:Usage :
CSS Code :
#text-align { text-align:center }
HTML Code :
<div id="text-align">Content goes here....</div>
http://www.techulator.com/resources/4299-center-Deprecated-tags-HTML.aspx
if you don't need to be position:fixed; you can just use
This is deprecated in HTML5