底部 ul 盒子为啥不会居中?设置了left:0;right:0;margin: auto;}

底部 ul 盒子为啥不会居中?设置了left:0;right:0;margin: auto;}

<!DOCTYPE html>

<html>

<head>

  <meta charset="UTF-8">

  <title></title>

  <style type="text/css">

    /*此处写代码*/

    *{margin:0;padding:0;}

    .go ol{list-style:none;display:inline-block;padding-left:100px;}

    .head{width:100%;height:100px;background:black;position:fixed;top:0;overflow:hidden;}

    .go{float:right;color:white;margin:35px 100px;}

    .img{float:left;width: 300px;height: 100px}

    .img img{display: block;width: 100%;height: 100%}

    .body{margin:100px 0;}

    .body img{display: block;width:100%;}

    /*图片是行级元素,要把他转换为块级元素才不会有缝隙。*/

    .footer{width:100%;height:100px;background:black;position:fixed;bottom: 0}

    /*.footergo{float:right;color:white;margin: 35px 22%;}*/

    .footergo{float:right;color:white;left:0;right:0;margin: auto;}

    .footergo ol{list-style:none;display:inline-block;padding-left:50px;padding-right:50px ;}

  </style>

</head>

<body>

  <!-- 此处写代码 -->

  <div class="head">

      <div class="img"><img src="http://img1.sycdn.imooc.com/climg//58c0d2d900016ce303000100.png"/></div>

      <ul class="go">

          <ol>课程</ol>

          <ol>职业路径</ol>

          <ol>实战</ol>

          <ol>猿问</ol>

          <ol>手记</ol>

      </ul>

  </div>

  <div class="body">

      <img src="http://img1.sycdn.imooc.com/climg//58c0eda50001e12416000480.jpg"/>

      <img src="http://img1.sycdn.imooc.com/climg//58c0edb80001c9f216000480.jpg"/>

      <img src="http://img1.sycdn.imooc.com/climg//58c0edc9000100d516000480.jpg"/>

  </div>

  <div class="footer">

        <ul class="footergo">

          <ol>课程</ol>

          <ol>职业路径</ol>

          <ol>实战</ol>

          <ol>猿问</ol>

          <ol>手记</ol>

      </ul>

  </div>

</body>

</html>

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

正在回答

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

2回答

同学你好,left:0;right:0;margin: auto;这几个属性设置居中,是要结合定位使用的哦。这里不没有定位,但是有右浮动,所以靠右边显示了。

建议:这里直接给ul添加内容居中即可,然后设置行高为100px,就可以实现垂直居中了。例:

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

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

  • 慕仰5025445 提问者 #1
    能否帮忙整理下,有哪几种居中方式,注意事项是啥?
    2020-06-16 18:03:03
好帮手慕糖 2020-06-16 18:13:23

同学你好,水平居中显示的方式有很多种, 需要根据实际布局方式的需要选择居中方式。例如:

(1)块级元素可以设置一个固定的宽度,使用margin:0 auto;实现水平居中

(2)行内元素和行内块元素可以直接给父级元素设置文本text-align:center;实现水平居中

(3)使用定位方式实现水平方向的居中

以上只是举了几个简单的例子, 同学可以在学习的过程中, 将自己实现水平居中的方法总结一下,方便以后布局的使用,且因为是自己实际操作之后进行的总结,印象也会更加深刻哦。

祝学习愉快~


问题已解决,确定采纳
还有疑问,暂不采纳

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

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

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

在线咨询

领取优惠

免费试听

领取大纲

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