老师我完成的对吗?还有什么地方需要优化的吗?

老师我完成的对吗?还有什么地方需要优化的吗?

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title></title>
  <style type="text/css">
   body{margin: 0;padding: 0;width: 1000px;height:350px;
    margin:auto auto;
    position: absolute;
    left: 0;right: 0;top: 0;bottom: 0;}
   .one{width: 1000px;height: 250px;background:#4c77f2;overflow: hidden;}
   img{display: block;}
   .num1 img{float: left;position: relative;top: 17.5px;margin-left:93px;}
   .num2 img{float: right;position: relative;top: 18px;margin-right:93px;}
   .two{width: 1000px;height: 100px;background:#ed817e;overflow: hidden;}
   .num3,.num4{float: left;position: relative;top: 20px;margin-left: 100px;}
   .num5{float: right;position: relative;top: 20px;margin-right:100px;}
  </style>
</head>
<body>
 <div class="one">
  <div class="num1" ><img src="http://img1.sycdn.imooc.com/climg//58c0f808000129a303600215.jpg"></div>
  <div class="num2" ><img src="http://img1.sycdn.imooc.com/climg//58c0f819000198a703600214.jpg"></div>
 </div>
 <div class="two">
  <div class="num3"><img src="http://img1.sycdn.imooc.com/climg//58c0f81d0001fe4402000060.jpg"></div>
  <div class="num4"><img src="http://img1.sycdn.imooc.com/climg//58c0f8220001dfce02000060.jpg"></div>
  <div class="num5"><img src="http://img1.sycdn.imooc.com/climg//58c0f8780001c74602000060.jpg"></div>
 </div>
</body>
</html>

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

正在回答

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

2回答

同学你好, container里的height确实是350;老师给出的示例中, 设置120px只是为了让整体内容与页面上方有一定的空白距离。使用margin:120px auto只实现了水平居中,没有考虑垂直居中。 如果要是整体内容垂直居中,同学使用绝对定位的方式实现是对的,可以在container中添加上这段代码, 示例:

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

同学很细心, 考虑的也很全面, 这点很棒, 继续加油哦~~

如果帮助到了你, 望采纳

祝学习愉快~~~

好帮手慕慕子 2019-04-19 10:55:56

同学你好, 效果实现的可以。

代码可以优化一下的就是: 一般不给body设置固定的宽高, 建议:这里可以使用一个大div包裹所有的元素, 通过margin: 120px auto;实现水平居中, 示例:

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

样式设置:

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

如果帮助到了你,欢迎采纳

祝学习愉快~~~

  • 提问者 原来是晓琪_ #1
    老师container里height应该是350吧? 还有是如何确定120px就可以垂直居中了呢?
    2019-04-19 12:21:33
问题已解决,确定采纳
还有疑问,暂不采纳

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

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

0 星
请稍等 ...
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

在线咨询

领取优惠

免费试听

领取大纲

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