CSE 205 Lesson 4
CSE 205 Lesson 4
Introduction to CSS
• CSS can easily apply same style rules on multiple elements.
• CSS can control the presentation of multiple pages of a website
with a single style sheet.
• CSS can present the same page differently on different devices.
• CSS can style dynamic states of elements such as hover, focus, etc.
that isn't possible otherwise.
• CSS can change the position of an element on a web page without
changing the markup.
• CSS can alter the display of existing HTML elements.
• CSS can transform elements like scale, rotate, skew, etc. in 2D or 3D
space.
• CSS can create animations and transitions effects without using any
JavaScript.
• CSS can create print friendly version of web pages.
Advantages of CSS
• CSS Save Lots of Time — CSS gives lots of flexibility to set the style properties of an
element. You can write CSS once; and then the same code can be applied to the
groups of HTML elements, and can also be reused in multiple HTML pages.
• Easy Maintenance — CSS provides an easy means to update the formatting of the
documents, and to maintain the consistency across multiple documents. Because
the content of the entire set of web pages can be easily controlled using one or
more style sheets.
• Pages Load Faster — CSS enables multiple pages to share the formatting
information, which reduces complexity and repetition in the structural contents of
the documents. It significantly reduces the file transfer size, which results in a
faster page loading.
• Superior Styles to HTML — CSS has much wider presentation capabilities than
HTML and provide much better control over the layout of your web pages. So you
can give far better look to your web pages in comparison to the HTML
presentational elements and attributes.
• Multiple Device Compatibility — CSS also allows web pages to be optimized for
more than one type of device or media. Using CSS the same HTML document can
be presented in different viewing styles for different rendering devices such as
desktop, cell phones, etc.
CSS Syntax
A CSS rule-set consists of a selector and a declaration block:
The simplest is within the header of Use @import rule to import a style
the document sheet within another style sheet.
<style> @import url("css/layout.css");
@import url("css/style.css"); @import url("css/color.css");
p{ body {
color: blue; color: blue;
font-size: 16px; font-size: 14px;
} }
</style>
Among all the three methods, using external style sheet is the best method for
defining and applying styles to the HTML documents. As you can clearly see with
external style sheets, the affected HTML file require minimal changes in the markup .