Current location - Quotes Website - Signature design - css dl-dt-dl centers the text under the image
css dl-dt-dl centers the text under the image

One of the methods is as follows:

The picture and picture description.html file code is as follows:

Pictures and picture descriptions

  • Picture 1

  • Picture 2

  • < li>Picture 3

  • Picture 4

  • Picture five

  • Picture 6

  • Picture 7

  • Picture 8

  • < /html>

    The img.css file code is as follows: body?{

    background:?#fff;

    margin:?0?auto;

    }

    dl?{

    margin:?0?24px;

    padding:?10px;

    width: ?920px;?/*?This is the key line, controlling the total width of the list?*/

    }

    dl?li?{

    list-style- type:?none;?/*?Remove the dot before the list?*/

    display:?inline;/*?This is the key line to make the list inline?*/

    float:?left;/*?This is the key line to make all inline list elements float left?*/

    }

    dl?li?p?. img?{

    width:?200px;?/*?This is the key line, controlling the width of the image?*/

    height:?200px;

    display :?block;/*?This is the key line, turning the inline image into a block-level box model?*/

    margin-bottom:?5px;/*?Add 5px to the block-level box model image Lower margin?*/

    }

    dl?li?p?{

    text-align:?center;/*?This is the key line, Control the text to be centered?*/

    }

    dl?li?p.marginright?{

    margin-right:?40px;/*?This is the key OK, control the width of the right outer margin of the image 1?2?3?5?6?7?*/

    text-align:?center;

    } Your problem lies in HTML Add appropriate tags

    to

  • in the
    list and wrap the and text in
  • . This way the HTML is structured enough.

    In CSS, there are three main problems to solve.

    1. Control the total width of the

    list and the width of each picture. The right margin of picture 1 2 3 5 6 7 will automatically wrap.

    1.1

    The left and right margins are 24px, the border defaults to 0, the inner margin is 10px, the width is 920px, and the total width is 988px;

    1.2 Picture 1 2 3 4 Each picture Width 200px (height 200px), the outer right margin of each

    including pictures 1, 2, and 3 is 40px. The total width of the first line is 920px, and the total width of

    is 920px, so the picture cannot be placed here. Automatic line wrapping.

    1.3 Each picture of pictures 5, 6, 7 and 8 is 200px wide (200px high), including pictures 5, 6, 7.

    Each outer right margin is 40px, and the second row has a total width of 920px, < The total width of dl/> is 920px, which is the second row.

    2. Use display:inline; to make

  • display inline, and add float:left; and all
  • will float into one line, but because In the above 1, we control the width so that the inline
  • will wrap when it reaches the fixed width.

    3. Then use display:block; to turn the

    containing " text" into a block-level box model, then the text will be displayed below the image, and then

    Add text-align:center; and the text will be centered.