Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does :: and ~ do in css?

Tags:

I was looking at a code made by a guy in twitter and it is like this :

div::after { -webkit-transform: rotate(2deg); }  div ~ div { -webkit-transform: rotate(0deg); } 

what is it ?

like image 996
monk Avatar asked Apr 22 '12 11:04

monk


People also ask

What is :: after and :: before 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. Version: CSS2.

What does the & symbol do in CSS?

A nested & selects the parent element in both SASS and LESS. It's not just for pseudo elements, it can be used with any kind of selector.

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.

What means & in sass?

The & is a special selector invented by SCSS which is used in nested selectors to refer to the outer selector . It simply means that it will be replaced with the outer selector when compiling to CSS. There are some most commonly used cases: there is a space after the ampersand.


2 Answers

The double colon replaced the single-colon selectors for pseudo-elements in CSS3 to make an explicit distinction between pseudo-classes and pseudo-elements. For backward compatibility, the single-colon syntax is acceptable for pre-CSS3 selectors. So, :after is a pseudo-class and ::after is a pseudo-element.


The general sibling selector is available in CSS3, and the combinator used in this selector is a tilde character (~).

The selector matches elements that are siblings of a given element. This example will match a p element if it’s a sibling of an h2 element:

http://reference.sitepoint.com/css/generalsiblingselector

http://www.evotech.net/blog/2007/05/after-v-after-what-is-double-colon-notation/

like image 139
Royi Namir Avatar answered Oct 06 '22 21:10

Royi Namir


The tilde character (~) is the siblings selector

h2 ~ p { color:red; } 

for example would make the paragraphs red in the below code

<h2>Heading</h2> <p>The selector above matches this paragraph.</p> <p>The selector above matches this paragraph.</p> 

the :: is used for ::before and ::after pseudo-elements which together with the content: allow you to put, for example, an icon before every link

a::before { content:url(link.png); } 
like image 29
Love Dager Avatar answered Oct 06 '22 19:10

Love Dager