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; }
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.
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.
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.
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.
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.
You should use :before
and :after
selectors with content
property:
.chart ul:after{ content: ""; border:1px solid #f30; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With