【问题标题】:Is there any way to exclude a single element from the style? (Bootstrap)有没有办法从样式中排除单个元素? (引导程序)
【发布时间】:2018-02-27 15:07:20
【问题描述】:

所以,我有一个img 徽标,覆盖在div 样式与background-image: url("...") 上,两个元素都在2 div 内,分别具有.to-color.to-overlay 类,以获得黑色透明覆盖。

有没有办法从这两个类给出的样式中排除徽标?

这是一个 JSFiddle 示例:Link

示例中的 HTML 和 CSS:

- HTML -

<div class="to-color">
<div class="to-overlay">

 <div class="respo">
  <div class="row">
   <div class="col-xs-4 col-xs-offset-4 text-center">
    <img src="http://ansonalex.com/wp-content/uploads/2011/06/google-logo-768x260.png" alt="..." class="img-responsive">
   </div>
  </div>
 </div>

</div>
</div>    


- CSS -

.to-color {
 background-color: #000;
}

.to-overlay {
 opacity : 0.5;
}

.respo {
 background-image: url("https://source.unsplash.com/category/objects/1600x900");
 background-position: center center;
 background-size: cover;
 padding-top: 10%;
 padding-bottom: 20%;
}

【问题讨论】:

  • 你必须给 logo 一个 css 类,然后你必须从那里明确地重置 bg 颜色和不透明度。 css 继承是一种痛苦......
  • 您可以更改标记吗?

标签: html css twitter-bootstrap


【解决方案1】:

您做错了使.to-overlay 及其所有子代半透明。

不要让.to-overlay 本身半透明,而是使用一个伪元素,该元素将出现在徽标之前并使其半透明。

.to-color {
  background-color: #000;
  position: relative;
}

.to-overlay:before {
  content: '';
  display: block;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
}

示例如下:https://jsfiddle.net/qet75juc/2/

【讨论】:

  • 哇,非常感谢!我是个新手,所以 CSS 中还有一些我不知道的东西,这绝对是将来肯定有用的东西:D
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-02-17
  • 2019-12-19
  • 1970-01-01
  • 1970-01-01
  • 2018-06-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多