CSS基础学习9-CSS设置浮动元素(float)

本文详细介绍了CSS中如何使用float属性使元素向左或向右浮动,并解释了clear属性的作用,即控制浮动元素之后的元素如何围绕浮动元素排列。通过实际代码示例展示了这些属性的应用。

所有CSS基础学习文档下载地址:http://download.youkuaiyun.com/detail/rongrong_love_lc/9663463

九、CSS设置浮动元素(float)
    通过float属性令元素向左或向右浮动。也就是说,令盒子及其内容浮动到文档(或者是上层盒子)的左边或者右边。
    value:left、right、none。
    html文件如下:
      <html>
          <head>
              <title>Color例子</title>
              <link rel="stylesheet" type="text/css" href="color.css"/>
          </head>
          <body>
          <div id="picture1">
              <img src="image1.jpg" alt="Back Picture" />
              </div>
          <div id="picture2">
              <img src="image1.jpg" alt="Back Picture" />
          </div>
          <p>study测试文本信息studystudy测试文本信息studystudy测试文本信息
                  studystudy测试文本信息studystudy测试文本信息studystudy测试文本信息
                  studystudy测试文本信息studystudy测试文本信息studystudy测试文本信息
                  studystudy测试文本信息studystudy测试文本信息studystudy测试文本信息
                  studystudy测试文本信息studystudy测试文本信息studystudy测试文本信息
                  studystudy测试文本信息studystudy测试文本信息studystudy测试文本信息
                  studystudy测试文本信息studystudy测试文本信息studystudy测试文本信息
                  studystudy测试文本信息studystudy测试文本信息studystudy测试文本信息
                  studystudy测试文本信息studystudy测试文本信息studystudy测试文本信息
                  studystudy测试文本信息studystudy测试文本信息studystudy测试文本信息
                  studystudy测试文本信息studystudy测试文本信息studystudy测试文本信息
                  studystudy测试文本信息studystudy测试文本信息studystudy测试文本信息
                  studystudy测试文本信息study</p>

          </body>
      </html>
    CSS文件如下:
      #picture1{float : left;
            width : 100px;
               }
      #picture2{float : right;
            width : 50%;
                }


    1.clear属性:
        用于控制浮动元素的后继元素的行为。
        缺省时,后继元素将向上移动,以填补由于前面元素的浮动而空出的可用控件。
        value:left、right、both、none。
        原则:如果一个盒子的clear属性被设置为both,那么该盒子的上边距将始终处于前面的浮动盒子的下  边距之下。
        html文件如下:
          <html>
            <head>
              <title>Color例子</title>
              <link rel="stylesheet" type="text/css" href="color.css"/>
            </head>
           <body>
              <div id="picture1">
                  <img src="image1.jpg" alt="Back Picture" />
              </div>

           <p  class="right">study测试文本信息studystudy测试文本信息studystudy测试文本信息
                  studystudy测试文本信息studystudy测试文本信息studystudy测试文本信息
                  studystudy测试文本信息studystudy测试文本信息studystudy测试文本信息
                  studystudy测试文本信息studystudy测试文本信息studystudy测试文本信息
                  studystudy测试文本信息studystudy测试文本信息studystudy测试文本信息
                  studystudy测试文本信息studystudy测试文本信息studystudy测试文本信息
                  studystudy测试文本信息studystudy测试文本信息studystudy测试文本信息
                  studystudy测试文本信息studystudy测试文本信息studystudy测试文本信息
                  studystudy测试文本信息studystudy测试文本信息studystudy测试文本信息
                  studystudy测试文本信息studystudy测试文本信息studystudy测试文本信息
                  studystudy测试文本信息studystudy测试文本信息studystudy测试文本信息
                  studystudy测试文本信息studystudy测试文本信息studystudy测试文本信息
                  studystudy测试文本信息study</p>
          <h1 class="right">测试信息1</h1>
          <h2 class="left">测试信息2</h2>
        </body>
      </html>

    CSS文件如下:
      #picture1{float : left;
                width : 100px;
                }
      #picture2{float : right;
                width : 50%;
                }
      .both {clear:both;
             }
      .left {clear:left;}
      .right {clear:right;}
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值