html - 如何添加 div 背景的 margin-top?

标签 html css background-image background-position

我有这个page ,其中我在一个框内显示视频,并希望我的背景图像有一些“顶部边距”,这样它就不会显示在框的边缘。我尝试添加 background-position: 10%,但它不起作用。

现在看起来像这样:

enter image description here

这是我的代码:

.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>

我也尝试添加 .bg-image img {margin-top:10%;},但后来一切都失败了,我只想要背景图片。

最佳答案

尝试给出两个坐标:

background-position: 0 50px;

在下面的例子中,背景图片的上边距为 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>

关于html - 如何添加 div 背景的 margin-top?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30103155/

相关文章:

jquery - 更改事件选项卡上的父 Div 背景颜色

html - CSS 背景图像未按预期工作

javascript - Jquery 在动态创建的 div 上淡入背景图像

Css div float 在 flex 背景图片上

javascript - 如何在选项卡式面板中编写内容?

javascript - 如何访问从 Javascript 函数中的 Controller 传递的 HTML 模板参数

html - 垂直定位元素

html - 网站在 iPhone 上旋转 180 度

html - CSS 下拉菜单

html - CSS float 、溢出和绝对位置