Align text block to the right with margin auto : Block Elements « Style Basics « HTML / CSS






Align text block to the right with margin auto

 



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en'>
    <head>
        <title>background-attachment</title>
        <style rel='stylesheet' type='text/css'>
body, p {
    background-color: #fff;
    background-image: url('http://www.java2s.com/style/logo.png');
    background-position: right bottom;
    background-repeat: no-repeat;
    background-attachment: fixed;
}
p {
    border: 1px solid rgb(200, 200, 200);
    background-image: url('palms2.jpg');
    margin: 10px 10px 10px auto;
    width: 200px;
    padding: 20px;
}        
        </style>
    </head>
    <body>
        <p>
            Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Sed vitae
            augue. Vivamus viverra libero in pede. Nam nisl ipsum, eleifend aliquet,
            laoreet vel, aliquet non, urna. Duis eget velit sed metus tincidunt
            viverra. Nulla imperdiet ligula nec velit. Vivamus augue pede, pharetra
            ac, dictum quis, aliquet at, ante. Aliquam vehicula arcu a ligula.
            Mauris accumsan nunc at tortor. Aenean vitae eros. Maecenas rutrum risus
            id metus. Duis ac leo. Phasellus sit amet diam. Sed semper, purus ut
            commodo interdum, mi tortor ullamcorper turpis, quis porta pede ante
            vitae erat. Integer imperdiet tempus purus. Aliquam erat volutpat.
            Aliquam eget magna. Nunc rhoncus mi vitae velit. Proin tempus tellus
            non orci. Nulla nec tortor.
        </p>
    </body>
</html>

 








Related examples in the same category

1.DIV by default starts new line
2.Use clear to start a new line
3.Floating left block pushes siblings to the right
4.Align in a row one by one for floating blocks
5.Use margin to offset block
6.Block being added one by one