Right-align block elements in HTML

后端 未结 8 865
故里飘歌
故里飘歌 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: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/

提交回复
热议问题