作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我目前正在使用一个居中的包装器(以 margin 0 auto 为中心)。现在我想要一个从左边开始的容器,直到居中的 wrapper 开始。对于这个给定的 margin 规范,这可能吗?
我真的很感激一些提示!
另见 fiddle : http://jsfiddle.net/TQhEa/1/
我现在拥有的:
我想要的:
我的代码:
<body>
<div id="page-wrapper">
<p><---- how can i cover the left side only with red without javascript but keeping the "0 auto margin?"
</div>
</body>
我的 CSS:
body, html{
width:100%;
height:100%;
top:0;
margin:0;
background-image: url('http://www.art-wallpaper.net/Full-Size-HD-Wallpaper29/images/HD%20Widescreen%20Wallpaper%2059.jpg');
background-repeat:no-repeat;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
#page-wrapper{
background-color:red;
margin: 0 auto;
width: 400px;
top:0;
margin-top:0;
height:100%;
}
p {
padding:0;
margin:0;
font-size:30px;
}
}
最佳答案
最简单的方法是设置background-color
和background-image
的位置。查看this piece of code :html
<div id="page-wrapper">content</div>
CSS
body {
margin: 0;
background: #c11 url(http://placekitten.com/1000/1000) 100% 0 no-repeat;
}
#page-wrapper {
width: 400px;
height: 1000px;
background: #ccc;
margin: 0 auto;
}
关于html - 尽管有 :0 auto with CSS?,但有没有办法覆盖 margin-left,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15656008/
我是一名优秀的程序员,十分优秀!