html - 尝试使其适合元素时背景图像被切断

标签 html css background-image

the video borders in this image are how I am trying to mine to look The picture on top of the border keeps cutting out on top.我试图让我的 background-image 适合我的视频,每次我尝试让它变大时,顶部都会被切断,我似乎无法让它真正适合视频并看起来好。

我希望图像成为我的视频的边框。我很确定它与视频 div 外面的图像有关,但我可能会弄错。任何帮助表示赞赏!

HTML:

<div class="videos">
    <div id="video1">
        <iframe width="450" height="315" src="https://www.youtube.com/embed/vr0dXfQQfNU" frameborder="0" allowfullscreen></iframe>
    </div>
    <div id="video2">
        <iframe width="450" height="315" src="https://www.youtube.com/embed/fevkx229XBs" frameborder="0" allowfullscreen></iframe>
        <!--h <img src="images/vidborder2.png" class="vidborder2">-->
    </div>
</div>

CSS:

div#video1 {
    float: right;
    background-image: url(images/vidborder.png);
    background-repeat: no-repeat;
    display: table-cell;
    vertical-align: middle;
    text-align: center;
}
div#video2 {
    background-image: url(images/vidborder2.png);
    background-repeat: no-repeat;
    display: table-cell;
    vertical-align: middle;
    text-align: center;
    background-size: 80%;
    background-position: center;
}
.videos {
    margin-top: 40px;
}

最佳答案

您非常接近解决方案。

I am pretty sure it has something to do with the image going out side the video div, but I could be mistaken.

图像不会超出 div .

为了使图像看起来像视频的边框,我们必须添加 paddingdiv . (@tylerism 在评论中也提到了)

看看这个 fiddle .

以下是我对您的代码所做的更改。 <罢工>

<罢工>
text-align: center;
background-size: 80%;

<罢工>

padding: 10px 10px;

我用了这个image用于测试目的。您可以替换 url。

关于html - 尝试使其适合元素时背景图像被切断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31121531/

相关文章:

html - 无法更改表格单元格宽度

html - CSS 不适用于组织结构图(使用 ul 和 li 构建)

html - 将多个轮播元素合并到 flex 网格中

html - 如何使文本严格显示在与上述图像的左侧钻孔对齐的图像底部 - 无论父对齐方式如何?

html - 滚动时将页眉固定在 Hop,底部固定页脚

javascript - 如何使用 Javascript 删除查询字符串中的 URL 编码

jquery - 如何获取来自 flatpickr 的日期输入?

css - 如果 :pseudo elements are not available?,还有哪些其他方法可用于裁剪/剪辑背景图像

html - 如何在不重叠网页内容的情况下减小背景图片的大小

html - CSS 显示调整大小和裁剪的图像