请问我这样设置浮动属性到底错在哪?父元素崩坏还是解决不了

weixin_40434598 2017-10-04 03:10:43
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<style type="text/css">

.content{width:100%;
height:auto;
border:1px solid #ccc;
padding:10px;
}
.part1{width: 100%;
float:left;
clear: both;
}
.test1,.test2,.test3
{border:1px solid #ccc;
width:200px;
height:auto;
float:left;
margin: 10px;
}
</style>
</head>
<body>
<div class="content">
<div class="part1">
<div class="test1">
<img src="http://climg.mukewang.com/590fe9770001e63102400135.jpg" width="200px" height="100px">
<p>欢迎来到慕课网学习新知识!</p>
</div>
<div class="test2">
<img src="http://climg.mukewang.com/590fe97d00011bda02400135.jpg">
<p>欢迎来到慕课网学习新知识!</p>
</div>
<div class="test3">
<img src="http://climg.mukewang.com/590fe982000150ba02400135.jpg">
<p>欢迎来到慕课网学习新知识!</p>
</div>

</div>

</div>
</body>
</html>
...全文
232 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
刚才发的又打错了,第二:样式为 .content 的<div>里还要加 overflow:hidden; 不过也可以用其它方式去清除浮动。
  • 打赏
  • 举报
回复
第一:你第一张图片<img>标签里图片设设置了 width="200px",height="100px" 而另2张没要,其实你在<style>里加个 mg {width:100%},就不用去每个<img>标签去设置了。 第二:样式为 .content 的<div>里还要加 ovoverflow:hidden;
hongmei85 2017-10-04
  • 打赏
  • 举报
回复

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="gb2312">
        <style type="text/css">
            
            .content{width:100%;
                height:auto;
                border:1px solid #ccc;
                padding:10px;
            }
            .part1{width: 100%;
            	float:left; 
            	clear: both;
            }
            .test1,.test2,.test3
            {border:1px solid #ccc;
                width:200px;
                height:auto;
                float:left;
                margin: 10px;
            }
						img{width:200px;height:100px}
						.clear{clear: both;}
        </style>
</head>
<body>   
         <div class="content">
             <div class="part1">
                 <div class="test1">
                     < img src="http://climg.mukewang.com/590fe9770001e63102400135.jpg" width="200px" height="100px">
                     <p>欢迎来到慕课网学习新知识!</p >
                 </div>
                 <div class="test2">
                     < img src="http://climg.mukewang.com/590fe97d00011bda02400135.jpg">
                     <p>欢迎来到慕课网学习新知识!</p >
                 </div>
                 <div class="test3">
                     < img src="http://climg.mukewang.com/590fe982000150ba02400135.jpg">
                     <p>欢迎来到慕课网学习新知识!</p >
                 </div>
                 
             </div>
						 <div id="" class="clear"></div>
             
         </div>
</body>
</html>
天际的海浪 2017-10-04
  • 打赏
  • 举报
回复
样式没问题,图片固定下大小就好

         <div class="content">
             <div class="part1">
                 <div class="test1">
                     <img src="http://climg.mukewang.com/590fe9770001e63102400135.jpg" width="200px" height="100px">
                     <p>欢迎来到慕课网学习新知识!</p>
                 </div>
                 <div class="test2">
                     <img src="http://climg.mukewang.com/590fe97d00011bda02400135.jpg" width="200px" height="100px">
                     <p>欢迎来到慕课网学习新知识!</p>
                 </div>
                 <div class="test3">
                     <img src="http://climg.mukewang.com/590fe982000150ba02400135.jpg" width="200px" height="100px">
                     <p>欢迎来到慕课网学习新知识!</p>
                 </div>
                 
             </div>
             
         </div>
一、网页设计与策划01 网页与网站的概念02 网页核心技术(HTML/CSS/JAVASCRIPT)简介03 什么是HTML04 什么是CSS05 什么是JavaScript06 网页的设计流程07 HTML5概述、浏览器及内核08 编写第一个HTML页面09 HTML页面基本结构10 章节练习二、网页的基本实现(HTML标签)01 HTML基本语法02 标签及属性03 标签04 标题标签05 段落标签06 水平分隔线标签07 换行标签08 文本的格式化标签09 特殊字符标签10 图像标签14 相对路径与绝对路径11 章节练习-《清平乐》12 章节练习-《李清照简介》13 章节练习-《家电排行》15 章节练习-《百度网简介》16 超级链接标签17 锚点链接18 影像地图19 《table》表格标签20 无序列表标签21 有序列表标签22 定义列表标签23 章节练习-《工资明细》24 章节练习-《我的电脑》25 章节练习-《在线考试》三、层叠样式表01 CSS简介02 CSS样式规则03 CSS样式的调用方法04 标签选择器05 类选择器06 ID选择器07 标签指定式选择器08 包含(后代)选择器09 群组选择器10 通配符选择器11 属性选择器12 关系选择器13 链接伪类选择器四、样式属性01 字体属性02 文本属性03 阴影效果04 对象内溢出文本05 背景设置06 定义列表的样式五、盒模型网页布局01 初识盒子模型02 边框属性(border)03 边距属性(padding与margin)04 圆角边框05 阴影效果06 浮动属性(float)07 元素定位(position)08 溢出属性(overflow)

61,112

社区成员

发帖
与我相关
我的任务
社区描述
层叠样式表(英文全称:Cascading Style Sheets)是一种用来表现HTML(标准通用标记语言的一个应用)或XML(标准通用标记语言的一个子集)等文件样式的计算机语言。
社区管理员
  • HTML(CSS)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧