L11 - CSS 3
L11 - CSS 3
COS216
AVINASH SINGH
DEPARTMENT OF COMPUTER SCIENCE
UNIVERSITY OF PRETORIA
CSS – OVERVIEW
• Styling rules
• Details on how to style elements
• Selectors
• Details on which elements to style
CSS – BACKGROUND
body
{
background: #FF44AA url("back.png") no-repeat right top;
background: red; /* set any parameter */
background-color: red; /* set a color */
background-image: url("images/back.jpg"); /* set an image */
p
{
color: rgb(142,256,230);
color: #A4B5C0;
color: red;
}
CSS – TEXT ALIGNMENT
• Align text
• Left
• Right
• Center
• Justify
p
{
text-align: right;
text-align: justify;
}
CSS – VERTICAL ALIGNMENT
• Typically has to be applied on the parent (eg: vertical align property on a table
cell so that its content is vertically aligned)
td
{
vertical-align: middle;
}
CSS – FONTS
p
{
font: 15px arial, sans-serif;
font: italic bold 12px Georgia, serif;
font-size: 12px;
font-size: 5em;
font-weight: bold;
font-weight: 900;
font-style: normal;
font-style: italic;
}
CSS – CUSTOM FONTS
• Examples
CSS – ANIMATIONS
• Keyframes are a predefined set of frames to transition between and can be reused
by different elements
• Example: move element from position X to position Y
• Example: change from color A to color B
• Example: rotate 360 degrees in 5 degree steps
CSS – ANIMATIONS
div
{
width: 50px;
height: 50px;
background: black;
position: relative;
animation: horizontalMove 5s infinite;
}
CSS – ANIMATIONS
@keyframes colorChanger
{
0% {background-color: blue;}
33% {background-color: green;}
66% {background-color: yellow;}
100% {background-color: red;}
}
CSS – ANIMATIONS
@keyframes multiChanger
{
0% {top: 0px; left: 0px; background: red;}
25% {top: 0px; left: 100px; background: blue;}
50% {top: 100px; left: 100px; background: yellow;}
75% {top: 100px; left: 0px; background: green;}
100% {top: 0px; left: 0px; background: red;}
}
CSS – ANIMATIONS
• What about mobile design? Different device sizes? How do we make a website
more responsive?
• The @media rule was created to allow CSS for specific device sizes
• Media queries can be used to determine viewport width and height, orientation
and resolution
• https://www.w3schools.com/css/css3_mediaqueries.asp
• https://www.w3schools.com/css/css3_mediaqueries_ex.asp
CSS – FLEXBOX MODULE
CSS – FLEXBOX MODULE
• Flexbox was introduced in CSS3 in 2017 that provided easier ways to align content
• Easier responsive design
• Ability for elements to be in a container for better design and grouping
https://css-tricks.com/snippets/css/a-guide-to-flexbox/
CSS – FLEXBOX MODULE
• main axis – provides the flex container with the axis / direct.
• main-start | main-end – The start and end positions of the flex container.
• main size – defines the height or width depending on the axis.
CSS – FLEXBOX MODULE
.container
{ .item {
display: flex; /* or inline-flex */ order: 5; /* default is 0 */
} }
CSS – FLEXBOX
.container {
flex-direction: row | row-reverse | column | column-reverse;
}
.container {
flex-wrap: nowrap | wrap | wrap-reverse;
}
CSS – FLEXBOX
.item { .item {
flex-grow: 4; /* default 0 */ order: 5; /* default is 0 */
} }
.item {
flex-shrink: 4; /* default 1 */
}
CSS – FLEXBOX
.container {
justify-content: flex-start | flex-end | center |
space-between | space-around | space-evenly |
start | end | left | right ... + safe | unsafe;
}
CSS – FLEXBOX GUIDE
• https://css-tricks.com/snippets/css/a-guide-to-flexbox/
CSS – ANIMATIONS