Lect 04-SET 372 - CSS
Lect 04-SET 372 - CSS
04 Introduction to CSS
body {
Property Value
CSS Sheet
CSS Pseudo Selectors
: hover selector is used to select elements when you mouse over them.
hover - Apply rule when mouse is over element (e.g. tooltip)
p:hover, a:hover {
background-color: yellow;
}
a:link , a: visited - Apply rule when link has been visited or not visited (link)
a:visited { a:link {
color: green; color: blue;
} }
CSS Properties
p: { text-decoration: line-through;
}
● Also used in animation
CSS Properties: Coloring
Must ultimately turn into red, green, and blue intensities between 0 and 255:
● Predefined names: red, blue, green, white, etc. (140 standard names)
● 8-bit hexadecimal numbers for red, green, blue: #ff0000
.div1 {
width: 300px;
height: 100px;
border: 1px solid blue;
box-sizing: border-box;
}
.div2 {
width: 300px;
height: 100px;
padding: 50px;
border: 1px solid red;
box-sizing: border-box;
}
This means: When you set the width/height of an element, the element
often appears bigger than you have set (because the element's border and
padding are added to the element's specified width/height).
The following illustration shows two <div> elements with the same
specified width and height:
.div2 {
width: 300px;
height: 100px;
padding: 50px;
border: 1px solid red;
}
The CSS box model is essentially a box that wraps around every
HTML element. It consists of: content, padding, borders and
margins.
CSS distance units
Size Properties : Element, pad,
margin, border
Width
Override element defaults border-bottom-color
height
border-bottom-style
padding-top border-bottom-width
padding-right border-left-color
border-left-style
padding-bottom border-left-width
padding-left border-right-color
border-right-style
border-right-width etc.
margin-top
i.e.
margin-right
margin-bottom p {
border: 5px solid red;
margin-left }
position property
To start using the Flexbox model, you need to first define a flex
container.
The element above represents a flex container (the blue area) with
three flex items.
The flex container becomes flexible by setting the display
property to flex:
Example
.flex-container {
display: flex;
}
SET 372 – Internet Development 12-Mar-
24
Flexbox and Grid layout
The <span> tag is much like the <div> element, but <div> is
a block-level element and <span> is an inline element.
Inheritance
○ Some properties (e.g. font-size) are inherited from parent elements
○ Others (border, background) are not inherited.
<span>Text1</span>
span.test { color: green }
<span class="test"> Text2 </span>
span { color: red }
Adding Styles to HTML
<style type="text/css">
body {
font-family: Tahoma, Arial, sans-serif;
}
</style>
Page-specific styles
</head>
<body>
<div style="padding:2px; ... ">
</body>
Element-specific styles
CSS: HTML
CSS HTML
Example Output
27
CSS Media Queries
Media queries are a popular technique for delivering a tailored style sheet to
different devices. To demonstrate a simple example, we can change the
background color for different devices:
/* On screens that are 992px or less, set the background color to blue
*/
@media screen and (max-width: 992px) {
body {
background-color: blue;
}
}
/* On screens that are 600px or less, set the background color to olive
*/
@media screen and (max-width: 600px) {
body {
background-color: olive;
}
}
SET 372 – Internet Development 12-Mar-
24
Output 1: Media Screen 29
blue
Composition is a problem
○ It can be really hard to figure out what rule from which
style sheet is messing things up