CSS has become a fundamental part of designing C# ASP .NET web applications. All web applications designed by Primary Objects include CSS styles and inner-html effects for a professional polished look. With the importance of cross-browser compatibility, neatness, and world wide web standards, CSS effectively brings your site up to date.
What ever happened to the good old days of using font tags? Some web developers will state that using font tags is actually a crime. The problem with font tags is that you don’t exactly get the size and look of what you really want. Instead, you are confined within the limits of the defined font. Further, a user’s web browser may change the font size by using the View menu option.
CSS styles often retain their set font sizes, although this depends on the web browser. Possibly, one of the most powerful feature of CSS is using CSS style sheets. With a style sheet, you can define specific styles using CSS, which will affect all HTML objects throughout your site. For example, you could set a style to draw a blue border around all tables. Now, when you create a table, you need not worry about drawing the borders manually and specifying sides, color, width, etc. You simply give the table a class name and the style is instantly applied.
Example setting blue border around all tables, courtesy of the CSS Table Border Style Wizard
Example validating form with hidden DIV tag:
If you paste the above example into Notepad and save it as an HTML file, you can see how using hidden DIV tags and the innerHTML property can greatly enhance the functionality of a web application. Note the CSS style on the error message enclosed within a span tag. An example of this running is shown below.
Including CSS style code within a web page can often become messy. This is especially the case when dealing with ASP .NET master page templates or ascx files. A better approach is to save the CSS styles within a stylesheet file, such as style.css, and linking to the style sheet from the master page template ascx file. To link the CSS file within a template, use the following code:
CSS styles can greatly enhance the appearance of ASP .NET web applications when used correctly. Experiment with designs and colors to achieve the perfect effects and don’t forget those hidden DIV tags.
This article was written by Kory Becker, software developer and architect, skilled in a range of technologies, including web application development, machine learning, artificial intelligence, and data science.