Right-align block elements in HTML

后端 未结 8 863
故里飘歌
故里飘歌 2021-02-06 23:53

I\'d like to right-align block elements in a floating container.

Assume the following markup.

相关标签:
8条回答
  • 2021-02-07 00:46

    Add overflow: hidden; to the parent div of the images. It will wrap around the images when you float them, and clear the images from the right with clear: right

    http://jsfiddle.net/zBnqQ/15/

    0 讨论(0)
  • 2021-02-07 00:47

    The correct way to align an element with CSS is to set text-align on the container and margin on the children elements.
    Your tries are wrong since you are setting margin and text-align on the img tag. Your css should look like:

    div {
    float:right;
    text-align: right;
    }
    img {
    margin: 0 0 0 auto;
    }  
    

    Just tested on ie8, ff and chrome.
    http://jsfiddle.net/notme/wfwjf/2/

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