Полный фоновый цвет фиксированного столбца - PullRequest
0 голосов
/ 07 октября 2019

Я хочу сделать цвет фона по краю для столбца внутри фиксированного контейнера. У меня есть пример здесь . Как мне этого добиться?

Я пробовал это, но ни один из них не работал ...

Первый:

@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)
      }
    }
  }
}

Второй:

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

Третье:

.breakout-background {
  margin: 0 -9999rem;
  padding: 0.25rem 9999rem;
  background: rgba(0, 0, 0, 0.5);
}

1 Ответ

3 голосов
/ 07 октября 2019

вот пример с псевдо:

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;
}
<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>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...