HTML Klasser

Klassificer HTML (sæt klasse), så vi kan definere CSS-stil for elementets klasse.

Sæt samme stil for samme klasse, eller forskellige stiler for forskellige klasser.

Example

<!DOCTYPE html>
<html>
<head>
<style>
.cities {
    background-color:black;
    color:white;
    margin:20px;
    padding:20px;
} 
</style>
</head>
<body>
<div class="cities">
<h2>London</h2>
<p>
London er hovedstaden i England. 
It is the most populous city in the United Kingdom, 
med en metropolområde på over 13 millioner indbyggere.
</p>
</div> 
</body>
</html>

Try it yourself

Klassificer blokkElementType

HTML <div>-elementet erBlokkElementTypeDen kan bruges som container for andre HTML-elementer.

Sæt <div>-elementets klasse, så vi kan sette samme klasse for samme <div>-elementer:

Example

<!DOCTYPE html>
<html>
<head>
<style>
.cities {
    background-color:black;
    color:white;
    margin:20px;
    padding:20px;
} 
</style>
</head>
<body>
<div class="cities">
<h2>London</h2>
<p>London er hovedstaden i England. 
It is the most populous city in the United Kingdom, 
with a metropolitan area of over 13 million inhabitants.</p>
</div>
<div class="cities">
<h2>Paris</h2>
<p>Paris is the capital and most populous city of France.</p>
</div>
<div class="cities">
<h2>Tokyo</h2>
<p>Tokyo is the capital of Japan, the center of the Greater Tokyo Area,</p>
and the most populous metropolitan area in the world.</p>
</div>
</body>
</html>

Try it yourself

Categorize inline elements

The HTML <span> element is an inline element that can be used as a container for text.

Setting the class of a <span> element allows you to set the same style for the same <span> elements.

Example

<!DOCTYPE html>
<html>
<head>
<style>
  span.red {color:red;}
</style>
</head>
<body>
<h1>My <span class="red">Important</span> Heading</h1>
</body>
</html>

Try it yourself