1

我目前正在使用居中的包装器(以margin 0 auto为中心)。现在我想要一个从左侧开始的容器,直到居中的包装器开始。使用这个给定的保证金规格,这可能吗?

我真的很感激一些提示!

另见小提琴: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;
}
} 
4

3 回答 3

1

使用以下 CSS 再添加 1 个 DIV:

#left_div {
    position: absolute;
    left: 0;
    top: 0;
    width: 50%;
    height: 100%;
    background-color: #F00;
    display: table; /* note IE5-7 does not support this */
    z-index: 1;
}

并修改当前居中的 DIV$('#page-wrapper')以具有更高的z-index

于 2013-03-27T10:00:30.797 回答
1

最简单的方法是设置 的background-color和 位置background-image。查看这段代码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;
}
于 2013-03-27T10:05:59.880 回答
0

添加一个带有属性的额外 divposition: absolute; width: 50%; height: 100%;z-index: -1;

见:http: //jsfiddle.net/skeurentjes/TQhEa/3/

于 2013-03-27T10:08:17.833 回答