I have this page, in which I am displaying a video inside a box, and want my background image to have some "margin-top" so it's not displayed touching the edge of the box. I tried to add background-position: 10%
, but it is not working.
我有这个页面,我在一个盒子里面显示一个视频,并希望我的背景图像有一些“边缘顶部”,因此它不会显示在框的边缘。我试图添加背景位置:10%,但它不起作用。
Right now it looks like this:
现在它看起来像这样:
And this is my code:
这是我的代码:
.eu {
height: auto;
width: 100%;
background: url(images/BODY-VERDE.png);
position: absolute;
top: 0;
}
.bg-image {
position: relative;
}
.bg-image img {
display: block;
width: 100%;
/* max-width: 1200px; */
/* corresponds to max height of 450px */
margin: 0 auto;
}
.container-video {
width: 100%;
height: auto;
background: url(images/BODY-VERDE.png);
margin: 0 auto;
overflow: auto;
}
<div class="bg-image" style="width: 70%;margin: 0 auto;">
<div class="eu">
<div class="text-sus">
<p>Set us perspiciatis</p>
<p style="text-align: center;color: white;font-size: 16px;">unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore</p>
</div>
<div class="video">
<img src="images/VIDEO.png" style="width:100%;height:auto;">
</div>
</div>
<img src="images/CU-PRETURI.png">
</div>
I also tried adding .bg-image img {margin-top:10%;}
, but then everything went down and I just want the background picture.
我也尝试添加.bg-image img {margin-top:10%;},但随后一切都下降了,我只想要背景图片。
1 个解决方案
#1
Try giving both coordinates:
尝试给出两个坐标:
background-position: 0 50px;
In the following example, the bg image has a top margin of 50px
在以下示例中,bg图像的上边距为50px
#wrapper {
width: 100%;
height: 300px;
border: 1px solid red;
background-image: url('http://www.bestmanspeechestoasts.com/wp-content/themes/thesis/rotator/sample-4.jpg');
background-position: 0 50px;
background-repeat: no-repeat;
}
<div id="wrapper"></div>
#1
Try giving both coordinates:
尝试给出两个坐标:
background-position: 0 50px;
In the following example, the bg image has a top margin of 50px
在以下示例中,bg图像的上边距为50px
#wrapper {
width: 100%;
height: 300px;
border: 1px solid red;
background-image: url('http://www.bestmanspeechestoasts.com/wp-content/themes/thesis/rotator/sample-4.jpg');
background-position: 0 50px;
background-repeat: no-repeat;
}
<div id="wrapper"></div>