我制作了一张图片,以便更轻松地解释我之后的事情:
Image Illustration http://bayimg.com/image/eabahaaci.jpg
我已经阅读了关于这个主题的其他一些问题,但我不确定这些解决方案对我有用,因为我的div需要可扩展并随着更多内容的增加而增长。
有谁知道如何以简单的方式实现这一目标?
答案 0 :(得分:2)
#body {background: transparent url(background/image.png) 0 0 repeat-y;
}
#content-wrap {width: 60%;
margin: 0 auto;
background: transparent url(partially/transparent/60percent-opaque.png) 0 0 repeat;
}
#main-content {width: 90%;
margin: 1em auto 0 auto;
background-color: #fff;
}
#footer {width: 90%;
margin: 1em auto 0 auto;
background-color: #fff;
}
这会将部分透明的.png
图片设置为#content-wrap
部分的背景,并为div设置纯色背景(我使用了#main-content
和{{1}但是他们有相同的风格,所以你可以使用#footer
并缩短css。
#content-wrap div
<div id="content-wrap">
<!-- this is the outer wrapping div -->
<div id="main-content">
<!-- this I'm assuming is the main content portion -->
</div>
<div id="footer">
<!-- the name explains my assumption, I think... -->
</div>
</div>
body {
background: #fff url(http://i.stack.imgur.com/9uIxu.png) 0 0 repeat;
}
#content-wrap {
width: 60%;
margin: 1em auto;
padding: 1em 0;
background-color: rgba(0, 0, 0, 0.3);
-moz-border-radius: 1em;
-webkit-border-radius: 1em;
}
#content-wrap div {
width: 90%;
margin: 1em auto;
background-color: #fff;
}
#content-wrap div p {
margin: 1em 0;
}
...如果您知道您的观众将使用FF3.x(可能还有基于webkit的浏览器),您可以使用<div id="content-wrap">
<div id="main-content">
<p>I presume the main content will sit here...</p>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium
quis, sem. Nulla consequat massa quis enim.</p>
<p>Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean
vulputate eleifend tellus.</p>
<p>Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue.
Curabitur ullamcorper ultricies nisi.</p>
<p>Nam eget dui. Etiam rhoncus. Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus.
Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante. Etiam sit amet orci eget eros faucibus tincidunt. Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, augue velit
cursus nunc,</p>
</div>
<div id="footer">
<p>This'd be the footer. And so on...</p>
</div>
</div>
来定义背景颜色(红色= 0,绿色= 0,蓝色) = 0,alpha = 0.4或40%不透明(或60%透明) - 值介于background-color: rgba(0,0,0, 0.6);
(完全透明)和0
之间(完全不透明)。)
使用1
颜色可以防止在尝试使子项可见时使用rgba
使父div透明的问题。但是由于浏览器的采用,它的用途有限,当然......
我的网站上有一个工作演示: http://www.davidrhysthomas.co.uk/so/transparent.html
答案 1 :(得分:0)
您需要1px高的图像切片才能获得透明度 还有一个用于底部的圆形角落
.background{
background:url(/image/path);
}
.wrapper{
background:url(/image/path/trans.png) repeat-y;
width:500px;
position:relative;
}
.wrapper .bottom{
background:url(path/to/image) no-repeat;
position:absolute;
bottom:0;
left:0;
height:20px;
}
.inner{
background:#fff;
margin:10px;
}
我已经将宽度和边距提高了。你应该自己选择合适的尺寸