Use Collapsible And Expandable Code Regions Feature In Visual Studio For Editing CSS/SCSS/LESS Files

The Best CSS editing feature

Collapsible/ Expandable Code Regions in Visual Studio Community 

Currently, the Visual Studio IDE is the world's best IDE available. Many people think that Visual Studio IDE is not free. Even though there are paid versions for enterprise developers, there is a free community edition for personnel and small teams. The community edition is more than enough to build a site like Facebook or even Amazon.com.  The IDE can be used in many programming languages to build a cross-platform desktop app, mobile app, or full-featured web application.

Today I am going to discuss a very handy feature available for editing CSS/SCSS or LESS files. When coding thousands of lines, it is very hard to track if we do not put comments to describe the code for later references. 

When we add lots of comments, the code will get a bit messy. In normal C# editing, it provides the developer with the region feature to collapse and expand it when necessary. 

Similarly, for CSS, there is a way to shrink a large block of code into a single line, using regions, 

In Visual Studio, we can add a collapsible region so that we can quickly collapse code sections to find and navigate to a different section of the file.

To add a region

In a CSS/LESS or SCSS file type region and then press(Esc if you see the context list, then) the tab button from the keyboard. It will add a code block for you like this:


    /*#region name */


    /*#endregion */


Then type a meaningful title over yellow highlighted "name".

Note: In addition to that just type the same title next to "#endregion so that it is easy to recognise if you expand a long code region and scroll to the bottom part of the region.

for example, if I want to place all my code related to the "Service" section, I will create a region as:


    /*#region Services */
    
    .section-divider {
        padding-top: 2em;
        padding-bottom: 2em;
    }

    /*#endregion  Services*/
You can easily collapse a region by clicking on the minus (-) sign located in front of the Region and then expand by clicking on the plus (+) sign. 

Here are some examples  how what it looks like in the editor:

 Collapsed region


Expanded region


with multiple regions


Nested regions

Also, you can have nested regions.


Hope this will help to write well-organised and maintainable CSS coding.



Comments

Popular posts from this blog

Examining the Project structure - ASP.NET Core 7 Part 4

Getting Familiar with Visual Studio 2022 IDE - ASP.NET Core 7 Part 3

Displaying A Start Page In ASP.NET Core 3.1 Web API Project.