图片布局 文字包围图片 CSS

梗概

实例:

脱离效果演示

原来的标准流: 给div2添加float:right属性: 给div2和div3都添加float:right属性: div4被浮起的div2给盖住了

环绕效果演示

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <style>
    .warp {
      background-color: red;
      border-radius: 20px;
      border-style: solid;
      border-width: 10px;
      border-color: green;
      box-sizing: border-box;
    }
    .a {
      background-color: blue;
      float: left;
      width: 100px;
      height: 100px;
    }
    .b {
      background-color: yellow;
      float: left;
      width: 100px;
      height: 150px;
    }
    .c {
      background-color: hotpink;
      border: 10px solid darkcyan;
      height: 200px;
      width: 100px;
    }
  </style>
  <body>
    <div class="warp">
      <div class="a">aaaaa</div>
      <div class="b">bbbbb</div>
      <div class="c">ccccc</div>
    </div>
  </body>
</html>

效果

  • 可以看到c的盒子被遮挡了,但行内文本会自动环绕到b的下方

原教程链接:

CSS 布局 - 浮动和清除 (w3school.com.cn)