CSS
Seoul National University of Science and Technology
Information Technology Management
Lecture slides index
March 10, 2025
Words + images
HTML
CSS
JavaScript
Best Practice
To keep your code clean and easier to mantain, separate your styling into its own file.
style
attribute and tag embedded in HTML<link>
elements.CSS Property | Example Values |
---|---|
color |
red, blue, #000000 (black) |
text-align |
left, right, center, justify |
width , height |
auto, 100px, 50%, 100% |
margin , padding |
0, 10px, 20px, 1em |
font-family |
Arial, Times New Roman, sans-serif, serif |
font-size |
12px, 16px, 1.5em, |
font-weight |
normal, bold, 400, 700 |
border |
none, 1px solid black, 2px dashed red, 3px double blue |
Allows us to reduce redundancy by grouping together rules into rulesets to style multiples types of elements with common styles. What will text inside the <p>
tag look like here?
id
and class
id
class
All styles “cascade” from the top of the sheet to the bottom
Source Order: If multiple CSS rules have the same specificity, the one that appears later in the stylesheet overrides earlier ones.
Specificity: More specific selectors (like IDs) override less specific ones (classes, tags).
Importance (!important
): Styles marked with !important override specificity and source order, becoming top priority.
How the browser represents the hierarchy of a page. Very useful when thinking about selectors!
For example:
<p>
, <em>
, <body>
, etc.) is part of the DOM, and has a place in a tree hierarchy.<body>
’s is <html>
) and almost always have a child (<title>
is a child of <head>
).Syntx | Name | Description |
---|---|---|
a, b |
Multiple Element Selector | |
a b |
Descendant Selector | Selects all b elements located anywhere inside of a |
a > b |
Child Selector | Selects all b descendants directly inside a elements |
a + b |
Adjacent Sibling Selector | Selects b only if it shares a parent with a and is immediately after it in the DOM |
[a=b] |
Attribute Selector | |
a:b |
Pseudoclass Selector | |
a::b |
Pseudoelement Selector |
Adjusts a website’s layout to fit the screen size of the device it’s being viewed on.
It allows a single website to work across many devices, including desktops, tablets, and phones.
Responsive design related concepts:
The viewport is the user’s visible area of a web page.
The viewport varies with the device, and will be smaller on a mobile phone than on a computer screen.
Include this line in the <head>
tag of your HTML document.
<meta name=viewport>
tag is essential for controlling how a webpage fits into different screen sizes
width=device-width
match the width of the viewport to the width of the device
initial-scale=1.0
defines the zoom of the page the moment it loads
Media types:
print
, screen
, hover
, etc.Media features:
height
, width
, orientation
, etc.The CSS box model module defines the margin
and padding
properties, which along with the height
, width
and border
properties, make up the CSS box model.
To label the container as a flex container we use the CSS set
dipslay:flex
display: flex;
-makes an element a “flex container”, items inside automatically become “items” - by default, starts as a row
justify-content: flex-end;
(flex-start
, space-around
,…)
align-items: flex-end;
(flex-start
, center
, baseline
,…) - indicates how to space the items inside the container along the cross axis
flex-direction: row
; (column
) - indicates whether the container flows horizontally or vertically (default row)
flex-wrap: wrap;
(no-wrap
, …) - indicates whether the container’s children should wrap on new lines
flex-direction
flex-direction
is row. If you change the flex-direction
to column you are changing the orientation of the axes.justify-content
still controls items along the main axis. The main axis is just vertical nowIt divides the page into major regions and defines the relationship in terms of size, position, and layering between parts of a control built from HTML primitives.
To label the container as a grid container we use the CSS set
grid-column-gap
and grid-row-gap
specifies the gap between the columns and rowsgrid-template-columns
and grid-template-rows
specifies the size of the rows in a grid layoutBootstrap is one of the most popular HTML, CSS, and JavaScript framework for developing responsive, mobile-first websites.
Bootstrap is opensource under the MIT license .
<head>
element of your HTML document<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
Say hello to our new friend, JavaScript…
Web Programming