代码:

<!DOCTYPE html PUBliC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>float属性</title>
<style type="text/css">
body{
margin:15px;
font-family:Arial; font-size:12px;
} .father{
background-color:#ffff99;
border:1px solid #111111;
padding:5px;
} .father div{
padding:10px;
margin:15px;
border:1px dashed #111111;
background-color:#90baff;
} .father p{
border:1px dashed #111111;
background-color:#ff90ba;
} .son1{
/* 这里设置son1的浮动方式*/ } .son2{
/* 这里设置son1的浮动方式*/ } .son3{
/* 这里设置son1的浮动方式*/ } </style>
</head>
<body>
<div class="father">
<div class="son1">Box-1</div>
<div class="son2">Box-2</div>
<div class="son3">Box-3</div>
<p>这里是浮动框外围的文字,这里是浮动框外围的文字,这里是浮动框外围的文字,这里是浮动框外围的文字,这里是浮动框外围的文字,这里是浮动框外围的文字,这里是浮动框外围的文字,这里是浮动框外围的文字,这里是浮动框外围的文字.</p>
</div>
</body>
</html>

代码:

<!DOCTYPE html PUBliC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>float属性</title>
<style type="text/css">
body{
margin:15px;
font-family:Arial; font-size:12px;
} .father{
background-color:#ffff99;
border:1px solid #111111;
padding:5px;
} .father div{
padding:10px;
margin:15px;
border:1px dashed #111111;
background-color:#90baff;
} .father p{
border:1px dashed #111111;
background-color:#ff90ba;
} .son1{
/* 这里设置son1的浮动方式*/
float:left;
} .son2{
/* 这里设置son1的浮动方式*/
float:left;
} .son3{
/* 这里设置son1的浮动方式*/
float:left;
} </style>
</head>
<body>
<div class="father">
<div class="son1">Box-1</div>
<div class="son2">Box-2</div>
<div class="son3">Box-3</div> <!-- 当所有div都浮动的时候,块空间就不占据一行了,下面的内容会自动填充 ,div只占据属于自己的那一部分,后面的元素会自动补齐行剩余空间-->
<p>这里是浮动框外围的文字,这里是浮动框外围的文字,这里是浮动框外围的文字,这里是浮动框外围的文字,这里是浮动框外围的文字,这里是浮动框外围的文字,这里是浮动框外围的文字,这里是浮动框外围的文字,这里是浮动框外围的文字.</p>
</div>
</body>
</html>

说明:浏览器宽度改变时,样子相应的也会改变,浮动之后,默认的占据一行的宽度没有了,剩下的是css中设置的padding、margin、width、height等效果。

代码:

<!DOCTYPE html PUBliC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>float属性</title>
<style type="text/css">
body{
margin:15px;
font-family:Arial; font-size:12px;
} .father{
background-color:#ffff99;
border:1px solid #111111;
padding:5px;
} .father div{
padding:10px;
margin:15px;
border:1px dashed #111111;
background-color:#90baff;
} .father p{
border:1px dashed #111111;
background-color:#ff90ba;
} .son1{
/* 这里设置son1的浮动方式*/
float:left;
} .son2{
/* 这里设置son1的浮动方式*/
float:left;
} .son3{
/* 这里设置son1的浮动方式*/
float:right;
} </style>
</head>
<body>
<div class="father">
<div class="son1">Box-1</div>
<div class="son2">Box-2</div>
<div class="son3">Box-3</div>
<p>这里是浮动框外围的文字,这里是浮动框外围的文字,这里是浮动框外围的文字,这里是浮动框外围的文字,这里是浮动框外围的文字,这里是浮动框外围的文字,这里是浮动框外围的文字,这里是浮动框外围的文字,这里是浮动框外围的文字.</p>
</div>
</body>
</html>

说明:div1、div2左浮动,div3右浮动,p文字被夹中间。

div1 div3 左浮动 div2 右浮动

代码:

<!DOCTYPE html PUBliC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>float属性</title>
<style type="text/css">
body{
margin:15px;
font-family:Arial; font-size:12px;
} .father{
background-color:#ffff99;
border:1px solid #111111;
padding:5px;
} .father div{
padding:10px;
margin:15px;
border:1px dashed #111111;
background-color:#90baff;
} .father p{
border:1px dashed #111111;
background-color:#ff90ba;
clear:right;
} .son1{
/* 这里设置son1的浮动方式*/
float:left;
} .son3{
/* 这里设置son3 的浮动方式*/
float:right;
} .son2 {
/* 这里设置son2 的浮动方式*/
float:left;
} </style>
</head>
<body>
<div class="father">
<div class="son1">Box-1</div>
<div class="son2">Box-2</div>
<div class="son3">Box-3<br/>Box-3<br/>Box-3<br/>Box-3<br/></div> <!-- 换行重新占据了三行内容 -->
<p>这里是浮动框外围的文字,这里是浮动框外围的文字,这里是浮动框外围的文字,这里是浮动框外围的文字,这里是浮动框外围的文字,这里是浮动框外围的文字,这里是浮动框外围的文字,这里是浮动框外围的文字,这里是浮动框外围的文字.</p>
</div>
</body>
</html>

说明:有了br之后,浮动元素所在行又被重新占据了,p元素不会上来填充。

代码:

<!DOCTYPE html PUBliC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>float属性</title>
<style type="text/css">
body{
margin:15px;
font-family:Arial; font-size:12px;
} .father{
background-color:#ffff99;
border:1px solid #111111;
padding:5px;
} .father div{
padding:10px;
margin:15px;
border:1px dashed #111111;
background-color:#90baff;
} .father p{
border:1px dashed #111111;
background-color:#ff90ba;
clear:right;
} .son1{
float:left;
/* 这里设置son1的浮动方式*/ } .son2{
/* 这里设置son1的浮动方式*/ float:left;
} .son3{
/* 这里设置son1的浮动方式*/
float:right;
} .father .clear{
margin:0;
padding:0;
border:0;
clear:both; } </style>
</head>
<body>
<div class="father">
<div class="son1">Box-1</div>
<div class="son2">Box-2</div>
<div class="son3">Box-3</div>
<div class="clear"></div>
<p>这里是浮动框外围的文字,这里是浮动框外围的文字,这里是浮动框外围的文字,这里是浮动框外围的文字,这里是浮动框外围的文字,这里是浮动框外围的文字,这里是浮动框外围的文字,这里是浮动框外围的文字,这里是浮动框外围的文字.</p> </div>
</body>
</html>

说明:添加一个clear:both;属性之后,之前的空当地方就会被清理掉,p元素就只能另起一行了。

css案例学习之float浮动的更多相关文章

  1. 【CSS学习】--- float浮动属性

    一.前言 浮动元素以脱离标准流的方式来实现元素的向左或向右浮动,并且浮动元素还是在原来的行上进行浮动的.float浮动属性的四个参数:left:元素向左浮动:right:元素向右浮动:none:默认值 ...

  2. CSS| position定位和float浮动

    对基础知识再度做个巩固和梳理. 一.position定位 (一):position的属性 1.absolute:生成绝对定位的元素,相对于最近一级定位不是static的父元素来进行定位: 2.rela ...

  3. CSS 案例学习

    1.样式 display:inline-block;可改变a标签,合其可定义宽高 2.a:hover表示鼠标经过 3.background:url(110.png) bottom 表示:给链接一个图片 ...

  4. css案例学习之table tr th td ul li实现日历

    效果 代码 <html> <head> <title>Calendar</title> <style> <!-- .month { b ...

  5. css案例学习之ul li dl dt dd实现二级菜单

    效果 代码实现 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www ...

  6. css案例学习之盒子模型

    定义:每个盒子都有:边界.边框.填充.内容四个属性: 每个属性都包括四个部分:上.右.下.左:这四部分可同时设置,也可分别设置:里的抗震辅料厚度,而边框有大小和颜色之分,我们又可以理解为生活中所见盒子 ...

  7. css案例学习之继承关系

    代码 <html> <head> <title>继承关系</title> <style> body{ color:blue; /* 颜色 * ...

  8. css案例学习之用thead、tbody、tfoot实现漂亮的table布局

    首先说说thead.tbody.tfoot <thead> <tbody> <tfoot> 无论前后顺序如何改变, <thead> 内的元素总是在表的最 ...

  9. css案例学习之span边框实现的特殊效果

    bottom left bottom right top left top right 配合颜色来使用,实现一些神奇的效果 #menu a span{ height:; width:; /*borde ...

随机推荐

  1. python学习资料

    http://woodpecker.org.cn/diveintopython/ http://www.cnblogs.com/txw1958/archive/2012/12/10/A_Byte_of ...

  2. Ubuntu14.04安装PostpreSQL9.3.5记录

    安装参考:http://www.postgresql.org/download/linux/ubuntu/ y@y:~$ sudo apt-get install postgresql-9.3 pos ...

  3. Plus One 解答

    Question Given a non-negative number represented as an array of digits, plus one to the number. The ...

  4. [置顶] 教你如何搭建RobotFramework环境

    看到这篇文章的朋友,相信已经知道RobotFramework是干什么的了,我这里就不再赘述了. 搭建步骤: 1. 下载安装Python,下载地址http://www.python.org/getit/ ...

  5. oracle 库文件解决的方法 bad ELF interpreter: No such file or directory

    今天是2014-05-27,今天遇到一个lib问题,再次记录一下.这是一个案例,更是一种解决该问题的方法过程. 当我们在使用sqlplus 登陆unix数据库的时候,有可能出现类似:xxxxxx ba ...

  6. Jquery ui datepicker 设置日期范围,如只能隔3天

    最近的后台项目前端使用了jquery ui 日历控件自然就使用了jquery ui 的   datepicker 后台数据比较好大,一般是千万级的和百万级的关联,查询会很慢,所以后加想多加些过滤条件, ...

  7. MyEclipse 注册码

    MyEclipse 注册码和大家共享一下! 一:MyEclipse_6.0.1GA_E3.3.1_FullStackInstaller注册码 Subscriber:javp Subscription ...

  8. 新生赛(2) problem 2 丁磊养猪

    Problem B Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Sub ...

  9. 查看Linux操作系统版本

      1.查看内核版本命令: [root@server1 Desktop]# cat /proc/version Linux version 2.6.32-358.el6.x86_64 (mockbui ...

  10. android中跨进程通讯的4种方式

    转自:http://blog.csdn.net/lyf_007217/article/details/8542359 帖子写的很好.看来一遍,试了一遍,感觉太有意义.必须转过来! android中跨进 ...