简体   繁体   中英

Pseudo-elements :after and :before not appearing consistently

I am creating two rectangles each with 2 colors. Rather than creating a container div and 2 seperate empty div boxes just to display color, I'm trying to use :after to overlay one box on top of another.

This is a learning process for me. So after I get it to work on the containers, I will attempt to add the two colors to :before and :after on the text objects themselves, and compare the process/results. Unfortunately I am so far unable to display the :after pseudo-elements in the container div.

Here's my prototype:在此处输入图片说明


Here's what I've got so far:在此处输入图片说明

#aprende_heading_container {
  width: 100%;
  float: left;
  margin-left: 0;
  margin-right: 0;
  background-color: #1b414a;
  height: 102px;
}

#aprende_heading_container:after {
  width: 100%;
  float: left;
  margin-left: 0;
  margin-right: 0;
  height: 100%;
  background-color: rgba(200, 0, 0, 0.29);
}

#aprende_subheading_container {
  width: 100%;
  float: left;
  margin-left: 0;
  margin-right: 0;
  background-color: #358394;
  height: 100px;
}

#aprende_subheading_container:after {
  width: 100%;
  float: left;
  margin-left: 0;
  margin-right: 0;
  height: 100%;
  background-color: #000;
}

Any Ideas?

Your before and after should have content and display attributes:

#aprende_subheading_container:after {
  content:'';
  display:block;
  width: 100%;
  float: left;
  margin-left: 0;
  margin-right: 0;
  height: 100%;
  background-color: #000;
}

I'm assuming you're trying to give your elements that two-tone effect with these pseudo elements? You should consider using gradients for that. You could use a gradient generator to create them.

Have you tried to used content: ''; in your pseudo-elements? :after and :before

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM