2012-08-05 73 views
0

目前,我有我的HTML,看起来有点像这样的组成部分。这是一个简化版本。CSS - 股利不会算子格

<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。 基本上,我需要的是,如果我做一些事来#content,它会影响孩子的div。它目前仅影响#screenshots。 :/

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

感谢,zeokila

编辑:我需要的是,如果我做一些事来#content,它会影响孩子的div。它目前仅影响#screenshots。 :/

回答

2

尝试指定宽度#content

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

+0

谢谢,这解决了我的问题。对不起,我没有解释太多,我不知道如何,但它解决了我。 – 2012-08-05 17:32:14

+0

不用担心。很高兴工作! – 2012-08-05 17:33:27

0

难道不应该是...

background-color:blue; 

而且你总是可以继承背景的颜色;还高度到div |

如果它显示的图像就像你说的,那么也许增加的宽度。

或者你可以尝试

#content > #introduction > P { 
    background-color:blue; 
} 
+0

背景:蓝色是速记http://www.w3schools.com/css/css_background.asp – jrubins 2012-08-05 17:29:21

+0

是的,但它使用背景色更加整洁: – 2012-08-05 17:30:06