Centralizing a floating element
My "div" element have a relative width, it isn't absolute so I can't use exact numbers to centralize. A nice solution is to use "display: inline-block":
body {
text-align: center;
}
#myDiv开发者_Python百科 {
border: 1px solid black;
display: inline-block;
padding: 50px;
}
But this element NEEDS to float, I tried this:
#myDiv {
border: 1px solid black;
display: inline-block;
float: left;
padding: 50px;
}
And this:
#myDiv {
border: 1px solid black;
display: inline-block;
padding: 50px;
position: absolute;
}
Without any success, can somebody help me ?
Thanks
#myDiv {
margin: 0 auto;
}
You can center any block element with this css:
margin:auto;
width: some fixed value;
So elment need to have fixed width, in order to be centerd like this.
精彩评论