Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: fixed grammar/formatting of entire document #35392

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
47 changes: 20 additions & 27 deletions guide/english/css/before-selector/index.md
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
[See A Whole Bunch of Amazing Stuff Pseudo Elements Can Do!](https://www.w3schools.com/css/css_pseudo_elements.asp)
[See A Whole Bunch of Amazing Stuff Pseudo Elements Can Do!](https://css-tricks.com/pseudo-element-roundup/)

I feel this is better and shows more variety

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find both of those links to be valid. My goal was not really to modify the content so much as clean everything up - if you'd like to submit a pull request to change that link please feel free!


<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/)