-
-
Notifications
You must be signed in to change notification settings - Fork 35.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: fixed grammar/formatting of entire document (#35392)
- Loading branch information
1 parent
f4528ad
commit 52105e3
Showing
1 changed file
with
20 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,61 @@ | ||
--- | ||
title: Before Selector | ||
--- | ||
## Before Selector | ||
|
||
The CSS **::before** selector can be used to insert anything before the content of an element or elements. In CSS, it is called a psuedoelement. It allows the designer perform any css design before the content in an element. It is used by attaching **::before** to the element it is to be used on. | ||
Also, it doesn't work without the **content** property. | ||
# Before Selector | ||
The CSS `::before` selector can be used to insert some content, usually cosmetic, *before* the content of an element or elements. It is used by attaching `::before` to the element it is to be used on. It is an inline element by default. | ||
|
||
## Examples | ||
Let's look at some examples: | ||
|
||
<!--Css --> | ||
```css | ||
|
||
p::before { | ||
content: ""; | ||
border: solid 5px #ccc; | ||
} | ||
|
||
span.comment::before{ | ||
span.comment::before { | ||
content: "Comment: "; | ||
color: blue; | ||
} | ||
|
||
``` | ||
<!--Html--> | ||
|
||
```html | ||
|
||
<p> To infinity and beyond</p> | ||
<p> I am buz lightyear, I come in peace.</p> | ||
<p> I am Buzz Lightyear, I come in peace.</p> | ||
|
||
<span class="comment"> May the force be with you</span> | ||
<br/> | ||
<span> Do. Or do not. There is no try</span> | ||
<span> Do, or do not. There is no try.</span> | ||
|
||
``` | ||
|
||
In the example above we are prepending a grey border before every paragraph element on a page and we are also prepending the words comment in blue before every span element with the class comment. | ||
In the example above we are prepending a grey border before every paragraph element on a page and we are also prepending the word "Comment: " in blue before every `span` element with the class name `comment`. | ||
|
||
> You can check out this demo here https://jsfiddle.net/398by400/ | ||
> You can check out this demo here https://jsfiddle.net/kxrdswtm/ | ||
#### Definition and usage | ||
`::before` is one of the CSS pseudo-elements selectors, which are used to style specified parts of an element. In this case, we can insert content before some HTML element from CSS. Although we will see the content in the page, it is not part of the DOM, what means that we can't manipulate it from Javascript. One trick to solve this handicap: passing the content with a data attribute and use jQuery to manipulate it. Here is an example of use: | ||
## Definition and Usage | ||
`::before` is one of the CSS pseudo-elements selectors, which are used to style specified parts of an element. In this case, we can insert content before some HTML element from CSS. Although we will see the content in the page, it is not part of the Document Object Model (DOM), which means that we cannot manipulate it from JavaScript. | ||
|
||
```css | ||
p::before { | ||
content: "Hello "; | ||
content: "Hello, "; | ||
} | ||
``` | ||
|
||
```html | ||
<p>world!!</p> | ||
<p>World!</p> | ||
``` | ||
|
||
This will show `Hello world!!` in the page. | ||
|
||
Not only strings, also images, counters or even nothing ("", useful for clearfix) can be inserted into the `content` attribute, but <strong>not HTML</strong>. There are a good number of cool things that can be made using ```::before``` and ```after``` in a creative way. You can take a look in the next link if you are curious: <a href='https://www.w3schools.com/css/css_pseudo_elements.asp' target='_blank' rel='nofollow'>A Whole Bunch of Amazing Stuff Pseudo Elements Can Do</a> | ||
|
||
#### Single-colon vs. Double-colon | ||
There's a bit of discussion about the right way of using pseudo-elements: old style single-colon (```:before```), used in CSS specifications 1 and 2, versus CSS3 recommendation, double-colon (```::before```), mainly to <em>"establish a discrimination between pseudo-classes and pseudo-elements"</em>. But for compatibility reasons, single-colon is still accepted. Talking about compatibility, IE8 supports the single-colon notation only. | ||
This will display `Hello, World!` on the page. | ||
|
||
#### More Information: | ||
String, images, counters, or even an empty string ("", useful for `clearfix`) can be inserted into the `content` attribute. HTML cannot be inserted. | ||
|
||
<a href='https://www.w3schools.com/css/css_pseudo_elements.asp' target='_blank' rel='nofollow'>W3Schools CSS Pseudo-elements</a> | ||
[See A Whole Bunch of Amazing Stuff Pseudo Elements Can Do!](https://www.w3schools.com/css/css_pseudo_elements.asp) | ||
|
||
<a href='https://css-tricks.com/almanac/selectors/a/after-and-before/' rel='nofollow'>CSS-Tricks ::after/::before</a> | ||
## Single-colon vs. Double-colon | ||
There's a bit of discussion about the right way of using pseudo-elements: old style single-colon (`:before`), used in CSS specifications 1 and 2, versus CSS3 recommendation, double-colon (`::before`), mainly to "establish a discrimination between pseudo-classes and pseudo-elements". But for compatibility reasons, single-colon is still accepted. IE8 supports the single-colon notation only. | ||
|
||
<a href='https://stackoverflow.com/questions/5041494/selecting-and-manipulating-css-pseudo-elements-such-as-before-and-after-usin' rel='nofollow'>Selecting and manipulating CSS pseudo-elements such as ::before and ::after using jQuery</a> | ||
## Additional Resources | ||
- [W3Schools CSS Pseudo-elements](https://www.w3schools.com/css/css_pseudo_elements.asp) | ||
- [CSS-Tricks ::after/::before](https://css-tricks.com/almanac/selectors/a/after-and-before/) |