为了账号安全,请及时绑定邮箱和手机立即绑定

有了绝对定位之后为什么水平居中效果没有消失呢?

有了绝对定位之后为什么水平居中效果没有消失呢?

一壶时光 2018-07-22 13:00:27
<!DOCTYPE html><html><head> <meta charset="utf-8"> <style type="text/css"> body{margin: 0;background:#333;} ul{margin: 0;padding: 0;} li{list-style: none;} #pic{width: 400px;height:500px;position:relative;margin: 0 auto;} #pic img{width: 400px;height:500px;} #pic ul{position: absolute;top:0;right: -50px;} #pic li{width: 40px;height: 40px;margin-bottom: 4px;background:#666;} #pic .active{background:yellow; } #pic p,#pic span{width: 400px;height: 30px;line-height: 30px;color:red;position: absolute;left:0;text-align: center;} #pic span{top: 0;} #pic p{bottom: 0;} </style> <script type="text/javascript"> </script></head><body> <div id="pic">  <img src="C:/Users/冯新星/Desktop/Saved Pictures/pic.jpg"/>  <span>数据加载中</span>  <p>图片加载中</p>  <ul>   <li class="active"></li>   <li></li>   <li></li>   <li></li>  </ul> </div></body></html>为什么我代码定位的是在父元素的left:0;处,显示的却是在水平居中位置呢?
查看完整描述

1 回答

?
奋斗好青年

TA贡献69条经验 获得超30个赞

不大理解你想问的意思,你是不是想要整块内容不居中呢?那么去掉#pic中的:margin: 0 auto;这个样式即可啦

查看完整回答
反对 回复 2018-07-23
  • 1 回答
  • 0 关注
  • 1274 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信