html - 防止图像上的线性渐变溢出

标签 html css

我正在尝试重新创建 this当前页面,现在看起来不错,但是当我尝试添加 iphone 图片时,页面变得像 this我放在背景图像上的线性渐变溢出到底部,然后将按钮推开。有没有办法解决这个问题,使线性渐变只覆盖背景图像?谢谢你

#body {
    background: url(assets/bg_home.jpg) no-repeat center center fixed;
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: 100% 70%;
    background-position: top center;
    display: block;
    position: relative;
}

#body::before {
    content: "";
    background-image: linear-gradient(#1659e0, #489AEA);
    opacity: 0.5;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    position: absolute;
}
<div id="body">
    <nav>
        <!--navbar here-->
    </nav>

    <div class="container">
        <div class="row">
            <div class="col-md-8 content">
                <h1>Meet BestApp</h1>
                <h1>The new world for chat</h1>
                <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quis deleniti cumque, odit atque molestiae totam facere aliquam sed cum perspiciatis quam, at sequi, corporis distinctio. Fugit nam, nesciunt quaerat pariatur.</p>
            </div>
            <div class="col-md-4 image">
                <img src="assets/phone.jpg" alt="phone ">
            </div>
        </div>
    </div>
</div>

<div class="container">
    <div class="row">
        <div class="col-md-8">
            <button class="button"> LEARN MORE</button>
            <button class="button"><i class="fa fa-cloud-download" aria-hidden="true"></i> DOWNLOAD APP</button>
        </div>
    </div>
</div>

最佳答案

最简单的方法可能是让手机在其所在的容器外流血。您可以通过将其设置为 position: absolute; 来做到这一点。

#body {
    background: url(assets/bg_home.jpg) no-repeat center center fixed;
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: 100% 70%;
    background-position: top center;
    display: block;
    position: relative;
}

#body::before {
    content: "";
    background-image: linear-gradient(#1659e0, #489AEA);
    opacity: 0.5;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    position: absolute;
}

.image img {
  position:absolute;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<div id="body">
    <nav>
      navigation
    </nav>

    <div class="container">
        <div class="row">
            <div class="col-md-8 content">
                <h1>Meet BestApp</h1>
                <h1>The new world for chat</h1>
                <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quis deleniti cumque, odit atque molestiae totam facere aliquam sed cum perspiciatis quam, at sequi, corporis distinctio. Fugit nam, nesciunt quaerat pariatur.</p>
            </div>
            <div class="col-md-4 image">
                <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/1/18/IPhone_7_Jet_Black.svg/150px-IPhone_7_Jet_Black.svg.png" alt="phone ">
            </div>
        </div>
    </div>
</div>

<div class="container">
    <div class="row">
        <div class="col-md-8">
            <button class="button"> LEARN MORE</button>
            <button class="button"><i class="fa fa-cloud-download" aria-hidden="true"></i> DOWNLOAD APP</button>
        </div>
    </div>
</div>

关于html - 防止图像上的线性渐变溢出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42798990/

相关文章:

html - 创建 3 列垂直布局?

Javascript 可拖动图像脚本

html - 为什么我的 HTML 文档只使用了一些我要求它使用的 CSS 表?

html - 子项不渲染父项的 %height?

javascript - 函数未定义 C#

javascript - 将 mask Canvas 与 KineticJS 结合使用

php - Wordpress 正在生成 400px x 300px 的缩略图,我如何将其更改为 210px x 210px

javascript - 从 chrome 开发工具获取 CSS 作为 JavaScript 对象值

javascript - 如何让 CSS 影响解释 CSS 后生成的 DOM 元素?

javascript - 单击按钮时更改表单(多步表单)- 没有 Bootstrap