请教2-6视频的m-bottom中img03左浮动时掉了下去,为什么没有实现效果呢?

请教2-6视频的m-bottom中img03左浮动时掉了下去,为什么没有实现效果呢?

我后来设置了另一个class=img3

.main .middle  .m-bottom  .img3{

transform: translate(320px, -310px)

}

按照这个css代码img03浮上去,为什么我按照老师的视频里的代码打的,为什么会出现这种情况呢?我是哪一步骤没做好?请老师指导一下,万分感谢!!

正在回答

登陆购买课程后可参与讨论,去登陆

3回答

同学你好,是因为同学第二个图片部分占据的宽度较大,我们可以按f12查看下控制台:

http://img1.sycdn.imooc.com//climg/5e12c80b096ae71909750802.jpg

第二列实际占据的宽度为350px。是因为同学的标签嵌套错了,把第三张图片放到了第二张里,所以布局就乱掉了。修改参考:

http://img1.sycdn.imooc.com//climg/5e12ca6b09cdf01f09920530.jpg

再将下方的translate去掉,按顺序自动排列就可以:

http://img1.sycdn.imooc.com//climg/5e12caaa09d4a87506390172.jpg

如果我的回答帮助到了你,欢迎采纳,祝学习愉快~

提问者 慕后端1196960 2020-01-06 09:52:44

<!DOCTYPE html>

<html>

<head>

<title>CSS网页布局</title>

<meta charset="utf-8">

<style type="text/css" >

*{

padding: 0;

margin:0;

}

.header{

width:100%;

height:100px;

}

.header img{

width: 300px;

height:85px;

padding-left: 100px;

padding-top: 8px;

}

.header .logo{

float:left;

}

.header .nav{

float: right;

}

.header .nav ul {

padding-right: 100px;

}

.header .nav ul li{

float: left;

list-style: none;

width:80px;

height: 100px;

line-height: 100px;

font-size: 15px;

font-weight: bold;

color:#7d7d7d;

}

.main .top{

width:100%;

height: 600px;

}

.main .top img{

width:100%;

height: 600px;

}

.main .topLayer{

position: absolute;

top: 100px;

left: 0;

background-color: #000;

width:100%;

height:600px;

opacity: 0.5;

}

.main .topLayer-top{

width: 500px;

height: 300px;

/*background-color: blue; 去掉蓝色背景*/

position: absolute;

top: 400px;

margin-top: -150px;

z-index: 2;

right:50%;

margin-right:-250px;

}

.main .topLayer-top .word{

padding-top: 100px;

color:#fff;

font-size: 45px;

font-weight: bolder;

text-align: center;

font-family: "微软雅黑";

}

.main .topLayer-top button{

width:200px;

height:60px;

margin-top: 50px;

color:#fff;

background-color: #F5704F;

font-family: "微软雅黑";

text-align: center;

font-weight: bolder;

font-size: 14px;

border-radius:8px;

margin-left:150px;

}


.main .middle{

width:1000px;

margin:0 auto;

}


.main .middle .m-top .commen{

float:left;

width:33.3%;

padding-top: 50px;

text-align: center;


}

.main .middle .m-top .commen img{

width:100px;

height:100px;

}

.main .middle .m-top .commen .comm{

font-size: 20px;

color:#7D7C7F;

font-weight: bold;

padding-top: 20px;

}


.main .middle .m-middle{

font-size: 22px;

color:#E19796;

font-weight: bold;

padding-top: 50px;

font-style: italic;

text-align: center;

padding-bottom: 50px;

}



.main .middle .m-bottom{

width: 990px;

margin:0 auto;

}


.main .middle  .m-bottom  .m-com{

padding:10px;

float: left;

text-align: center;

font-size: 20px;

font-weight: bold;

}


.main .middle .m-bottom .m-com img{

width:310px;

height:260px;

}

.main .middle  .m-bottom  .img3{

transform: translate(340px, -348px)

}


.main .middle .m-bottom .m-com .des1{

color:#7D7C7F;

padding-top: 20px;


}


.main .middle .m-bottom .m-com .des2{

color:#BDBDBC;

padding-top: 10px;


}

.main .bottom{

background-color: #F9F9F9;

transform: translate(12px, -300px)

}


.main .bottom .content{

width:1000px;

margin: 0 auto;

}

.main .bottom .content .title{

text-align: center;

font-size: 20px;

font-weight: bold;

color: #7D7C7F;

font-family: "微软雅黑";

padding-bottom: 50px;


}


.main .bottom .content .pic-content dl{

float: left;

width: 470px;

margin: 10px 12px;

}

.main .bottom .content .pic-content dl img{

width: 470px;

height: 460px;

}


.main .bottom .content .pic-content dl .word{

padding-top: 20px;

font-size: 20px;

font-weight: bold;

color: #7D7C7F;

padding-bottom: 50px;

}

.footer{

width: 100%;

height: 100px;

background-color: #292C35;

color: #ffffff;

text-align: center;

line-height: 100px;

font-family: "微软雅黑";

font-size: 15px;

}

</style>

</head>

<body>

<!--header-->

<div class="header">

<div class="logo">

<img src="image/logo.png" alt="pic">

</div>

<div class="nav">

<ul>

<li>首页</li>

<li>图片</li>

<li>视频</li>

<li>手记</li>

</ul>

</div>

</div>

<!--main container-->

<div class="main">

<div class="top">

<img src="image/1.jpeg" />

</div>

<!--topLayer-->

<div class="topLayer"></div>

<div class="topLayer-top">

<div class="word">MY BEAUTIFUL LIFE</div>

<button>LOOK MORE &gt;</button>

</div>

<div class="middle">

<div class="m-top">

<div class="commen weibo">

<img src="image/weibo.png">

<div class="comm">MICROBLOG</div>

</div>

<div class="commen weixin">

<img src="image/weixin.png">

<div class="comm">WECHAT</div>

</div>

<div class="commen qq">

<img src="image/QQ.png">

<div class="comm">QQ</div>

</div>

</div>

<div style="clear:both;"></div>

<div class="m-middle">

"I want to give good things to record down,<br/>after recall will be very beautiful."

</div>

<div class="m-bottom">

<div class="m-com">

<img src="image/03-01.jpg" />

<div class="des1">Cool Image</div>

<div class="des2">Record The Picture</div>

</div>

<div class="m-com">

<img src="image/03-02.jpg" />

<div class="des1">Great Picture</div>

<div class="des2">Record The Picture</div>

<div class="m-com img3">

<img src="image/03-03.jpg" />

<div class="des1">Cool Image</div>

<div class="des2">Record The <span>Picture</span></div>

</div>

</div>

<div style="clear:both;"></div>

<div class="bottom">

<div class="content">

<div class="title">FROM THE PHOTO ALBUM</div>

<div class="pic-content">

<dl>

<dt>

<img src="image/04-01.jpg" />

</dt>

<dd class="word">Life is like a book, just read more and more refined, more write more carefully. When read, mind open, all things have been indifferent to heart. Life is the precipitation.</dd>

</dl>

<dl class="img4">

<dt>

<img src="image/04-02.jpg">

</dt>

<dd class="word">Life is like a cup of tea, let people lead a person to endless aftertastes. You again good taste, it will always have a different taste, different people will have different taste more.</dd>

</dl>

</div>

<div style="clear: both;">

</div>

</div>

</div>

<div style="clear:both;"></div>

<!--footer-->

<div class="footer">© 2016 imooc.com  京ICP备13046642号</div>


</body>

</html>


好帮手慕粉 2020-01-04 14:07:08

同学你好,建议同学将完整的代码粘贴上来呢,这样老师是不知道同学到底是哪个地方出了问题的。

祝学习愉快!

  • 提问者 慕后端1196960 #1
    .main .middle .m-bottom{ width: 990px; margin:0 auto; } .main .middle .m-bottom .m-com{ padding:10px; float: left; text-align: center; font-size: 20px; font-weight: bold; } .main .middle .m-bottom .m-com img{ width:310px; height:260px; } .main .middle .m-bottom .img3{ transform: translate(340px, -348px) } .main .middle .m-bottom .m-com .des1{ color:#7D7C7F; padding-top: 20px; } .main .middle .m-bottom .m-com .des2{ color:#BDBDBC; padding-top: 10px; } 设置左浮动时我要额外给img03设置一个transform才能浮上去,不然就掉在img02下面。我也设置了m-bottom的width了,所以很困惑,谢谢老师哦
    2020-01-05 11:28:03
  • 卡布琦诺 回复 提问者 慕后端1196960 #2
    辛苦同学再补充一下html代码哦,祝学习愉快!
    2020-01-05 19:20:20
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师