CSS
CSS
2
Web Concepts
05. CSS 2/2 Mohammed
AbuJarour
29.10.24
* SUBJECT TO CHANGE
Plan
<body>
<ul class="nav">
<li class="menu"><a href="html.html">HTML</a></li> |
<li class="menu"><a href="css.html">CSS</a></li> |
<li class="menu"><a href="js.html">JavaScript</a></li>
</ul>
<p> In this tutorial, we will discuss:
<ul>
<li>Basics</li>
<li>Examples</li>
<li>Best practices</li>
</ul>
</p>
• The position property specifies the type of positioning method used for an element
(static, relative, fixed, absolute or sticky).
• Elements are then positioned using the top, bottom, left, and right properties.
• These properties will not work unless the position property is set first.
• They also work differently depending on the position value.
• HTML elements are positioned static by default.
.relative {
position: relative;
left: 3em;
color: blue;
}
.fixed {
position: fixed;
bottom: 0;
right: 0;
color: crimson;
}
.absolute {
position: absolute;
right: 10px;
color: green;
}
</style>
3.none - The element does not float (will be displayed just where it occurs in the
text). This is default
<p>
<img src="logo.png">
The demand for digitization ...
</p>
img {
float: right;
}
• To horizontally center a block element (like <div> ), use margin: auto; and set the
width of the element to prevent it from stretching out to the edges of its container.
• To center an image, set left and right margin to auto and make it into
a block element
• <aside> defines content aside from the content (like a sidebar) <aside>
• <footer> defines a footer for a document or a section
• <details> defines additional details <article>
<section>
<article>
<h2>HTML</h2>
<p><!-- ... --></p>
<p><!-- ... --></p>
</article>
<aside>Google Ads come here!</aside>
</section>
<footer>
<p> All rights reserved. ©
MDH University Berlin, 2024</p>
</footer>
</body>
• The Flexible Box Layout Module, • The flex container properties are:
makes it easier to design flexible 1.flex-direction
responsive layout structure without
2.flex-wrap
using float or positioning.
3.flex-flow
• To start using the Flexbox model, you
4.justify-content
need to first define a flex container.
5.align-items
• The flex container becomes flexible
by setting the display property to flex 6.align-content
.flex-container {
display: flex;
background-color: lightblue;
flex-wrap: wrap;
/* nowrap wrap-reverse */
}
Property Description
display Specifies the type of box used for an HTML element
flex-direction Specifies the direction of the flexible items inside a flex container
justify-content Horizontally aligns the flex items when the items do not use all available
space on the main-axis
align-items Vertically aligns the flex items when the items do not use all available
space on the cross-axis
flex-wrap Specifies whether the flex items should wrap or not, if there is not enough
room for them on one flex line
align-content Modifies the behavior of the flex-wrap property. It is similar to align-items, but
instead of aligning flex items, it aligns flex lines
flex-flow A shorthand property for flex-direction and flex-wrap
• The direct child elements of a flex • The flex item properties are:
container automatically becomes
1.order
flexible (flex) items.
2.flex-grow
3.flex-shrink
4.flex-basis
5.flex
6.align-self
<div class="flex-container">
<div style="order: 2">1</div>
<div style="order: 1">2</div>
<div style="order: 3">3</div>
<div style="order: -1">4</div>
<div>5</div>
<div>6</div> • The order property specifies the order
<div>7</div> of the flex items.
<div>8</div> • The order value must be a number,
<div>9</div> default value is 0.
</div>
• The CSS Grid Layout Module offers a grid-based layout system, with rows and
columns, making it easier to design web pages without having to use floats and
positioning.
• A grid layout consists of a parent element, with one or more child elements.
• An HTML element becomes a grid container when its display property is set
to grid or inline-grid.
• All direct children of the grid container automatically become grid items.
.item1 {
grid-column: 1 / span 2;
grid-row: 1;
}
• Grid and Flexbox are both excellent tools ➔ Pick the tools that best suit what
you’re trying to build
• Links can be styled with any CSS • The four links states are:
property (e.g., color, font-
1.a:link - a normal, unvisited link
family, background, etc.).
2.a:visited - a link the user has visited
• In addition, links can be styled
differently depending on 3.a:hover - a link when the user
what state they are in. mouse is over it
4.a:active - a link the moment it is
clicked
a:link {
color: red;
}
a:visited {
color: green;
}
a:hover {
color: hotpink;
}
a:active {
color: blue;
}
• CSS:
https://www.w3schools.com/css/default.asp
• Learn to style HTML using CSS:
https://developer.mozilla.org/en-
US/docs/Learn/CSS
CSS
Mohammed AbuJarour – CSS 2/2 29.10.24 49
CSS Diner
• https://www.w3schools.com/css/exercise.asp
• https://github.com/TheOdinProject/css-exercises