Easy way to center variable width divs in CSS

前端 未结 4 743
清歌不尽
清歌不尽 2020-12-25 12:46

I\'m trying to center a Div that will have varying width\'s (based on content of a website).

I read about a relative positioning technique here:

http://www.t

4条回答
  •  温柔的废话
    2020-12-25 13:13

    @Talon; you can do it like this http://jsfiddle.net/sandeep/7PXQF/

    CSS:

    .container{
    background-color:red;
        text-align:center;
    }
    .center{
    background-color:yellow;
    display:inline-block;
    text-align:left;}
    

    HTML:

    This is a div with an much wider width, to make the yellow div go off the page to the right. We'll type a bit more to be sure.

    Most people will see a horizontal scroll bar on the bottom, unless their screen is very wide.

提交回复
热议问题