Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pseudo after align right

I'm trying to use the CSS3 pseudo :after on li elements. The issue is that the content of :after is immediately following the li content - as if :after uses text-align:left; But since my li elements use display:block; shouldn't using text-align:right; on :after move the :after content all the way to the right? It doesn't anyway.

.container ul li    {     display: block;     border-bottom: 1px solid rgb(60,60,60);     border-top: 1px solid rgb(255,255,255);     padding: 5px 5px 5px 30px;     font-size: 12px; }  .container ul li:after {     content: ">";     text-align: right; } 

This is a screen shot of the issue:

:after not doing what I want

I want the > to be all the way at the right, and since the content of the li changes, I can't set a width on the :after content.

How would I get the :after content to align to the right, if not with text-align?

like image 231
CJT3 Avatar asked Jul 04 '12 11:07

CJT3


People also ask

What is after pseudo element?

In CSS, ::after creates a pseudo-element that is the last child of the selected element. It is often used to add cosmetic content to an element with the content property. It is inline by default.

When would you use the :: before or :: after pseudo element in your CSS?

Special welcome offer: get $100 of free credit. 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.


2 Answers

Try float :

.container ul li:after {     content: ">";     text-align: right;     float:right; } 

Demo http://jsfiddle.net/surN2/

like image 157
Sowmya Avatar answered Sep 17 '22 14:09

Sowmya


Hey now you can used position properties as like this:

.container ul li    {     display: block;     border-bottom: 1px solid rgb(60,60,60);     border-top: 1px solid rgb(255,255,255);     padding: 5px 5px 5px 30px;     font-size: 12px;     position:relative; }  .container ul li:after {     content: ">";     position:absolute;     left:20px;     top:5px; } 

and change to css properties according your design.

Live demo: http://tinkerbin.com/yXzOyDNg

If you want to right align than change left into right

.container ul li    {     display: block;     border-bottom: 1px solid rgb(60,60,60);     border-top: 1px solid rgb(255,255,255);     padding: 5px 5px 5px 30px;     font-size: 12px; }   .container ul li:after {     content: ">";     position:absolute;     right:20px;     top:5px; } 

Live demo: http://tinkerbin.com/rSWKxLwX

like image 24
Rohit Azad Malik Avatar answered Sep 18 '22 14:09

Rohit Azad Malik