Bootstrap 4 Beta - 将背景图像应用于Jumbotron会破坏Form元素

时间:2017-08-17 17:42:22

标签: forms image bootstrap-4

当我遇到一个无法找到解决方法的问题时,我正在创建一个自举网站作为挑战。

在jumbotron中我有一个带有文本字段和提交按钮的表单。

文本字段还有一个插件(input-group-addon)

没有任何图像插件完全放置在应有的位置但是当我添加图像时,插件会从文本字段移开一个像素。



            .bg {  
              background-image: url("http://www.zastavki.com/pictures/originals/2013/Photoshop_Image_of_the_horse_053857_.jpg");
              text-align: center;
              color: white;
            }
            .jumbotron form {
                text-align: none;
            }
            .jumbotron hr {
                background-color: white;
            }

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js"></script>
<body style="position: relative;" data-spy="scroll" data-target="#navBar">
        <nav id="navBar" class="navbar navbar-toggleable-md navbar-light bg-faded">
            <button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
                <span class="navbar-toggler-icon"></span>
            </button>
            <a class="navbar-brand" href="#">My App</a>  
            <div class="collapse navbar-collapse" id="navbarSupportedContent">
                <ul class="navbar-nav mr-auto">
                    <li class="nav-item active">
                        <a class="nav-link" href="#home">Home <span class="sr-only">(current)</span></a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="#">Features</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="#">Download</a>
                    </li>
                </ul>
                <form class="form-inline my-2 my-lg-0">
                    <input class="form-control mr-sm-2" type="text" placeholder="Search">
                    <button class="btn btn-success my-2 my-sm-0" type="submit">Search</button>
                </form>
            </div>
        </nav>
        <div class="jumbotron bg">
            <h1 class="display-3">My Amazing App!</h1>
            <p class="lead">The MAIN reason for YOU to download THIS app on your handheld Android or iOS device.</p>
            <hr class="my-4">
            <p class="lead">Want to learn more ? Join our Mailing List and get a free bonus.</p>
            <form class="form-inline justify-content-center">
                <label class="sr-only" for="email">Email</label>
                <div class="input-group mb-2 mr-sm-2 mb-sm-0">
                  <div class="input-group-addon">@</div>
                  <input style="width: 350px;" type="email" class="form-control" id="email" placeholder="Your Email">
                </div>
                <button type="submit" class="btn btn-primary">Sign Up</button>
            </form>
        </div>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

Bootstrap 4仍在测试版中,为.form-control类应用了一个高度透明的边框。您的示例突出显示了在对具有深色背景的容器使用输入元素时,这可能会产生意外结果。 Bootstrap 4的默认样式是:

.form-control {
    border-color: rgba(0, 0, 0, 0.15);
}

这是一个近乎最大透明度的黑色边框。正如您所发现的那样,在黑暗的背景下渲染将无法达到预期的效果。

我已经附加了一个自定义类来覆盖.stat-control类的Bootstrap 4的默认边框颜色。应用于您的示例,仅当类.bg也应用于jumbotron时,它才有效。

.bg .form-control.solid-gray-border {
    border-color: rgb(222,222,222);
}

&#13;
&#13;
.bg {  
              background-image: url("http://www.zastavki.com/pictures/originals/2013/Photoshop_Image_of_the_horse_053857_.jpg");
              text-align: center;
              color: white;
            }
            .jumbotron form {
                text-align: none;
            }
            .jumbotron hr {
                background-color: white;
            }
            .bg .form-control.solid-gray-border {
                border-color: rgb(222,222,222);
            }
&#13;
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js"></script>
<body style="position: relative;" data-spy="scroll" data-target="#navBar">
        <nav id="navBar" class="navbar navbar-toggleable-md navbar-light bg-faded">
            <button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
                <span class="navbar-toggler-icon"></span>
            </button>
            <a class="navbar-brand" href="#">My App</a>  
            <div class="collapse navbar-collapse" id="navbarSupportedContent">
                <ul class="navbar-nav mr-auto">
                    <li class="nav-item active">
                        <a class="nav-link" href="#home">Home <span class="sr-only">(current)</span></a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="#">Features</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="#">Download</a>
                    </li>
                </ul>
                <form class="form-inline my-2 my-lg-0">
                    <input class="form-control mr-sm-2" type="text" placeholder="Search">
                    <button class="btn btn-success my-2 my-sm-0" type="submit">Search</button>
                </form>
            </div>
        </nav>
        <div class="jumbotron bg">
            <h1 class="display-3">My Amazing App!</h1>
            <p class="lead">The MAIN reason for YOU to download THIS app on your handheld Android or iOS device.</p>
            <hr class="my-4">
            <p class="lead">Want to learn more ? Join our Mailing List and get a free bonus.</p>
            <form class="form-inline justify-content-center">
                <label class="sr-only" for="email">Email</label>
                <div class="input-group mb-2 mr-sm-2 mb-sm-0">
                  <div class="input-group-addon">@</div>
                  <input style="width: 350px;" type="email" class="form-control solid-gray-border" id="email" placeholder="Your Email">
                </div>
                <button type="submit" class="btn btn-primary">Sign Up</button>
            </form>
        </div>
&#13;
&#13;
&#13;