gpt4 book ai didi

html - 如何在保持相同图像背景的同时在 div 中制作 div

转载 作者:太空宇宙 更新时间:2023-11-04 14:01:41 26 4
gpt4 key购买 nike

我在第一个 div 上有一个图像背景。然后我想要一个 div(为方便起见,橙色背景显示在这里)和另一个带有评论的框(称为“评论框”)“上方”。

问题是我不希望“橙色区域”的内容显示在它下面。

这是我目前拥有的:

enter image description here我当前代码的问题是,我放在“橙色区域”div 中的某些内容确实位于评论框下方,这很丑陋。

这里有一个 jsfiddle:http://jsfiddle.net/uu0xe2xL/1/ :

HTML

<body class='example-page'>

<div id="content">
<div class="page-main-image" >
</div>
<!--div with orange background -->
<div id="orange-zone">
</div>
<!-- comment box -->
<div class="comment-box comment" style="opacity: 1;">
xxx it's cool to comment<br/>
nice one dude
</div>
</div>
</body>

CSS

html {
height:100%;
}

body.example-page {
height:100%;
}

#content {
height: 100%;
margin-top: 18px;
@media (max-width: 767px) {
margin-top: 9px;
}
}
.page-main-image {
height: 100%;
background: url('http://www.thedrum.com/uploads/drum_basic_article/115509/main_images/BBCb.jpg'); background-size: cover; background-repeat: no-repeat;
}

#orange-zone {
position:fixed;
top:10%;
left:30%;
width:100%;
height:100%;
background-color:orange;
}
.treasure{
position: absolute;
}

.comment-box {
position:relative;
text-align: center;
background-color: rgba(255, 255, 255, 0.3);
padding: 10px;
bottom:5%;
right:5%;
}
.comment {
position:absolute;
}

这是我想要实现的目标

enter image description here

请注意,橙色永远不会出现在评论区下方,但在“评论框”下方仍然可以看到带有岛屿的背景图片,这正是我想要实现的目标。

我还想将文本放在橙色区域,但我不能将背景图像放在 body 标签中,因为它必须在菜单之后立即开始,所以它有自己的 a。

随时更新此 jsfiddle

最佳答案

主要思想是使用边框来创建纯色背景。请参阅以下内联演示和说明。

JsFiddle Demo

html, body {
height: 100%;
margin: 0;
}
/* setting up background image */
.container {
background: url("http://i.imgur.com/V4xzKOv.jpg") 0 0 no-repeat;
background-size: cover;
position: relative;
height: 100%;
}
/* creating the borders */
.container:before {
content: "";
display: block;
background-color: rgba(0, 0, 0, .25);
position: absolute;
right: 20px;
bottom: 20px;
border-style: solid;
border-color: orange;
border-width: 20px 30px 90px 190px;
width: 120px;
height: 60px;
}
/* positioning the text */
.container p {
position: absolute;
width: 280px;
right: 50px;
bottom: 45px;
overflow: auto;
padding: 0;
margin: 0;
}
/* creating placeholder and floating it */
.container p:before {
content: "";
float: right;
width: 120px;
height: 60px;
}
<div class="container">
<p>Gingerbread tootsie chocolate. Cheesecake gummi bears I love caramels gummies cake oat cake tootsie roll. Ice cream sesame snaps. Biscuit gingerbread I love gummi dragée bear chocolate cheesecake.</p>
</div>

关于html - 如何在保持相同图像背景的同时在 div 中制作 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29578449/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com