How to bring html code into normal form. How to catch a lion in the desert


Do you love your CSS code as much as I do? If so, then, of course, strive to ensure that he not only behaves and feels good, but also looks nice.
I hope that the tools described below will help your code get closer to ideal.

1.Styleneat

Probably the simplest service presented in the review.
The tool doesn't have many options:
  • Sort properties alphabetically
  • Sorting selectors alphabetically (if “Safe Organize” is checked, this option is not available)
  • Ability to choose formatting style: multi-line or single line
  • Can pull CSS files connected using import into the main file and process them mercilessly
  • You can submit code for processing using: a text field, uploading a file, or providing a link to CSS
  • The result can be obtained as CSS code or upload a file

2.FormatCSS



Despite its menacing appearance, the instrument copes well with its functions, of which it has plenty.
You can configure a lot:
  • placement of spaces/tabs/new lines,
  • sorting properties and selector names,
  • converting property names and selectors to lower case, etc.
What I particularly liked about this service: the ability to format subrules with a “ladder” (I think this is very in a convenient way organization of styles).

3. CleanCSS



Enough powerful tool, which provides us with many possibilities:
  • You can feed CSS by copy-pasting in the “CSS-Code” field or as a link to the style file
  • You can get the result as text or as a file.
  • The user can choose from 4 types of source formatting: the code can be optimized for smallest size or, conversely, for better readability. It is possible to set a formatting template in the “Custom template” field
  • Able to combine rules and reduce properties to a short form
  • If necessary, remove comments and invalid definitions
  • Like the services described above, it will happily sort whatever your heart desires alphabetically and convert it to lower/upper case
By the way, basically of this service engine “ ” is detected- open source CSS parser/optimizer. So, everyone can freely depict their own beauty on its base, with blackjack and switches.
UPD> In the comments they suggested a link to the twin of this service: CodeBeautifier. The set of functions is almost identical to CleanCSS (the service also runs on CSSTidy).

4. ProCSSor



In my experienced opinion, it is the most convenient of all presented in this review.
The service greets the user with a pleasant interface and very clear pop-up tips that allow you to quickly understand the settings.
Like any self-respecting beautifier, ProCSSor will accept the code from us in the input field, in the form of a file or link. It will send the result to the browser and display a link to download the file.
The tool has enough settings to please almost any user; it doesn’t make much sense to list them - it’s better to try it right away.
A nice feature of the service is ability to save your settings, so that next time you can skip the settings step and go straight to the refining process.
Another attraction - ProCSSor provides an API, the documentation can be found here:

Wide development various platforms and devices forces developers to make for them special versions sites, which is quite labor-intensive and problematic. However, times and needs change, and creating a website for different devices is inevitable and necessary link its development. With this in mind, CSS introduced the concept of a media type, where a style is applied only to a specific device. In table 4.1 lists some media types.

CSS uses the @import and @media commands to specify media types, which can be used to style elements depending on whether the document is being output to the screen or to a printer.

The @media and @import keywords refer to et-rules. This name comes from the name of the @ symbol - “et”, with which these keywords begin. In RuNet, the established term “dog” is used to denote the @ symbol. It’s just that I don’t dare use the expression “dog rule”.

When importing a style using the @import command, the media type is specified after the file address. In this case, it is possible to specify several types at once, mentioning them separated by commas, as shown in example 4.1.

Example 4.1. Import style file

HTML5 CSS 2.1 IE Cr Op Sa Fx

Importing a style

IN in this example two files are imported - main.css is intended for changing the appearance of the document when viewing it on a monitor screen, and smart.css - when printing the page and displaying it on a smartphone.

Browser Internet Explorer up to the seventh version inclusive does not support media types when importing a style file.

The @media command allows you to specify the media type for global or linked styles and generally has the following syntax.

@media media type 1 (Style description for media type 1) @media media type 2 (Style description for media type 2)

After keyword@media is one or more media types listed in the table. 4.1, if there is more than one, then they are separated by a comma. This is followed by mandatory braces, inside of which there is a usual description of style rules. Example 4.2 shows how to set a different style for printing and display on the monitor.

Example 4.2. Styles for different types carriers

HTML5 CSS 2.1 IE Cr Op Sa Fx

Media types

How to catch a lion in the desert

Random number method

Let's divide the desert into a number of elementary rectangles, the size of which coincides with the size of the lion's cage. Then we sort through the resulting rectangles, each time choosing a given area randomly. If there is a lion in this area, we will catch it by covering it with a cage.

In this example, two styles are introduced - one to change the appearance of elements when they are normally displayed in the browser, and the second when the page is printed. At the same time, the appearance of a document for different media can vary greatly, for example, as shown in Fig. 4.1 and fig. 4.2.

You can view a document that has CSS set to print type by printing a specific page or by using the browser preview ( File > Preview ). Or use a trick and temporarily replace print with screen to display the result in the browser. This is how the rice was obtained. 4.2.

The @media command is used mainly to generate one style file, which is divided into blocks by device type. Sometimes it makes sense to create several different CSS files - one for printing, one for display in the browser - and connect them to the document as needed. In such a case, you should use the tag with the media attribute, the value of which is all the same types listed in table. 4.1.

Example 4.3. Connecting styles for different media

HTML5 CSS 2.1 IE Cr Op Sa Fx

Various media

This example uses two linked style sheets, one for display in the browser, and one for printing the document and viewing it on a smartphone. Although two are loaded onto the page at the same time different styles, they apply only to certain devices.

Similarly, you can use global styles by adding the media attribute to the tag

Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diem nonummy nibh euismod tincidunt ut lacreet dolore magna aliguam erat volutpat.

In this example, the width for handheld devices is limited to 320 pixels.

Questions to check

1. Pasha decided to make a printable version for his website. Which line should he use in the code?

  1. @import "palm.css" print;
  2. @import url("printer.css") printer;
  3. @media "palm.css" print;