0

我目前的部分 HTML 看起来有点像这样。这是一个简化版本。

<div id="content">
   <div id="screenshot">
      <img src="res/screenshot.png" />
   </div>
   <div id="introduction">
      <p>This is just some text</p>
   </div>
</div>

我的 CSS 看起来像这样。

#content {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    background: blue;
}

#screenshot img {
    padding-top: 10px;
    padding-bottom: 10px;
    float: left;
}

#introduction {
    position: relative;
    top: -100%;
    left: 200px;
    width: 500px;
    height: 100%;
}

我的问题是“背景:蓝色;” 仅选择图像,但不环绕文本。顺便说一句,我知道如何将文本背景设置为蓝色,但我需要通过#content. 如果它可以提供帮助,则#content' 的父级是 CSS 中的 this。基本上,我需要的是,如果我对此做一些事情#content,它会影响两个孩子的 div。它只影响#screenshots目前。:/

#content-wrapper{
    position: absolute;
    width: 100%;
    height: 340px;
    left: 0;
    top: 50%;
    margin-top: -170px;
}

谢谢, zeokila

编辑:我需要的是,如果我对此做一些事情#content,它会影响两个孩子的 div。它只影响#screenshots目前。:/

4

2 回答 2

2

尝试为#content.

当一个元素被绝对定位时,它的宽度不再默认为 100%。

于 2012-08-05T17:27:11.043 回答
0

难道不应该...

background-color:blue;

你也可以继承背景的颜色;

如果它如您所说的那样显示图像,那么也可以在 div 中添加一个宽度 | 高度。

或者你可以试试

#content > #introduction > P {
    background-color:blue;
}
于 2012-08-05T17:26:27.863 回答