Support for HTML/CSS

ReSharper v6 was very web development friendly. Besides supporting JavaScript, it also started supporting HTML and CSS.

Writing HTML/CSS code

ReSharper comes with a couple of features that help you in writing HTML and CSS code.

The first feature is IntelliSense for HTML tags, attributes, CSS attributes, and values. In a very smart way, it prompts you about what you wish to probably write. These options are shown in the following screenshot:

Writing HTML/CSS code

ReSharper can not only prompt defined CSS attributes, but also your custom CSS classes, as shown in the following screenshot:

Writing HTML/CSS code

ReSharper analyzes your CSS files (and CSS inline code) and allows you to use created classes in your code. What is really cool is that ReSharper prompts these classes not only in HTML code, but also in ASP.NET (MVC) as well as JavaScript.

Additionally, ReSharper provides you with context actions that also help you in writing code. They allow you to remove HTML attributes, add tags, and quickly create the table structure. The following screenshot shows you how you can easily create new table rows:

Writing HTML/CSS code

In the same way, you can create new columns.

Tip

If you would like to duplicate the whole line (in any type of file), just hover the cursor over that line and press Ctrl + D!

In the case of CSS, ReSharper comes with a set of context actions that allow you to convert different methods of presenting colors, such as named colors, hex, and RGB.

ReSharper also displays visually used colors any time you specify a color, as shown in the following screenshot:

Writing HTML/CSS code

You can also adjust your color by using a palette color. Just move your cursor to the color definition, press Alt + Enter, and select Pick color from palette.

CSS hierarchy

CSS hierarchy is a very useful tool that shows you how CSS classes inherit from other classes. A sample view of the CSS hierarchy window is shown in the following screenshot:

CSS hierarchy

The CSS hierarchy makes it easier to understand which style will be applied to the HTML elements.

Navigation

Similar to other languages, you can display the file structure for HTML and CSS code as you can see in the following screenshot:

Navigation

This helps you quickly go to the proper place in your file.

You can also search CSS classes with the Go to everything option (Ctrl + T) and use the Go to declaration or Find usages features to quickly check how your CSS class is declared and where it is used.

Go to file member (Alt + ) works for both CSS and HTML code.

Browser compatibility support

There are a couple of CSS and HTML versions which may be supported by browsers a bit differently sometimes. ReSharper can check if your code is compatible with the CSS and HTML version that you are using as well as with specific versions of different browsers.

You can configure these settings in the ReSharper options by navigating to Code Editing | CSS | Inspections, as shown in the following screenshot:

Browser compatibility support

Templates

You can also use templates in HTML and CSS code. From these templates, you can find the following tags:

  • t: This generates open and close tags
  • tc: This generates self-closing tags
  • <script: This generates the script tag and automatically displays the list of available script types

Note

You can check the list of available templates in the Templates Explorer window. You can find out more about templates in Chapter 2, Write Smarter Code.

Remember that you can create your own templates as you need!

Tip

Surround With (Ctrl + E, U) is a very useful template that allows you to select some text and surround it with any HTML tag.

Code analysis

Code analysis is also available in HTML and CSS, where it can quickly find and fix some common errors, such as unknown tags and IDs, and unused, obsolete, or redundant code.

You can find the list of available code analysis in ReSharper options by navigating to Code Inspection | Inspection Severity.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.116.21.152