How to align 3 divs (left/center/right) inside another div?

前端 未结 18 2572
猫巷女王i
猫巷女王i 2020-11-21 20:48

I want to have 3 divs aligned inside a container div, something like this:

[[LEFT]       [CENTER]        [RIGHT]]

Container div is 100% wid

18条回答
  •  时光取名叫无心
    2020-11-21 21:25

    If you do not want to change your HTML structure you can also do by adding text-align: center; to the wrapper element and a display: inline-block; to the centered element.

    #container {
        width:100%;
        text-align:center;
    }
    
    #left {
        float:left;
        width:100px;
    }
    
    #center {
        display: inline-block;
        margin:0 auto;
        width:100px;
    }
    
    #right {
        float:right;
        width:100px;
    }
    

    Live Demo: http://jsfiddle.net/CH9K8/

提交回复
热议问题