Web Technologies

CSS

Claudia Chiriță . 2026/2027

METADATA

HTML metadata

  <head>
    Page Title 
    
    
    
    
    
    
    
    
    
    
    
  </head>

Base element

  • defines the base URL for all relative URLs in the document
  • in a document there can only be one base

Base element

CSS

CSS = CASCADING STYLE SHEETS

  • style sheet language used for defining the presentation of a web page:
    • styling elements: color, size, font etc.
    • setting the page layout
    • defining visibility
  • also used for animations

style file

<head>
...

...
</head>

CSS rules

  • the style file contains one or more CSS rules

selector { 
  prop1: value1;
  prop2: value2;
  prop3: value3;
  ...
}
p { 
  color: pink;
  font-family: sans-serif;
  font-size: 12pt;
}

HTML + CSS alignment

in a separate file

HTML + CSS alignment

in the same file

HTML + CSS alignment

in line

Style precedence

in ascending order of precedence:

  1. implicit style of the browser
  2. external CSS file and in file styles; the style that is written last in the <head> is applied
  3. inline styles

Selectors

selector1, selector2 { 
  prop1: value1;
}
selector1 {  
  prop2: value2;
}
  • several rules can be applied to an element
  • we group elements with a common style; we write specific styles in separate rules
  • some styles are inherited from the parent elements (in the DOM tree), but can be changed using specific rules

Properties: Colors

color: defining the color of the text;
background-color: defining the color of the background;
  • specified through name: red, green, blue, pink, ...

Properties: Colors

Properties: Colors

Properties: Colors

Distance/size

  • absolute units: mm, cm, px, in, pt
  • relative units:
    • em: relative to the element font size
    • %: relative to the parent size
    • vw, vh: relative to 1% of the width/height
      of the viewport
    • rem: relative to the root font size

selectors

universal selector *

Selecting by type

name of an element from the document: h1, p, div, a...

Selecting by id

  • #identif selects the element with id="identif"
  • <tag id="identif"> content </tag>
    an HTML document can contain a single id attribute with value "identif"

Selecting by class

  • .cls selects elements with class="cls"
  • <tag1 class="cls"> content </tag1>
    <tag2 class="cls"> content </tag2> with the class attribute we group several elements that will have a common style

Selecting by class

Specificity

selecting by id has greater specificity than by class

Specificity

when two styles have the same specificity, the one written last in the CSS file wins

!important

properties marked as !important are applied regardless of their specificity

inherit

  • some properties can have the value inherit: the property is inherited from the parent element
  • used to overwrite a style and force the implicit behaviour

Combining selectors

  • selectors for descendents
    E F   selects all F elements that are descendents of E
  • selectors for children
    E > F   selects all F elements that are children of E
  • selectors for siblings
    E + F   selects all F elements that are siblings of E and that follow imemdiately after E
    E ~ F   selects all F elements that are siblings of E and that follow after E

Combining selectors

Selecting by attributes

  • e[attr] -> elements e that have attribute attr
  • e[attr="val"] -> elements e with attr="val"
  • e[attr~="val"] -> elements e with the property that the value of attr contains the word val
  • e[attr*="val"] -> elements e with the property that the value of attr contains the substring val

CSS BOX model

  • representation of the space that an element occupies in a page and of the way in which this relates to other elements
box

CSS BOX model

CSS default values

width + height

width: 500px /* 50% */
/* height, max-width, min-width, max-height, min-height */

BORDER

border: width style color;
border-left: width style color;
border-right: width style color;
border-top: width style color;
border-bottom: width style color;
  • width: given in px, pt, em, thin, medium, thick
  • style: none, solid, dotted, dashed, inset, outset, double, groove, ridge, hidden

BORDER

border-color: ...;
border-style: ...;
border-width: ...;
border-left-color: ...;
border-bottom-width: ...;
border-radius: 12px; /* margins with rounded corners */ 

padding + margin

padding: 15px;
padding-top: 15px;
padding-right: 20%;
padding-bottom:15px;
padding-left: 10%;
margin: 15px;
margin-top: 15px;
margin-right: 20%;
margin-bottom:15px;
margin-left: 10%;
margin: 15px 20% 15px 10%;
padding: 15px 20% 15px 10%;

FLASH QUIZ

box
  • the width and height and the yellow square are 150px
  • the width and height of the big square are 250px
  • the width of the pink and blue strips is 25px

FLASH QUIZ


  
  • the width and height and the yellow square are 150px
  • the width and height of the big square are 250px
  • the width of the pink and blue strips is 25px

FLASH QUIZ

FLASH QUIZ SOLUTION #1

FLASH QUIZ SOLUTION #2

fonts

font-family: Helvetica,"Times New Roman",serif;
font-size: 16px; /* 16pt, 1.25em, 125%, x-large*/
font-weight: normal; /* bold, lighter, bolder, 100,...,900 */
font-style: normal; /* italic, oblique */
font-family:
  • generic fonts: serif, sans-serif, monospace, cursive, fantasy
  • specific fonts: Times New Roman, Arial, Georgia, Verdana

fonts

font-family: Helvetica,"Times New Roman",serif;
font-size: 16px; /* 16pt, 1.25em, 125%, x-large*/
font-weight: normal; /* bold, lighter, bolder, 100,...,900 */
font-style: normal; /* italic, oblique */
font-size:
  • units: px, pt, em (1em = current font size)
  • values: xx-small, x-small, small, medium, large, x-large, xx-large, ...
  • percentage: percentage of the font size of the parent

custom fonts

/* for importing a font*/
	
@font-face { 
font-family: name-of-the-font;
src:url(file-font.ext); 
}

selector { font-family: name-of-the-font; 
}

custom fonts

example: embed mr. Roboto

text formatting

color: pink;
text-align: center; /* left, right, justify */
text-decoration: underline; /* overline, line-through */
text-shadow: -2px 5px 2px gray; /* none initial */
/* x-offset, y-offset, blur-radius, color */
text-indent: 3em;
text-transform: uppercase; /* lowercase, capitalize */
line-height: 150%; /* 1.5em , 30px */
word-spacing: 1em; /* +15mm */
letter-spacing: 0.1em; /* -1px */
	

visibility

visibility: visible; /* hidden */
  • sets the visibility of an element;
    even if the visibility is hidden, the element occupies some space in the page

overflow

overflow: hidden; /* visible, scroll */
  • describes the way in which a text overflowing a frame is displayed

display

display: inline; /* block, inline-block, none */
  • describes the way in which an element is displayed on a page
  • the space that it occupies is the size of the element
  • ignores the width and height properties, but accepts border, padding

display

display: block; /* inline, inline-block, none */
  • describes the way in which an element is displayed on a page
  • styling using the box model is allowed
  • new line placing

display

display: inline-block; /* inline, block, none */
  • describes the way in which an element is displayed on a page
  • element positioned inline that can be styled as a block element
  • accepts width and height properties

display

display: none; /* inline, block, inline-block */
  • describes the way in which an element is displayed on a page
  • the element is not displayed
  • although the element is not on the page, it is present in the DOM

Extra++


          
                  _,.,.__,--.__,-----.
                ,""   '))              `.
              ,'   e                    ))
             (  .-'__,                  ,
              `~`    `-\  /._____,/   /
                       | | )    (  (   ;
                       | | |    / / / / 
              
                         questions?