ASP.NET Interview questions and answers for cascading style sheets

What are Cascading style sheets?
Cascading style sheets (CSS) collect and organize all of the formatting information applied to HTML elements on a Web form. Because they keep this information in a single location, style sheets make it easy to adjust the appearance of Web applications.

What are the 3 levels at which formatting can be applied with in a web application?
1. Styles can be defined in a style sheet file. Styles in a style sheet can be applied to all webforms referencing the style sheet.

2. You can also define styles in the page’s head element. These styles can be applied to all elements on the current page.

3. You can also define styles inline, in the HTML tag itself. Inline styles are applicable only to the HTML element in which these styles are defined.

Inline formatting takes precedence over local formatting, which, in turn, takes precedence over global formatting. These precedence rules are the reason style sheets are referred to as cascading.

What are the advantages of storing style definitions in a style sheet file (.css) rather than locally in each Web form or inline with each HTML element?
1. Formatting can be maintained in one location so that you make changes only once for an entire application.

2. Several sets of parallel formatting rules can be maintained in separate style sheets for formatting output on different devices or for different user needs. For example, an application might provide standard, enlarged-type, and printer-friendly style sheets that the user can select at run time.

3. In general, you should use page and inline styles only when you have a really good reason to override the global styles. Relying heavily on page and inline styles can make it difficult to maintain the formatting in a Web application.

What HTML element is used to reference a style sheet on webform?
To reference a style sheet on webform you must add a link element to the page’s head element, as shown below.

link href="Styles.css" type="text/css" rel="st"

What is the use of Style Builder?
Style Builder is used to change the appearance of any of the styles in a style sheet. Changes to the style sheet change the appearance of all Web forms that reference that style sheet.

How do you modify a style sheet using style builder?
To modify a style sheet using style builder, follow these steps:

1. Open the style sheet in Visual Studio. Visual Studio .NET displays the style definitions in the Document window and an outline of the style sheet in the Tool window

2. Select the style to modify from the Tool window. Visual Studio .NET displays the definition for that style in the Document window.

3. Right-click in the style definition or right-click the style in the Tool window, and select Build Style from the shortcut menu. Visual Studio .NET displays the Style Builder Wizard.

4. Use the Style Builder to compose the formatting that you want to add or modify in the selected style, and then click OK.

5. When you have finished, you’ll see that the Style Builder adds the new or modified style attributes to the style definition.

Can you apply styles using class names or element IDs?
Yes, Using class names allows you to apply a single style to a number of different elements or to style the same element differently, depending on how the element is used. Using element IDs allows you to apply a style to a unique element on one or more Web forms.

When you create a style rule for a class, Visual Studio .NET adds a style definition to the style sheet using a .classified identifier.

You apply the style class to HTML elements by using the class attribute. You apply the style to server controls by using the Cssclass attribute.

Can you change style sheets at run time?

No comments:

Top Blogs