我想为固定容器内的列设置一个完整的边缘背景色。我有一个here的例子。我怎样才能做到这一点呢?
我试过了,但都不管用。
首先:
@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);
}发布于 2019-10-07 17:22:52
下面是一个带有伪代码的示例:
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>
https://stackoverflow.com/questions/58266179
复制相似问题