Home > Web Front-end > HTML Tutorial > Doubts about CSS_html/css_WEB-ITnose

Doubts about CSS_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 11:45:39
Original
1124 people have browsed it

In the following code, there are four DIVs A, B, C, and D. Why is the text content of the last DIV separated and the border of DIV D moved to the first line?

<!DOCTYPE html><html><head lang="en">    <meta charset="UTF-8">    <title>CSS</title></head><style type="text/css">    .A, .B, .C {        float: left;        width: 200px;        height: 100px;        margin: 1em;        border-style: solid;        border-width: 1px;        border-color: #ccc;    }    .D {        width: 200px;        height: 100px;        margin: 1em;        border-style: solid;        border-width: 1px;        border-color: #A94E38;    }</style><body><div class="A">Text in div A</div><div class="B">Text in div B</div><div class="C">Text in div C</div><div class="D">Text in div D</div></body></html>
Copy after login

Operation effect

Please clarify, thank you.


Reply to discussion (solution)


You are doing this because floating elements have an impact on unfloated elements (standard document flow). Just use clear.

<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>Document</title></head> <style type="text/css">    .A, .B, .C {        float: left;        width: 100px;        height: 100px;                border: solid 2px blue;        background-color: green;    }     .D {        width: 200px;        height: 200px;        background-color: red;    }    /* 清除浮动元素对当前元素的影响 */    .clear {         clear: both;    }</style> <body><div class="A">Text in div A</div><div class="B">Text in div B</div><div class="C">Text in div C</div> <div class="D clear">Text in div D</div> </body></html>
Copy after login


Thanks, I found a blog post based on your tips,
http://www.cnblogs.com/polk6/archive/ 2013/07/25/3142187.html
Still trying to understand

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template