How to align a div to the top of its parent but keeping its inline-block behaviour?

后端 未结 5 2092
后悔当初
后悔当初 2020-11-29 21:38

See: http://jsfiddle.net/b2BpB/1/

Q: How can you make box1 and box3 align to the top of the parent div boxContainer?

#boxContainerContai         


        
相关标签:
5条回答
  • 2020-11-29 21:47

    Try the vertical-align CSS property.

    #box1 {
        width: 50px;
        height: 50px;
        background: #999;
        display: inline-block;
        vertical-align: top; /* here */
    }
    

    Apply it to #box3 too.

    0 讨论(0)
  • 2020-11-29 21:48

    As others have said, vertical-align: top is your friend.

    As a bonus here is a forked fiddle with added enhancements that make it work in Internet Explorer 6 and Internet Explorer 7 too ;)

    Example: here

    0 讨论(0)
  • 2020-11-29 21:51

    You can add float: left; for each of the boxes (box1, box2, box3).

    http://jsfiddle.net/Wa4ma/

    0 讨论(0)
  • 2020-11-29 21:53

    Use vertical-align:top; for the element you want at the top, as I have demonstrated on your jsfiddle.

    http://www.brunildo.org/test/inline-block.html

    0 讨论(0)
  • 2020-11-29 21:58

    Or you could just add some content to the div and use inline-table

    0 讨论(0)
提交回复
热议问题