html - 如何修复 Bootstrap 不透明度?

标签 html css twitter-bootstrap bootstrap-4 opacity

检查图片的侧面。我试图使背景具有不透明度,而不影响我放在上面的内容。 (我也不希望文本具有不透明度)但自始至终的问题是我的图片的侧面不具有不透明度。

.container {
  position: relative;
  background-image: url("https://www.elephantsdeli.com/wp-content/uploads/fly-images/1673/elephants-delicatessen-sack-lunch-order-form-hero-image.jpg-1920x1080.jpg");
  height: 50vh; 
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
}

.background {
  height: 100vh;
  background: rgba(255,255,255,.4)
}

.text-center {
  padding: 50px 0;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" integrity="sha384-9gVQ4dYFwwWSjIDZnLEWnxCjeSWFphJiwGPXr1jddIhOegiu1FwO5qRGvFXOdJZ4" crossorigin="anonymous">

<div class="container">
  <div class="background">
    <h1 style="font-size: 350%;" class="text-center"><b>It's Lunch-Time!</b></h1>
  </div>
</div>

最佳答案

您应该使用 d-flexalign-items-centerjustify-content-center 而不是自定义 文本中心 样式。此外,不要将行的高度设置为固定数字:让它占据容器的整个高度。

.container {
  position: relative;
  background-image: url("https://www.elephantsdeli.com/wp-content/uploads/fly-images/1673/elephants-delicatessen-sack-lunch-order-form-hero-image.jpg-1920x1080.jpg");
  height: 50vh;
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
}

.background {
  background: rgba(255, 255, 255, .4)
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" integrity="sha384-9gVQ4dYFwwWSjIDZnLEWnxCjeSWFphJiwGPXr1jddIhOegiu1FwO5qRGvFXOdJZ4" crossorigin="anonymous">

<div class="container">
  <div class="row background h-100">
    <div class="col d-flex align-items-center justify-content-center">
      <h1 style="font-size: 350%;"><b>It's Lunch-Time!</b></h1>
    </div>
  </div>
</div>

关于html - 如何修复 Bootstrap 不透明度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50453262/

相关文章:

javascript - 使用 CSS block 显示/隐藏文本

python - 无法提取具有 beautifulsoup 中指定的类的标签

php - 使用 PHP 缩小 CSS 文件

jquery - Bootstrap Carousel 不适用于不同的 JQuery 和 Bootstrap 文件顺序

javascript - 使用不同的变量名

css - 带有 css 的中心 jquery slider

html - 如何删除 CSS 中的悬停样式

jquery - 如何获取动态(jquery 创建的)元素内 <img> 的 src?

css - IE8 上的 Bootstrap 3 错误行为

html - 为具有未知数量的行和列的表制作固定表头