html - 为什么透明 div 上的输入也呈现为透明?

标签 html css

我有一个透明的白色 div,我想在其中放置一个输入。无论出于何种原因,输入和按钮也呈现为透明。

HTML:

<div class="covered">
  <div class="container covered-container">
    <div class="col-md-12 infotron-home"><div class="input-group">
            <input type="text" class="form-control" placeholder="Search for...">
            <span class="input-group-btn">
    <button class="btn btn-default" type="button">Go!</button>
  </span>
        </div> </div>
  </div>
</div>

CSS:

div.covered{
  background: url(http://i2.cdn.cnn.com/cnnnext/dam/assets/140801145902-irpt-birds-heron-scott-baumann-horizontal-large-gallery.jpg) no-repeat center center;
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
  height: 80%;
  padding-top:50px
}
.covered-container{
  background-color:white;
  opacity: .7;
  margin-bottom:20px;
}


.infotron-home{
  margin-top:50px;
text-align: center;
font-family: "Roboto Slab";
color:#0c5449;
}

.infotron-home li, .infotron-home p{
  list-style-type: none;
  font-family:Helvetica, Arial, sans-serif;
  font-size:18px;
}


.search-home{
  width:80%;
  opacity: 1;
}

input, select, textarea{
  color: #ffffff !important;
  opacity: 1;
}

JsFiddle:https://jsfiddle.net/49fp9ngk/1/

如何使输入像默认值一样不透明和白色?

最佳答案

opacity 用于 parent element 时,它甚至影响它的 child elements,所以我建议你使用 background 作为 rgba 并从父 div 和子 div 中删除 opacity,如下所示。

div.covered{
  background: url(http://i2.cdn.cnn.com/cnnnext/dam/assets/140801145902-irpt-birds-heron-scott-baumann-horizontal-large-gallery.jpg) no-repeat center center;
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
  height: 80%;
  padding-top:50px;
}
.covered-container{
  background-color:rgba(255,255,255,0.7); /* Add this */
  margin-bottom:20px;
}


.infotron-home{
margin-top:50px;
text-align: center;
font-family: "Roboto Slab";
color:#0c5449;
}

.infotron-home li, .infotron-home p{
  list-style-type: none;
  font-family:Helvetica, Arial, sans-serif;
  font-size:18px;
}

.search-home{
  width:80%;
  opacity: 1;
}

input, select, textarea{
  background:rgba(255,255,255,1); /* Add this */
}
<div class="covered">
    <div class="container covered-container">
        <div class="col-md-12 infotron-home"><div class="input-group">
                <input type="text" class="form-control" placeholder="Search for...">
                <span class="input-group-btn">
        <button class="btn btn-default" type="button">Go!</button>
      </span>
     </div><!-- /input-group --> </div>
  </div>
</div>

关于html - 为什么透明 div 上的输入也呈现为透明?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41455966/

相关文章:

css - CSS 的 Visual Studio 2015 语法突出显示在 vbhtml Razor 页面中不起作用

css - 从生成的 html 中删除一个类项

html - 如何将 Google 字体 .ttf 文件转换为其他文件类型以支持所有浏览器

html - 简单的 Z-Index 不起作用

javascript - 准备学习html5

html - 悬停子列表时更改列表选项的颜色

html - 单行动态列数的CSS解决方案

html - 阻止用户在我们网站上观看 YouTube 视频时被带离我们的网站

javascript - 如何使链接出现在文本框中,并让按钮将其保存在数据库中

jquery - History.pushstate 不能返回多次