Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS :before and :after not working? [duplicate]

Tags:

css

I am trying to use :before and :after with list but it is not working. I am sure it's a simple mistake but I am not able to point it out.

Any help would be appreciated

Please check the fiddle

<div class="org-chart">   <ul class="chart chart-prhead">     <li>       <span><a href="#">Dabba</a></span>       <ul class="chart-mgr">         <li>           <!-- level 2 -->           <span><a href="#">Dabba</a></span>          </li>        </ul>     </li>   </ul> </div> 
.chart ul:after {   border: 1px solid #f30; } .chart li span:after {   border: 1px solid #eee; } .chart li span:before {   border: 1px solid #ccc; } .chart li a:after {   border: 1px solid #666; } .chart li a:before {   border: 1px solid #333; } 
like image 246
Tom Avatar asked Feb 03 '16 14:02

Tom


People also ask

Why use:: before and:: after in CSS?

The CSS ::before selector inserts content before a selected element. CSS :after inserts content after a specified element. These selectors are commonly used to add text before or after a paragraph or a link.

How to use before and after in CSS?

Definition and UsageThe ::before selector inserts something before the content of each selected element(s). Use the content property to specify the content to insert. Use the ::after selector to insert something after the content.

How to use before and after pseudo elements in CSS?

CSS ::before and ::after pseudo-elements allow you to insert “content” before and after any non-replaced element (e.g. they work on a <div> but not an <input> ). This effectively allows you to show something on a web page that might not be present in the HTML content.

How do you duplicate elements in CSS?

Short answer no, in css you can't create content or display it multiple times. Usually this repeated content is taken care of via server side technologies (PHP, JSP, ASPX) etc. If your site is static content (no server side processing) then your best bet is just copy and past.


2 Answers

If you want :before and :after to work, you need to give them content, otherwise they don't really 'exist'. The easiest thing to do is, in the css, set content: '' for both pseudoelements.

like image 194
GMchris Avatar answered Oct 04 '22 21:10

GMchris


You should use :before and :after selectors with content property:

.chart ul:after{   content: "";   border:1px solid #f30; } 
like image 26
Enver Dzhaparoff Avatar answered Oct 04 '22 21:10

Enver Dzhaparoff