html -::after 伪元素出现在之前

标签 html css pseudo-element

我正在尝试在渐变的顶部和底部创建一个微妙的波浪。但是,::after 伪元素出现在主要内容之前而不是之后。目前它显示为::before,::after,主要内容,但我希望它显示为::before,主要内容,::after。

这是我的代码:

#gradient {
  background: #0068a9;/* For browsers that do not support gradients */
  background: -webkit-linear-gradient(rgba(0, 104, 169, 1), rgba(0, 104, 169, .9));/*Safari 5.1-6*/
  background: -o-linear-gradient(rgba(0, 104, 169, 1), rgba(0, 104, 169, .9));/*Opera 11.1-12*/
  background: -moz-linear-gradient(rgba(0, 104, 169, 1), rgba(0, 104, 169, .9));/*Fx 3.6-15*/
  background: linear-gradient(rgba(0, 104, 169, 1), rgba(0, 104, 169, .9));/*Standard*/
  width: 100%;
  height: 300px;
  min-height: 0px;
  display: block;
}

#gradient::before,
#gradient::after {
  display: block;
  content: "";
  width: 100%;
  height: 75px;
}

#gradient::before {
  background: #f2f2f2 url("http://www.qumidesignco.com/clients/preparedcapital/pc_topcurve.png") center top;
}

#gradient::after {
  background: #f2f2f2 url("http://www.qumidesignco.com/clients/preparedcapital/pc_bottomcurve.png") center top;
}
<div style="background:#f2f2f2; width: 100%; height: 300px; min-height: 0px; display:block;"></div>
<div id="gradient"></div>
<div style="background:#f2f2f2; width: 100%; height: 300px; min-height: 0px; display:block;"></div>

最佳答案

让你的gradient div relative , :before and :after absolute and top:0 :before 中的 :after

中的 bottom:0

#gradient {
  background: #0068a9;/* For browsers that do not support gradients */
  background: -webkit-linear-gradient(rgba(0, 104, 169, 1), rgba(0, 104, 169, .9));/*Safari 5.1-6*/
  background: -o-linear-gradient(rgba(0, 104, 169, 1), rgba(0, 104, 169, .9));/*Opera 11.1-12*/
  background: -moz-linear-gradient(rgba(0, 104, 169, 1), rgba(0, 104, 169, .9));/*Fx 3.6-15*/
  background: linear-gradient(rgba(0, 104, 169, 1), rgba(0, 104, 169, .9));/*Standard*/
  width: 100%;
  height: 300px;
  min-height: 0px;
  display: block;
  position: relative;
}

#gradient::before,
#gradient::after {
  display: block;
  content: "";
  width: 100%;
  height: 75px;
  position: absolute;
}

#gradient::before {
  background: #f2f2f2 url("http://www.qumidesignco.com/clients/preparedcapital/pc_topcurve.png") center top;
  top:0;
}

#gradient::after {
  background: #f2f2f2 url("http://www.qumidesignco.com/clients/preparedcapital/pc_bottomcurve.png") center top;
  bottom: 0;
}
<div style="background:#f2f2f2; width: 100%; height: 300px; min-height: 0px; display:block;"></div>
<div id="gradient"></div>
<div style="background:#f2f2f2; width: 100%; height: 300px; min-height: 0px; display:block;"></div>

关于html -::after 伪元素出现在之前,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46343113/

相关文章:

html -::select 伪元素在填充空间中被忽略,选择越界...?

javascript - 如何在 sIFR3 中获得软投影?

CSS - 为什么要添加 -webkit 等到过渡

css - ie10结合flexbox伪元素消失

php - CSS/JS 将 <td> 着色为条形图?

html - 将无响应图像水平居中

css - 为什么不是 :visited instead of a:visited for links?

javascript - 淡出并多次替换一个div

javascript - 当所有元素都悬停时,CSS 在悬停时更改单独的元素

html - 如何从包含在另一个 div 中的 div 中删除背景