WT_UNIT 2_
WT_UNIT 2_
Borders – Margins – Floating and positioning – CSS layout with flexbox and grid – CSS
Animations and Transitions – Responsive Design with Media Queries.
Declarations
The declaration is made up of a property/value pair. There can be more than one
declaration in a single rule; for example, the rule for the p element shown earlier in the code
example has both the font-size and font-family properties.
Each declaration must end with a semicolon to keep it separate from the following
declaration. If you omit the semicolon, the declaration and the one following it will be ignored.
The curly brackets and the declarations they contain are often referred to as the declaration
block.
p{
font-size: large;
font-family: sans-serif;
}
Inline styles apply only to the particular element in which they appear. Inline styles should be
avoided, unless it is absolutely necessary to override styles from an embedded or external style
sheet. Inline styles are problematic in that they intersperse presentation information into the
structural markup.
CSS (Cascading Style Sheets) is a vital tool for web developers and designers to enhance the
appearance and visual aesthetics of their web pages. CSS allows developers to control the layout,
styling, and formatting of HTML elements. There are three primary types of CSS: inline, internal,
and external CSS. In this article, we will learn about these different types of CSS with examples.
Let’s start!!!
Types of CSS
1. Inline CSS
Inline CSS is the simplest form of CSS, and it is embedded within the HTML tags. It is useful when a
single element requires some styling. However, it is not recommended for use on larger projects
because it can become difficult to manage the styles as the project grows. Here’s an example of
inline CSS:
<p style="color: blue; font-size: 20px;">Dataflair: This text is blue and 20px in size.</p>
Advantages of Inline CSS:
Quick and easy to use.
Specific styles can be applied to individual elements.
Overrides external and internal CSS styles.
Disadvantages of Inline CSS:
Difficult to maintain and update.
Increases the size of the HTML file, which can slow down page load times.
Repeated use of inline styles can lead to inconsistent styling across a website.
2. Internal CSS
Internal CSS is used to apply styles to a single HTML document, and it is placed within the head
section of an HTML document. It is useful when working on smaller projects or making changes to
a single HTML document. Here’s an example of internal CSS:
<!DOCTYPE html>
<html>
<head>
<title>Internal CSS Example</title>
<style>
p{
color: blue;
font-size: 20px;
}
</style>
</head>
<body>
<p>This text is blue and 20px in size.</p>
</body>
</html>
Output
Rule order
The cascade follows a “last one wins” rule. Whichever rule appears last has the last word.
The Box Model
As long as we’re talking about Big CSS Concepts, it is only appropriate to introduce the
cornerstone of the CSS visual formatting system: the box model. The easiest way to think of the
box model is that browsers see every element on the page (both block and inline) as being
contained in a little rectangular box. You can apply properties such as borders, margins, padding,
and backgrounds to these boxes, and even reposition them on the page.
Grouped Selectors
Hey! This is a good opportunity to show you a handy style rule shortcut. If you ever need to apply
the same style property to a number of elements, you can group the selectors into one rule by
separating them with commas. This one rule has the same effect as the five rules listed
previously. Grouping them makes future edits more efficient and results in a smaller file size:
FORMATTING TEXT
BASIC FONT PROPERTIES
In CSS, fonts are specified using a set of font-related properties for typeface, size, weight, font
style, and special characters. There are also shortcut properties that let you specify multiple font
attributes in a single rule.
The font-style property affects the posture of the text—that is, whether the letter shapes are vertical
(normal) or slanted (italic and oblique).
Some typefaces come in a “small caps” variant. This is a separate font design that uses small uppercase-
style letters in place of lowercase letters. Small caps characters are designed to match the size and density
of lowercase text so they blend in.
Compare NASA and USA in the standard font to nasa and usa in small caps.
Specifying multiple font properties for each text element can get repetitive and lengthy, so the creators of
CSS provided the shorthand font property, which compiles all the font-related properties into one rule.
order is imporatnt
h1 { color: gray; }
h1 { color: #666666; }
h1 { color: #666; }
h1 { color: rgb(102,102,102); }
Color is inherited, so you can change the color of all the text in a document by applying the color property
to the body element, as shown here:
Element selector
Grouped selectors
p { color: navy; }
Descendant Selectors
A descendant selector targets elements that are contained within (and there fore are descendants of)
another element. It is an example of a contextual selector because it selects the element based on its
context or relation to another element.
li em { color: olive; }
ID Selectors
#sleestak { color: olive; }
Text Shadow The text-shadow property adds a “shadow” below your text that makes it seem to hover or
pop out above the page.