It is unknown whether the child elements centered horizontally in css are fixed width or width.
This article mainly explains the "css horizontal center child elements is a fixed width or width unknown", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in-depth, together to study and learn "css horizontal center child elements is a fixed width or width unknown" it!
It is relatively easy to center horizontally, first of all, it is unknown whether the child element is of fixed width or width.
1, fixed width this way is absolute positioning center, in addition to using margin, you can also use transform.
(pay attention to browser compatibility, which is only applicable to ie9+, mobile development. Please ignore)
.container {width: 300px; height: 200px; background: pink; position: relative;} .inner {width: 100px; height: 50px; position: absolute; top: 50%; left: 50%; margin-top:-25px Margin-left:-50px; background: # fff; text-align: center;}
2. Unknown width sets the child element to the inline element, and then the parent element sets text-align: center.
.container {width: 300px; height: 200px; background: pink; position: relative; text-align: center;} .inner {display: inline-block } Thank you for your reading, the above is the content of "css horizontal center child elements are fixed width or unknown width". After the study of this article, I believe you have a deeper understanding of the question of whether the horizontal center child elements of css are fixed width or unknown width, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!