首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >固定定位列的完整背景颜色

固定定位列的完整背景颜色
EN

Stack Overflow用户
提问于 2019-10-07 16:48:39
回答 1查看 119关注 0票数 0

我想为固定容器内的列设置一个完整的边缘背景色。我有一个here的例子。我怎样才能做到这一点呢?

我试过了,但都不管用。

首先:

代码语言:javascript
复制
@import '~bootstrap/scss/variables';
@import '~bootstrap/scss/bootstrap-grid';
@import '~bootstrap/scss/mixins';

// Apply this class to elements which should have breakout backgrounds
.breakout-background {
  position: relative; // establish breakout positioning ancestor
  z-index: 0; // establish stacking context for breakout

  // Breakout background pseudo element
  &:before {
    content:'';
    position: absolute;
    height: 100%;
    top:0;
    width: 100vw; // Takes up 100% of the viewport width
    z-index: -1; // pseudo element is behind its parent
    background-color: blue;

    // Different left position for each breakpoint
    @each $breakpoint, $container-max-width in $container-max-widths {
      @include media-breakpoint-up($breakpoint, $grid-breakpoints) {

        // Position -50% of viewport width, then readjust right again half the grid container width
        left: calc(-100vw / 2 + #{$container-max-width} / 2)
      }
    }
  }
}

第二:

代码语言:javascript
复制
.breakout-background {
 &:before {
  content: "";
  background-color: #322529;
  z-index: -1;
  right: 0px;
  width: 1000px;
  height: 60%;
  top: 35%;
  position: absolute;
 }
}

第三:

代码语言:javascript
复制
.breakout-background {
  margin: 0 -9999rem;
  padding: 0.25rem 9999rem;
  background: rgba(0, 0, 0, 0.5);
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-10-07 17:22:52

下面是一个带有伪代码的示例:

代码语言:javascript
复制
body {
  margin: 0;
  height: 100vh;
}
div {
  border: solid 1px;
}
.row {
  padding: 0.5em;
}
.row div {
  margin: 0.5em;
}
.mw-90 {
  min-width: 90%;
}
.col:nth-child(1) {
  background: lightgreen;
}
.col:nth-child(2) {
  background: orange;
}
:nth-child(3) {
  background: tomato;
}
:nth-child(4) {
  background: lightblue;
}
.col:nth-child(5) {
  background: purple;
}
.relative {
  position: relative;
  z-index: 1;
}

.relative:before {
  content: "";
  position: absolute;
  width: 100vw;  
  top: -1px;
  bottom: -2px;
  left:50%;
  transform:translatex(-50%);
  background: inherit;
  z-index:-1;
  border-top:1px solid;
  border-bottom:1px solid;
}
代码语言:javascript
复制
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container h-100">
  <div class="row h-100">
    <div class="col">Column</div>
    <div class="col">Column</div>
    <div class="col mw-90 relative">Column</div>
    <div class="col-4">Column</div>
    <div class="col">Column</div>
  </div>
</div>

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58266179

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档