zoukankan      html  css  js  c++  java
  • 使用样式“clear”和“overflow”消除浮动元素对环绕行框的影响

      为元素设置“float”样式之后,元素会脱离标准文档流,不再占据原来的空间。后续元素会向前移动,占据这个新的空间。后续的文本会围绕着浮动元素分布,形成一种环绕布局的现象。

      示例代码:

      

     1 <!DOCTYPE html>
     2 <html>
     3 <head>
     4     <title>test page</title>
     5     <meta charset="utf-8">
     6     <style type="text/css">
     7         #ele-1 {
     8             width: 100px;
     9             height: 50px;
    10             background-color: #3E3;
    11             float: left;
    12         }
    13         #ele-2 {
    14             width: 500px;
    15             background-color: #EE3;
    16         }
    17     </style>
    18 </head>
    19 <body>
    20     <div id="ele-1">Div area!</div>
    21     <p id="ele-2">
    22         This is a paragrapha!This is a paragrapha!This is a paragrapha!This is a paragrapha!This is a paragrapha!This is a paragrapha!This is a paragrapha!This is a paragrapha!This is a paragrapha!This is a paragrapha!This is a paragrapha!This is a paragrapha!This is a paragrapha!This is a paragrapha!This is a paragrapha!This is a paragrapha!This is a paragrapha!This is a paragrapha!This is a paragrapha!This is a paragrapha!This is a paragrapha!This is a paragrapha!This is a paragrapha!This is a paragrapha!This is a paragrapha!This is a paragrapha!This is a paragrapha!This is a paragrapha!This is a paragrapha!This is a paragrapha!This is a paragrapha!This is a paragrapha!This is a paragrapha!This is a paragrapha!This is a paragrapha!This is a paragrapha!This is a paragrapha!This is a paragrapha!This is a paragrapha!This is a paragrapha!This is a paragrapha!This is a paragrapha!This is a paragrapha!
    23     </p>
    24 </body>
    25 </html>
    View Code

      显示效果如下:

    文本围绕浮动元素分布

      现在分别为“<p>”标签添加“clear:left”和“overflow:hidden”样式,消除这种环绕效果!

      添加样式“clear:left”之后,显示效果如下:

    添加样式“clear:left”.

      添加样式“overflow:hidden”之后,显示效果如下:

    添加样式“overflow:hidden”.

      可以通过合理的使用这两种样式效果实现页面布局。

  • 相关阅读:
    使用.Net Core 2.2创建windows服务
    Ubuntu 18.04 安装部署Net Core、Nginx全过程
    Task的在主线程处理异常信息的Helper类
    行转列的处理。
    netcore 下加密遇到的问题
    关于安装angular-cli环境报错的问题
    64位的windows服务安装问题
    EF.Mysql在codefirst模式下调用存储过程,和再DbFirst模式下的调用
    阿里云消息队列的C#使用http接口发送消息实例
    [转载]EF或LINQ 查询时使用IN并且根据列表自定义排序方法
  • 原文地址:https://www.cnblogs.com/tangfly/p/5876689.html
Copyright © 2011-2022 走看看