Interne

Eksterne


OPP


ATTRIBUTTER

Attributter

Attributter er tillegg eller noe ekstra til HTML-elementet og de settes alltid inn i starttagen. Et av de mest vanlige attributtene er href-attributtet. Det er det som gjør a-elementet til en link. Uten dette attributtet ville ikke nettleseren visst hvor på nettet den skulle sende deg.

<a href="http://www.google.com">www.google.com</a>

På bilde over er href navnet på attributtet, mens det som er i mellom anførselstegnene er verdien til attributtet. Verdien til attributtet, som her er adressen til Google, må alltid være omsluttet av to anførselstegn. I tillegg må det også alltid være et = mellom navnet på attributtet og verdien.

<a href="folder1/folder2/file1.html">link</a>

I det første eksempelet linkes det til en ekstern nettside. Det kalles for en absolutt link. Hvis du skal linke til en intern side. Dvs. en annen HTML-side som ligger på samme server. Så skriver du bare navnet på filen og eventuelt navnet på mappen den ligger i.

<a href="#seksjon371">Go to section 371</a>
 ...
<h3 id="seksjon371">Section 371</h3>

Du kan også linke til et sted på samme side. Hvis du setter inn en id-attributt et sted på en side og så har du en link et annet sted så kan du bare skrive # og navnet du satte inn i id-attributtet i href-attributtet, så vil du bli sendt til den id-en når du klikke på linken.

<img src="folder/picture.jpg">

Bildeelementet er også et veldig vanlig og mye brukt element som må ha en attributt for å fungere. Elementet for bilde i HTML er img og attributtet er src. Akkurat som verdien av href i en link er adressen til stedet det linkes til, er src stien eller adressen til der hvor selve bildefilen ligger på serveren, f.eks bildemappe01/bilde.jpg.

Mange attributter

Det finnes mange attributter i HTML og det er ikke noe poeng å gå gjennom alle her eller lære seg alle. Du trenger bare lære deg en håndfull attributter og så kan du lære deg resten etterhvert som du får behov for flere. Noen attributter er spesifikke for noen enkelte elementer mens andre er mer generelle og kan brukes på alle elementene i HTML. Det er heller ingen grenser for hvor mange attributter du kan putte inn i starttagen på et element.

<h3 id="title">My heading</h3>
<p class="lead">This is a paragraph with text.</p>

Jeg nevner til slutt 2 generelle attributter, de heter id og class. De kan brukes på alle elementer og brukes nesten alltid i sammenheng med stilspråket CSS. Dette språket kan du lære mer om senere men id og class attributtene brukes oftest til å lage «knagger» til å henge CSS på.

Det vil ikke bli noen endring i utseende i nettleseren, men du har nå muligheten til å påvirke de elementene spesielt ved hjelp av CSS.


w3schools: HTML Attributes

PB: Dette er kun en liten liste, av veldig mange.

PB: Plukket ut de mest nærliggende for mitt behov, fra (https://www.w3schools.com/tags/ref_attributes.asp).

alt
- Specifies an alternate text when the original element fails to display.
- Belongs to: <area> <img> <input>
charset
- Specifies the height of the element.
- Belongs to: <meta> <script>
cite
- Specifies a URL which explains the quote/deleted/inserted text.
- Belongs to: <blockquote> <del> <ins> <q>
class
- Specifies one or more classnames for an element (refers to a class in a style sheet).
- Belongs to: Global Attributes.
cols
- Specifies the visible width of a text area.
- Belongs to: <textarea>
colspan
- Specifies the number of columns a table cell should span.
- Belongs to: <td> <th>
content
- Gives the value associated with the http-equiv or name attribute.
- Belongs to: <meta>
headers
- Specifies one or more headers cells a cell is related to.
- Belongs to: <td> <th>
height
- Specifies the height of the element.
- Belongs to: <canvas> <embed> <iframe> <img> <input> <object> <video>
href
- Specifies the height of the element.
- Belongs to: <a> <area> <base> <link>
http-equiv
- Provides an HTTP header for the information/value of the content attribute.
- Belongs to: <meta>
id
- Specifies a unique id for an element.
- Belongs to: Global Attributes.
lang
- Specifies the language of the element's content.
- Belongs to: Global Attributes.
media
- Specifies what media/device the linked document is optimized for.
- Belongs to: <a> <area> <link> <source> <style>
name
- Specifies the name of the element.
- Belongs to: <button> <fieldset> <form> <iframe> <input> <map> <meta> <object> <output> <param> <select> <textarea>
onmouseover
- Script to be run when a mouse pointer moves over an element.
- Belongs to: All visible elements.
onresize
- Script to be run when the browser window is being resized.
- Belongs to: <body>
onsearch
- Script to be run when the user writes something in a search field (for <input="search">).
- Belongs to: <input>
placeholder
- Specifies a short hint that describes the expected value of the element.
- Belongs to: <input> <textarea>
rel
- Specifies the relationship between the current document and the linked document.
- Belongs to: <a> <area> <form> <link>
required
- Specifies that the element must be filled out before submitting the form.
- Belongs to: <input> <select> <textarea>
reversed
- Specifies that the list order should be descending (9,8,7...).
- Belongs to: <ol>
rows
- Specifies the visible number of lines in a text area.
- Belongs to: <textarea>
rowspan
- Specifies the number of rows a table cell should span.
- Belongs to: <td> <th>
sandbox
- Enables an extra set of restrictions for the content in an <iframe>.
- Belongs to: <iframe>
scope
- Specifies whether a header cell is a header for a column, row, or group of columns or rows.
- Belongs to: <th>
span
- Specifies the number of columns to span.
- Belongs to: <col> <colgroup>
spellcheck
- Specifies whether the element is to have its spelling and grammar checked or not.
- Belongs to: Global Attributes.
src
- Specifies the URL of the media file.
- Belongs to: <audio> <embed> <iframe> <img> <input> <script> <source> <track> <video>
srcdoc
- Specifies the HTML content of the page to show in the <iframe>.
- Belongs to: <iframe>
srcset
- Specifies the URL of the image to use in different situations.
- Belongs to: <img> <source>
start
- Specifies the start value of an ordered list.
- Belongs to: <ol>
style
- Specifies the start value of an ordered list.
- Belongs to: Global Attributes.
target
- Specifies the target for where to open the linked document or where to submit the form.
- Belongs to: <a> <area> <base> <form>
title
- Specifies extra information about an element.
- Belongs to: Global Attributes.
translate
- Specifies whether the content of an element should be translated or not.
- Belongs to: Global Attributes.
type
- Specifies the type of element.
- Belongs to: <a> <button> <embed> <input> <link> <menu> <object> <script> <source> <style>
value
- Specifies the value of the element.
- Belongs to: <button> <input> <li> <option> <meter> <progress> <param>
width
- Specifies the width of the element.
- Belongs to: <canvas> <embed> <iframe> <img> <input> <object> <video>


BACKGROUND

Info fra W3school

The background property is a shorthand property for:

It does not matter if one of the values above are missing, e.g. background:#ff0000 url(smiley.gif); is allowed.

Note: If using multiple background-image sources but also want a background-color, the background-color parameter needs to be last in the list.

Shorthand

body {
  background-color: #ffffff;
  background-image: url("img_tree.png");
  background-repeat: no-repeat;
  background-position: right top;
}
body {
  background: #ffffff url("img_tree.png") no-repeat right top;
}

When using the shorthand property the order of the property values is:


Brukendes i bruk

.note {
  background: #d5e9f6;
  color: #144261;
  padding: 2px 18px;
}

Note: Rippet fra www.tutorialrepublic.com.

.tip {
  background: #d5efc2;
  color: #2e5014;
  padding: 2px 18px;
}

Tip: Rippet fra www.tutorialrepublic.com.

.warning {
  background: #ecd2d7;
  color: #913944;
  padding: 2px 18px;
}

Warning: Rippet fra www.tutorialrepublic.com, kan brukes på OBS! også.


Fra (hiof.instructure.com/courses/713/pages/css-farger-og-fonter)

De mest brukte attributter som angår bakgrunnseffekter for html-elementene er:

Example

body {background-color: lightblue;}
h1 {background-color: green;}
div {background-color: powderblue;}
p {background-color: yellow;}

<h1>Header</h1>

<div>
</div>

<p> style="background-color:yellow;"</p>


https://developer.mozilla.org/en-US/docs/Web/CSS/background

/* Using a <background-color> */
background: green;

/* Using a <bg-image> and <repeat-style> */
background: url("test.jpg") repeat-y;

/* Using a <box> and <background-color> */
background: border-box red;

/* A single image, centered and scaled */
background: no-repeat center/80% url("../img/image.png");

CSS background-image Property

w3schools.com

Definition and Usage

The background-image property sets one or more background images for an element.

By default, a background-image is placed at the top-left corner of an element, and repeated both vertically and horizontally.

Tip: The background of an element is the total size of the element, including padding and border (but not the margin).

Tip: Always set a background-color to be used if the image is unavailable.

Her blander jeg litt med egne og nedlastede bilder og stier:

Example

body {
  background-image: url('bilder/img_tree.gif'), url('bilder/paper.gif');
  background-color: #cccccc;
}

Example

body {
  background-image: url('bilder/img_tree.png');
  background-repeat: no-repeat;
  background-position: right top;
  margin-right: 200px;
}

Hello World!

W3Schools background no-repeat, set position example.

Now the background image is only shown once, and positioned away from the text.

In this example we have also added a margin on the right side, so the background image will never disturb the text.

Example

body {
  background-image: url('bilder/img_tree.png');
  background-repeat: repeat-x;
}

Hello World!

Here, a background image is repeated only horizontally!

Example

body {
  background-image: url('bilder/img_tree.png');
  background-repeat: repeat-y;
}

Heisann verden!

Og her repeteres bakgrunnsbildet vertikalt!

Background Cover

Set the background-size property to "cover" and the background image will cover the entire element, in this case the body element.


body {
  background-image: url('img_girl.jpg');
  background-repeat: no-repeat;
  background-attachment: fixed;  
  background-size: cover;
}

Example

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
}

.hero-image {
  background-image: url("/w3images/photographer.jpg");
  background-color: #cccccc;
  height: 500px;
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  position: relative;
}

.hero-text {
  text-align: center;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: white;
}
<div class="hero-image">
  <div class="hero-text">
    <h1 style="font-size:50px">I am Jane Doe</h1>
    <h3>And I'm a Photographer</h3>
    <button>Hire me</button>
  </div>
</div>

Note that this technique will also make the image responsive: Resize the browser window to see the effect.

Petrus Bojanowski

Driver med musikk og data


Linear Gradient as Background Image

Verktøy for å lage, se: https://cssgradient.io/

w3schools.com

Example

#grad1 {
  height: 100px;
  background-color: #cccccc;
  background-image: linear-gradient(red, yellow);
}
<div id="grad1"></div>

Example

#grad1 {
  height: 100px;
  background-color: #cccccc;
  background-image: linear-gradient(red, yellow, green);
}

Example

#grad1 {
  height: 100px;
  background-color: #cccccc;
  background-image: repeating-linear-gradient(red, yellow 10%, green 20%);
}

Example

#grad1 {
  height: 100px;
  background-color: #cccccc;
  background-image: radial-gradient(red, yellow);
}

Example

#grad1 {
  height: 100px;
  background-color: #cccccc;
  background-image: radial-gradient(red, yellow, green);
}

Example

#grad1 {
  height: 100px;
  background-color: #cccccc;
  background-image: repeating-radial-gradient(red, yellow 10%, green 15%);
}

Example

#grad1 {
  height: 100px;
  background-color: red; /* For browsers that do not support gradients */
  background-image: linear-gradient(to right, red , yellow);
}

Example

#grad1 {
  height: 100px;
  background-color: red; /* For browsers that do not support gradients */
  background-image: linear-gradient(to bottom right, red, yellow);
}

Example

#grad1 {
  height: 100px;
  background-color: blue; /* For browsers that do not support gradients */
  background-image: linear-gradient(0deg, blue, lime);
}

Example

#grad1 {
  height: 100px;
  background-color: blue; /* For browsers that do not support gradients */
  background-image: linear-gradient(90deg, blue, lime);
}

Example

#grad1 {
  height: 100px;
  background-color: blue; /* For browsers that do not support gradients */
  background-image: linear-gradient(180deg, blue, lime);
}

Example

#grad1 {
  height: 100px;
  background-color: blue; /* For browsers that do not support gradients */
  background-image: linear-gradient(-90deg, blue, lime);
}

Example

#grad1 {
  height: 100px;
  background-color: blue; /* For browsers that do not support gradients */
  background-image: linear-gradient(90deg, #00CED1, #FFFF00);
}

Example

#grad1 {
  height: 100px;
  background-color: #bbb; /* For browsers that do not support gradients */
  background-image: linear-gradient(90deg, #bbb, #fff);
}

Example

#grad1 {
  height: 50px;
  background-color: blue; /* For browsers that do not support gradients */
  background-image: linear-gradient(to right, red, orange, yellow, green, blue, indigo, violet);
}
Rainbow Background

Example

#grad1 {
  height: 150px; width: 200px;
  background-color: red; /* For browsers that do not support gradients */
  background-image: radial-gradient(circle, red, orange, yellow, green, blue, indigo, violet);
}

Example

#grad1 {
  height: 150px; width: 200px;
  background-color: red; /* For browsers that do not support gradients */
  background-image: radial-gradient(circle, red 5%, yellow 15%, green 90%);
}

lifewire (2020): How to Create Linear Gradients in CSS3

.diversediv {
  background: #999999;
  background: -moz-linear-gradient(left, #999999 0%, #ffffff 100%);
  background: -webkit-gradient(linear, left top, right top, color-stop(0%,#999999), color-stop(100%,#ffffff));
  background: -webkit-linear-gradient(left, #999999 0%, #ffffff 100%);
  background: -o-linear-gradient(left, #999999 0%, #ffffff 100%);
  background: -ms-linear-gradient(left, #999999 0%, #ffffff 100%);
  filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#999999', endColorstr='#ffffff',GradientType=1 );
  -ms-filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#999999', endColorstr='#ffffff',GradientType=1 );
  background: linear-gradient(left, #999999 0%, #ffffff 100%); padding:16px;
}
- cross-browser
- linear-gradient
- med fin overgang
- som bakgrunn

CSS background-color

w3schools.com

h1 {
  background-color: green;
}

div {
  background-color: lightblue;
}

p {
  background-color: yellow;
}
<h1>CSS background-color example!</h1>
<div>
This is a text inside a div element.
<p>This paragraph has its own background color.</p>
We are still in the div element.
</div>

CSS background-color example!

This is a text inside a div element.

This paragraph has its own background color.

We are still in the div element.

Opacity / Transparency

w3schools.com

The opacity property specifies the opacity/transparency of an element. It can take a value from 0.0 - 1.0. The lower value, the more transparent:

Note: When using the opacity property to add transparency to the background of an element, all of its child elements inherit the same transparency. This can make the text inside a fully transparent element hard to read.

Example

div {
  background-color: green;
}

div.first {
  opacity: 0.1;
}

div.second {
  opacity: 0.3;
}

div.third {
  opacity: 0.6;
}

opacity 0.1

opacity 0.3

opacity 0.6

opacity 1 (default)


Transparency using RGBA

w3schools.com

If you do not want to apply opacity to child elements, like in our example above, use RGBA color values.

An RGBA color value is specified with: rgba(red, green, blue, alpha). The alpha parameter is a number between 0.0 (fully transparent) and 1.0 (fully opaque).

The following example sets the opacity for the background color and not the text:

Example

div {
  background: rgb(0, 128, 0);
}

div.first {
  background: rgba(0, 128, 0, 0.1);
}

div.second {
  background: rgba(0, 128, 0, 0.3);
}

div.third {
  background: rgba(0, 128, 0, 0.6);
}

10% opacity

30% opacity

60% opacity

opacity 1 (default)



BILDER

w3schools: HTML Images

HTML Images Syntax

The HTML <img> tag is used to embed an image in a web page.

Info (Fra: hiof.instructure.com:) Embed kalles på norsk innebygging. I praksis betyr det at du har en framviser, som viser fram videoen fra det stedet den er publisert - uten at den er lastet opp eller lagret på ditt nettsted.

Images are not technically inserted into a web page; images are linked to web pages. The <img> tag creates a holding space for the referenced image.

The HTML <img /> tag is empty, it contains attributes only, and does not have a closing tag.

The HTML <img> tag has two required attributes:

Syntax

 <img src="url" alt="alternatetext" />

The src Attribute

The required src attribute specifies the path (URL) to the image.

The alt Attribute

The required alt attribute provides an alternate text for an image, if the user for some reason cannot view it (because of slow connection, an error in the src attribute, or if the user uses a screen reader).

The value of the alt attribute should describe the image:

 <img src="img_chania.jpg" alt="Flowers in Chania" />

Image Size - Width and Height

 <img src="img_girl.jpg" alt="Girl in a jacket" width="500" height="600" />

The width and height attributes always define the width and height of the image in pixels.

Note: Always specify the width and height of an image. If width and height are not specified, the web page might flicker while the image loads.

Width and Height, or Style?

The width, height, and style attributes are all valid in HTML.

However, we suggest using the style attribute. It prevents styles sheets from changing the size of images:

CSS:

img {
  width: 100%;
}

PB: Modifisert

<img src="bilder/testing-bilde_asus.png" alt="Test-bilde" width="209" height="98">

The first image uses the width attribute, but the width: 100%; style in the head section overrides it, and sets the width to 100%.

Test-bilde
<img src="bilder/testing-bilde_asus.png" alt="Test-bilde" style="width: 209px; height: 98px;">

The second image uses the style attribute to set the width, this will not be overridden by the style width: 100%; in the head section.

Test-bilde

Image as a Link

To use an image as a link, put the <img /> tag inside the <a> tag:

<a href="default.asp">
  <img src="smiley.gif" alt="HTML tutorial" style="width:42px;height:42px;">
</a> 
Test-bilde stjerne

Image Floating

Use the CSS float property to let the image float to the right or to the left of a text:

Example - float: right;

img {
  float: right;
}
<img src="bilder/170x170-stjerner.jpg" alt="Test-bilde" style="width:170; height:170px; margin-left:15px; float:right;">

Test-bilde Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus imperdiet, nulla et dictum interdum, nisi lorem egestas odio, vitae scelerisque enim ligula venenatis dolor. Maecenas nisl est, ultrices nec congue eget, auctor vitae massa. Fusce luctus vestibulum augue ut aliquet. Mauris ante ligula, facilisis sed ornare eu, lobortis in odio. Praesent convallis urna a lacus interdum ut hendrerit risus congue. Nunc sagittis dictum nisi, sed ullamcorper ipsum dignissim ac. In at libero sed nunc venenatis imperdiet sed ornare turpis. Donec vitae dui eget tellus gravida venenatis. Integer fringilla congue eros non fermentum. Sed dapibus pulvinar nibh tempor porta. Cras ac leo purus. Mauris quis diam velit.

Example - float: left;

img {
  float: left;
}
<img src="bilder/170x170-stjerner.jpg" alt="Test-bilde" style="width:170; height:170px; margin-right:15px; float:left;">

Test-bilde Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus imperdiet, nulla et dictum interdum, nisi lorem egestas odio, vitae scelerisque enim ligula venenatis dolor. Maecenas nisl est, ultrices nec congue eget, auctor vitae massa. Fusce luctus vestibulum augue ut aliquet. Mauris ante ligula, facilisis sed ornare eu, lobortis in odio. Praesent convallis urna a lacus interdum ut hendrerit risus congue. Nunc sagittis dictum nisi, sed ullamcorper ipsum dignissim ac. In at libero sed nunc venenatis imperdiet sed ornare turpis. Donec vitae dui eget tellus gravida venenatis. Integer fringilla congue eros non fermentum. Sed dapibus pulvinar nibh tempor porta. Cras ac leo purus. Mauris quis diam velit.

Common Image Formats

Here are the most common image file types, which are supported in all browsers (Chrome, Edge, Firefox, Safari, Opera):

Abbreviation File Format File Extension
APNG Animated Portable Network Graphics .apng
GIF Graphics Interchange Format .gif
ICO Microsoft Icon .ico, .cur
JPEG Joint Photographic Expert Group image .jpg, .jpeg, .jfif, .pjpeg, .pjp
PNG Portable Network Graphics .png
SVG Scalable Vector Graphics .svg

Attribute order

HTML attributes should come in this particular order for easier reading of code.

PB: Dette er hentet fra generelt bruk (https://codeguide.co/)

<a class="..." id="..." data-toggle="modal" href="#">
  Example link
</a>

<input class="form-control" type="text">

<img src="..." alt="...">

MAX-WIDTH

developer.mozilla.org: Sizing items in CSS

https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Sizing_items_in_CSS

A common use of max-width is to cause images to scale down if there is not enough space to display them at their intrinsic width while making sure they don't become larger than that width.

As an example, if you were to set width: 100% on an image, and its intrinsic width was smaller than its container, the image would be forced to stretch and become larger, causing it to look pixelated.

If you instead use max-width: 100%, the image is able to become smaller than its intrinsic size, but will stop at 100% of its size.

...This will enable the image to become smaller in size than the box but not larger.

Veranda med gamle farger, vinduer og dør (2018)

How to Align and Float Images with CSS

https://www.inmotionhosting.com/support/edu/website-design/align-float-images-css/

Aligned images do not wrap text around them. Aligning images will only position the image left, right, or center with the text following before and after the image. Aligning leaves quite a bit of white space on your site. You will see the white space when you go though the aligning section.

A floated image will allow the text to wrap around the image like a regular book or newspaper would do. Images can also be floated so they appear horizontally on your site. This is good for displaying images like a gallery. The following sections will explain how to float and align images using CSS.

Left Align

<div style="text-align: left;">
<img src="bilder/testing-bilde_asus.png" width="100" />
</div>
The line of code is for aligning an image to the left (text-align: left;). Jeg satte denne teksten rett etter bildet.

Center Align

<div style="text-align: center;">
<img src="bilder/testing-bilde_asus.png" width="100" />
</div>
The following line of code is for centering an image. (text-align: center;). Jeg satte denne teksten rett etter bildet.

Right Align

<div style="text-align: right">
<img src="bilder/testing-bilde_asus.png" width="100" />

The following line of code contains the CSS attribute for aligning right. Jeg satte denne teksten rett etter bildet.

Floating Images Using CSS

Floating images allows images to horizontally align with each other and allows text to wrap around the image. The following will explain horizontally aligning images and floating images around text.

Floating Images Left to Wrap Text

<img style="float: left; margin: 0px 15px 15px 0px;" src="bilder/testing-bilde_asus.png" width="100" />
<p><strong>Important!</strong> Floated image...
Below is the code to clear your floats.</p>
<br style="clear:both" />

Important! Floated images will overlap each other if the float is not cleared. Make sure you are placing a clear float code after each section your image is floating in. Below is the code to clear your floats.


Floating Images Right to Wrap Text

<img style="float: right; margin: 0px 0px 15px 15px;" src="bilder/testing-bilde_asus.png" width="100" />
<br style="clear:both" />

Important! Floated images will overlap each other if the float is not cleared. Make sure you are placing a clear float code after each section your image is floating in. Below is the code to clear your floats.


Floating Images Left Horizontally

Test-bilde Test-bilde Test-bilde Test-bilde Her er bildene satt ett og ett på linje, også her med clear:both rett etter (denne teksten).


lifewire.com (2019): How to Wrap Text Around an Image

<img src="sti/til/bildet.jpg" style="stilsett" alt="beskrivelse av bildet" class="stilsett" />
.left {
 float: left;
 padding: 0 20px 20px 0;
}
<img src="/images/team-photo.jpg" alt="A photo of our employees" class="left" />

PB: Jeg har forandret padding, slik at bildet ikke forskyver seg over kanten av teksten, men ligger mer på linje med topp-teksten. i tillegg, en ClearFix i slutten.

A photo of our employees

What you did here is use the CSS "float" property, which will pull the image from normal document flow (the way that image would normally display, with the text aligned beneath it) and it will align it to the left side of its container. The text that comes after it in the HTML markup with now wrap around it. We also added some padding values so that this text would not but directly up against the image. Instead, it will have some nice spacing that will be visually attractive in the page's design. In the CSS shorthand for padding, we added 0 values to the top and left side of the image, and 20 pixels to its left and bottom. Remember, you need to add some padding to the right side of a left-aligned image. A right aligned image (which we will look at in a moment) would have padding applied to its left side.

<div style='content: ""; clear: both; display: table;' /></div>

alt

Use the alt text to give additional details about the image that are not relevant or important to the text of the web page. But, remember that in screen readers and other text-only browsers, the text will be read inline with the rest of the text on the page. To avoid confusion, use descriptive alt text that says (for example), “About Web Design and HTML” instead of just “logo.”

The alt text is also essential for SEO(Search Engine Optimization). The bots that search engines, like Google, use to explore the content on sites can't "see" images. They rely on the alt text to determine what's on the page.

In HTML5, the alt attribute is not always required, because you can use a caption to add more description to it. You can also use this attribute to indicate an ID that contains a full description:

Use Blank Alt Text Only for Icons and Bullets

aria-describedby="Description of image"

... the size of the image

...Remember to exclude any visual characteristics (like width and height values) from that HTML. This is important, especially for a responsive website where the image size will vary based on the browser.

...if you have a responsive website whose sizing changes based on a visitors screen and device size, you will also want your images to be flexible. If you state in your HTML what the fixed size is, you will find it very hard to override with responsive CSS media queries.

For this reason, and to maintain a separation of style (CSS) and structure (HTML), it is recommended that you do NOT add width and height attributes to your HTML code.

One note: If you do leave these sizing instructions off and do not specify a size in CSS, the browser will show the image at its default size anyway.


The CSS float property and clearing

https://flaviocopes.com/css-floating-clearing/

.parent {
  background-color: #af47ff;
  padding: 30px;
  width: 500px;
}

.child {
  background-color: #ff4797;
  padding: 30px;
}

.box {
  background-color: #f3ff47;
  padding: 30px;
  border: 2px solid #333;
  border-style: dotted;
  font-family: courier;
  text-align: justify;
  font-size: 1rem;
}

.span {
  float: right;
  margin: 20px 0px 20px 20px;
  padding: 10px;
  border: 1px solid black
}
<div class="parent">
  <div class="child">
    <div class="box">
      <p>This is some random paragraph and an image. 
	  <span>Some text to float</span> 
	  The image is in the middle of the text. 
	  The image is in the middle of the text. 
	  The image is in the middle of the text. 
	  The image is in the middle of the text. 
	  The image is in the middle of the text. 
	  The image is in the middle of the text. 
	  The image is in the middle of the text. 
	  The image is in the middle of the text. 
	  The image is in the middle of the text.
      </p>
    </div>
  </div>
</div>

This is some random paragraph and an image (eller også SPAN). Some text to float The image is in the middle of the text. The image is in the middle of the text. The image is in the middle of the text. The image is in the middle of the text. The image is in the middle of the text. The image is in the middle of the text. The image is in the middle of the text. The image is in the middle of the text. The image is in the middle of the text.

PB: Har laget et FAKE, DUMMY, DEMO, IMAGE eller IMG-bilde med DIVs, her eksemplifisert med 100x100 størrelse.

Trikset med sentrert tekst plassert i midten gjøres her med line-height: 100px; = høyden på DIV, selv om det anbefales andre løsninger som er sikrere å bruke (men mye mer knot å få til å fungere inline når de presenteres som fullscreen).

<div style="
 background-color: #eee;
 text-align: center;
 width: 100px;
 height: 100px;
 line-height: 100px;">
 100x100</div></div>
100x100

PB: Tror at følgende muligens er safe, som i alle fall anbefales fremfor den over. Men denne fungerer ikke som flere forskjellige enheter som skal simulere bilder, slik den over gjør.

<div style="
 text-align:center;
 border:1px solid silver;
 display: table-cell;
 vertical-align:middle;
 width:100px;
 height:100px;">
 100x100</div></div>
100x100

Eksempler

<div class="boks">

<p>This is some random paragraph and an image. The 

<div class="img" style="width: 100px; height: 100px;
 line-height: 100px;">100x100</div>

<div class="img" style="width: 100px; height: 50px;
 line-height: 50px;">100x50</div>

<div class="img" style="width: 80px; height: 100px;
 line-height: 100px;">80x100</div>

     image is in the middle of the text.
 The image is in the middle of the text. 
 The image is in the middle of the text.
 The image is in the middle of the text. 
 The image is in the middle of the text.
 The image is in the middle of the text. 
 The image is in the middle of the text.
 The image is in the middle of the text. 
 The image is in the middle of the text.
 </p>
</div>
.boks {
 background-color: #ecffec;
 width: 500px;
 padding: 26px;
 border: 2px solid #ccc;
 border-style: dotted;
 font-family: courier;
 text-align: justify;
 font-size: 1rem;
}

PB: Jeg har lagt inn clear: none; kun for å vise at dette kan brukes, men den har ingen effekt på eksemplene nedenfor. I tillegg testet jeg float: right; mot clear: left; og motsatt. Fungerer som clear: none;.

float: right; og clear: none; på IMG

.img {
 float: right;
 margin: 0px 0px 0px 20px;
 clear: none;
}

This is some random paragraph and an image. The

100x100
100x50
80x100
image is in the middle of the text. The image is in the middle of the text. The image is in the middle of the text. The image is in the middle of the text. The image is in the middle of the text. The image is in the middle of the text. The image is in the middle of the text. The image is in the middle of the text. The image is in the middle of the text.

float: left; og clear: none; på IMG

.img {
 float: left;
 margin: 0px 20px 0px 0px;
 clear: none;
}

This is some random paragraph and an image. The

100x100
100x50
80x100
image is in the middle of the text. The image is in the middle of the text. The image is in the middle of the text. The image is in the middle of the text. The image is in the middle of the text. The image is in the middle of the text. The image is in the middle of the text. The image is in the middle of the text. The image is in the middle of the text.

float: right; og clear: right; på IMG

.img {
 float: right;
 margin: 0px 0px 20px 20px;
 clear: right;
}

PB: Her med <div style='content: ""; clear: both; display: table;'></div> etter </P> tag.

This is some random paragraph and an image. The

100x100
100x50
80x100
image is in the middle of the text. The image is in the middle of the text. The image is in the middle of the text. The image is in the middle of the text. The image is in the middle of the text. The image is in the middle of the text. The image is in the middle of the text. The image is in the middle of the text. The image is in the middle of the text.

float: left; og clear: left; på IMG

.img {
 float: left;
 margin: 0px 0px 20px 20px;
 clear: left;
}

PB: Her med <div style='content: ""; clear: both; display: table;'></div> etter </P> tag.

This is some random paragraph and an image. The

100x100
100x50
80x100
image is in the middle of the text. The image is in the middle of the text. The image is in the middle of the text. The image is in the middle of the text. The image is in the middle of the text. The image is in the middle of the text. The image is in the middle of the text. The image is in the middle of the text. The image is in the middle of the text.


w3schools: CSS Text Alignment

https://www.w3schools.com/css/css_text_align.asp

Vertical Alignment

Definition and Usage

The vertical-align property sets the vertical alignment of an element.

This example demonstrates how to set the vertical alignment of an image in a text:

Default

An W3Schools image with a default alignment.

Top

img.top {
  vertical-align: top;
}

An W3Schools image with a top alignment.

Middle

img.middle {
  vertical-align: middle;
}

An W3Schools image with a middle alignment.

Bottom

img.bottom {
  vertical-align: bottom;
}

An W3Schools image with a bottom alignment.


INNRAMMING

Ramme-radius 8px

PB: Bruker kantlinjer til å lage rammer rundt bildene.

<img src="bilder/170x170-stjerner.jpg" 
alt="Test-bilde" 
style="width:170px; height:170px; 
border-radius: 8px;">
Test-bilde

Ramme-radius 25%

<img src="bilder/170x170-stjerner.jpg" 
alt="Test-bilde" 
style="width:170px; height:170px; 
border-radius: 25%;">
Test-bilde

50% Hvis bildet er kvadratisk, sirkelrund ramme

<img src="bilder/170x170-stjerner.jpg" 
alt="Test-bilde" 
style="width:170px; height:170px; 
border-radius: 50%;">
Test-bilde

50% Hvis bildet er rektangulært, ovalformet ramme

<img src="bilder/testing-bilde_asus.png" 
alt="Test-bilde" 
style="width:209px; height:98px; 
border-radius: 50%;">
Test-bilde

Border-ramme

<img src="bilder/170x170-stjerner.jpg" 
alt="Test-bilde" 
style="background-color: #555; width:170px; height:170px; 
border: 5px solid #555;">
Test-bilde
img {
 border-style:solid;
 border-color:lightblue;
 border-width:15px;
 border-radius:50%;
}
Test-bilde

Thumb-nails

img {
  border: 1px solid #ddd;
  border-radius: 4px;
  padding: 5px;
  width: 150px;
}

img:hover {
  box-shadow: 0 0 2px 1px rgba(0, 140, 186, 0.5);
}
Test-bilde Test-bilde

Skygge h.s. ned

img {
 box-shadow:20px 10px 5px black;
]
Test-bilde

Skygge v.s. ned

img {
 box-shadow:-20px 10px 0 indigo;
]
Test-bilde

Skygge glød

img {
 box-shadow:0px 0px 20px #68201d;
]
Test-bilde

The Figure Element

28 HTML5 Features, Tips, and Techniques you Must Know

Fra: code.tutsplus.com

Consider the following mark-up for an image:

<img src="path/to/image" alt="About image" />
<p>Image of Mars.</p>
About image

Skjermbilde av ASUS logoen.

There unfortunately isn't any easy or semantic way to associate the caption, wrapped in a paragraph tag, with the image element itself. HTML5 rectifies this, with the introduction of the <figure> element. When combined with the <figcaption> element, we can now semantically associate captions with their image counterparts.

<figure>
  <img src="path/to/image" alt="About image" />
    <figcaption>
      <p>This is an image of something interesting.</p>
  </figcaption>
</figure>
About image

Skjermbilde av ASUS logoen.


Responsive images

Fra (https://polypane.app/responsive-design-glossary/#responsive-images)

For a sharp picture on a desktop you need a much larger image than on a mobile phone. If you just add images for the desktop size, your mobile users will end up downloading large images, wasting their bandwidth and slowing your site down. With responsive images, you can offer a set of images at different sizes and quality (and even content), and the browser will decide which is the best to show to the user.

You can do this by using the srcset and sizes attribute on an <img> element, or by using the <picture> element and adding <source> elements to it. With this, you can vary the size of images you send, the pixel density (so mobile phones with sharper screens get sharper images), the type of image (you can send a webp to browsers that support it, and a jpg to browsers that don't) or even do art direction, where on smaller screens you zoom in to a specific part of the image.

SJEKK OGSÅ: https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Responsive_images

FORELØPIG lagt på is, da jeg ikke har mange store bilder i bruk.


CARDS

w3schools: Responsive Polaroid Images / Cards

div.polaroid {
  width: 80%;
  background-color: white;
  box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
  margin-bottom: 25px;
}

div.container {
  text-align: center;
  padding: 10px 20px;
}
<div class="polaroid">
  <img src="img_5terre.jpg" alt="5 Terre" style="width:100%">
  <div class="container">
  <p>Cinque Terre</p>
  </div>
</div>

<div class="polaroid">
  <img src="lights600x400.jpg" alt="Norther Lights" style="width:100%">
  <div class="container">
  <p>Northern Lights</p>
  </div>
</div>
Morgan forsterkeren

Cinque Terre

Skap smiley

Northern Lights

w3schools: Responsive Column Cards

PB: Sliter med å få denne inline, men egen CLASS på * fungerer.

* {
  box-sizing: border-box;
}

/* Float four columns side by side */
.column {
  float: left;
  width: 25%;
  padding: 0 10px;
}

/* Remove extra left and right margins, due to padding */
.row {margin: 0 -5px;}

/* Clear floats after the columns */
.row:after {
  content: "";
  display: table;
  clear: both;
}

/* Responsive columns */
@media screen and (max-width: 600px) {
  .column {
    width: 100%;
    display: block;
    margin-bottom: 20px;
  }
}

/* Style the counter cards */
.card {
  box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
  padding: 16px;
  text-align: center;
  background-color: #f1f1f1;
}
<div class="row">
  <div class="column">
    <div class="card">
      <h3>Card 1</h3>
      <p>Some text</p>
      <p>Some text</p>
    </div>
  </div>

  <div class="column">
    <div class="card">
      <h3>Card 2</h3>
      <p>Some text</p>
      <p>Some text</p>
    </div>
  </div>
  
  <div class="column">
    <div class="card">
      <h3>Card 3</h3>
      <p>Some text</p>
      <p>Some text</p>
    </div>
  </div>
  
  <div class="column">
    <div class="card">
      <h3>Card 4</h3>
      <p>Some text</p>
      <p>Some text</p>
    </div>
  </div>
</div>

https://www.tutorialspoint.com/how-to-create-responsive-column-cards-with-css

* {
  box-sizing: border-box;
}

.card {
  color: white;
  float: left;
  width: calc(25% - 20px);
  padding: 10px;
  border-radius: 10px;
  margin: 10px;
  height: 200px;
}

.card p {
  font-size: 18px;
}

.cardContainer:after {
  content: "";
  display: table;
  clear: both;
}

@media screen and (max-width: 600px) {
.card {
  width: 100%;
  }
}
<h2>Resize the screen to see the below cards resize themselves</h2>
<div class="cardContainer">
<div class="card" style="background-color:rgb(153, 29, 224);">
<h2>First card</h2>
<p>Some text</p>
</div>
<div class="card" style="background-color:rgb(12, 126, 120);">
<h2>Second card</h2>
<p>Some text</p>
</div>
<div class="card" style="background-color:rgb(207, 41, 91);">
<h2>Third card</h2>
<p>Some text</p>
</div>
<div class="card" style="background-color:rgb(204, 91, 39);">
<h2>Fourth card</h2>
<p>Some text</p>
</div>
</div>


BORDERS

CSS - Borders

Fra tutorialspoint.com

The border-color Property

PB: Modifisert.

p.example1 {
  border:10px solid;
  border-bottom-color:#009900; /* Green */
  border-top-color:#FF0000;    /* Red */
  border-left-color:#330000;   /* Black */
  border-right-color:#0000CC;  /* Blue */
}

This example is showing all borders in different colors.

p.example2 {
  border:10px solid #009900;
}

This example is showing all borders in green color only.

The border-style Property

border-width:8px; border-style:none;

border-width:8px; border-style:solid;

border-width:8px; border-style:dashed;

border-width:8px; border-style:double;

border-width:8px; border-style:groove;

border-width:8px; border-style:ridge;

border-width:8px; border-style:inset;

border-width:8px; border-style:outset;

border-width:8px; border-style:hidden;

border-width:8px; border-top-style:solid; border-bottom-style:dashed; border-left-style:groove; border-right-style:double;

The border-width Property

border-width:1px; border-style:solid;

border-width:8pt; border-style:solid;

border-width:thin; border-style:solid;

border-width:medium; border-style:solid;

border-width:thick; border-style:solid;

border-bottom-width:4px;border-top-width:10px; border-left-width: 2px;border-right-width:15px;border-style:solid;


Shorthand

Fra developer.mozilla.org

The 1-value syntax: border-width: 1em — The unique value represents all edges
The 2-value syntax: border-width: 1em 2em — The first value represents the vertical, that is top and bottom, edges, the second the horizontal ones, that is the left and right ones.
The 3-value syntax: border-width: 1em 2em 3em — The first value represents the top edge, the second, the horizontal, that is left and right, ones, and the third value the bottom edge

The 4-value syntax: border-width: 1em 2em 3em 4em — The four values represent the top, right, bottom and left edges respectively, always in that order, that is clock-wise starting at the top (The initial letter of Top-Right-Bottom-Left matches the order of the consonant of the word trouble: TRBL) (You can also remember it as the order that the hands would rotate on a clock: 1em starts in the 12 o'clock position, then 2em in the 3 o'clock position, then 3em in the 6 o'clock position, and 4em in the 9 o'clock position).


Border

tagindex.net

Sets all border properties

div {
border: thick red solid;
}

p {
border-top: 2px #85b9e9 solid;
border-right: 4px #bde9ba double;
border-bottom: 6px #ffd37d dotted;
border-left: 8px #d1d1d1 dashed;
}
DIV = border: thick red solid;

P =
border-top: 2px #85b9e9 solid;
border-right: 4px #bde9ba double;
border-bottom: 6px #ffd37d dotted;
border-left: 8px #d1d1d1 dashed;

Image border

#example { border: 5px orange solid; }
<p><img src="image/photo.jpg" alt="Example" width="200" height="133" id="example"></p>

GAP MELLOM BILDET OG BORDER

PB: Modifisert, samt fant en FIX (samme bakgrunnsfarge!) for å bli kvitt et lite hvitt gap mellom bildet og rammen laget av kantlinje.

<div style=""><img src="bilder/testing-bilde_asus.png" alt="Asus-logo" 
style="border: 5px orange solid; background-color: orange;"></div>
Asus-logo

Spacing between the borders

table {
border: 2px #2b2b2b solid;
border-collapse: separate;
width: 250px;
margin-bottom: 20px;
}
td, th {
border: 2px #2b2b2b solid;
}

#example1 {
border-spacing: 5px;
}
#example2 {
border-spacing: 30px 5px;
}
<table id="example1">
<tr>
<th colspan="2">[The spacing on all sides:5px]</th>
</tr>
<tr>
<td>Cell A</td>
<td>Cell B</td>
</tr>
</table>
[The spacing on all sides:5px]
Cell A Cell B
<table id="example2">
<tr>
<th colspan="2">[left,right:30px] [top,bottom:5px]</th>
</tr>
<tr>
<td>Cell A</td>
<td>Cell B</td>
</tr>
</table>
[left,right:30px] [top,bottom:5px]
Cell A Cell B

Hvordan style borders i CSS

Border-egenskapen i CSS lar deg sette en ramme eller kant rundt et element. Det finnes mange varianter å eksperimentere med. Du kan sette border-style til solid, dotted, inset og så videre. Du har border-width hvor du kan bestemme tykkelsen på rammen. Du har border-color hvor du kan sette fargen på rammen. Du kan også sette stil, tykkelse og farge på en enkelt side med for eksempel border-bottom-style eller border-right-color. I tillegg har vi noe som heter border-radius hvor du kan definere avrundede hjørner. Her er noen eksempler som du kan se på.

PB: Modifisert. Det var ingen HTML-eksempler vedlagt. Border kalles generelt sett heller kantlinjer fremfor rammer.

Legg inn følgende kode på ul-regelen i CSS-filen.

border-style: dashed;
border-width: 3px;
border-color: #0f0;

Det er mulig å slå sammen disse tre egenskapene til en ved å skrive følgende. Legg koden inn i li-regelen i CSS-filen.

border: solid 3px #00f;

Legg inn border-radius på li-regelen også og se hva som skjer.

border-radius: 6px;

Egne tester og eksempler, P

border-style: dotted; (1)

border-style: dotted solid; (2)

border-style: dotted solid double; (3)

border-style: dotted solid double dashed; (4)

border: 2px solid #444;

border-top: 5px solid #444;

border-right: 23px solid #444;

border-bottom: 5px solid #444;

border-left: 23px solid #444;

.to-og-to-tykke-farger { border-width: 20px 20px; border-style: solid; border-color: blue #0f0; }

.bakgrunn-v-og-h-a { border-width: 20px 60px; border-style: solid; border-color: blue #87CEFA; }

.bakgrunn-v-og-h-b { border: 60px solid green; border-top: 20px solid red; border-bottom: 20px solid red; }

.tynn-m-tykk-farget-v-og-h-a { border-width: 1px 20px; border-style: solid; border-color: blue #0f0; }

.tynn-m-tykk-farget-v-og-h-b { border: 1px solid green; border-right: 12px solid red; border-left: 12px solid red; }

.tynn-m-tykk-farget-venstre-a { border-width: 1px 1px 1px 20px; border-style: solid; border-color: blue blue blue #0f0; }

.tynn-m-tykk-farget-venstre-b { border: 1px solid green; border-left: 12px solid red; }

.kun-right-og-farge-a { border-style: solid; border-right-width: 20px; border-color: blue; }

.kun-right-og-farge-b { border: 1px solid green; border-right: 12px solid red; }

.farger-1-stykk { border-style: dotted; border-color: blue; }

.farger-2-stykk { border-style: dotted; border-color: blue violet; }

.farger-3-stykk { border-style: dotted; border-color: blue violet green; }

.farger-4-stykk { border-style: dotted; border-color: blue violet green red; }

.farger-tykkelser-forskjellig { border-top: solid blue 10px; border-right: solid violet 8px; border-bottom: solid green 6px; border-left: solid red 4px; }

.alle-forskjellige { border-width: 1px 30px .5em 20px; border-style: solid dotted inset double; border-color: #f0f #0f0 #0ff #ff0; }

.bruk-av-none { border: 12px #000; border-style: none solid none solid; }

.kun-bunn-satt { border-style: solid; border-bottom-width: 15px; }

.tynn-kun-bunn-satt { border: 1px solid black; border-bottom-width: 15px; }

.left-right--forskjellige { border-left: 30px solid #800000; border-right: 80px solid #006400; }

.tykk-dobbel { border: thick double #32a1ce; }

.tykk-dobbel-topp { border-style: solid; border-top: thick double #32a1ce; }

.tykk-dobbel-v { border-style: double; border-left-width: 15px; border-color: #32a1ce; }

.radius-1-stykk { border:2px solid DodgerBlue; border-radius: 12px; }

.radius-2-stykk { border:2px solid rgb(255, 99, 71); border-radius: 26px 12px; }

.radius-3-stykk { border:2px solid rgb(60, 179, 113); border-radius: 42px 26px 12px; }

.radius-4-stykk { border:2px solid rgb(77, 77, 77); border-radius: 56px 42px 26px 12px; }

.border-top-left-radius { border:2px solid #7c0085; border-top-left-radius: 26px; }

.border-top-right-radius { border:2px solid #7c0085; border-top-right-radius: 26px; }

.border-bottom-right-radius { border:2px solid #7c0085; border-bottom-right-radius: 26px; }

.border-bottom-left-radius { border:2px solid #7c0085; border-bottom-left-radius: 26px; }

.full-pakke--gray { background-color:#708090; color:white; padding:20px; border: 1px solid #304050; border-left-width: 34px; border-left-color: #405060; border-radius: 0 32px 32px 0; }


Border margin and padding

Bare margin

Dette er en H2 overskrift

Disse har: margin: 26px; padding: 0;

Bare padding

Dette er en H2 overskrift

Disse har: margin: 0; padding: 26px;

Både margin og padding

Dette er en H2 overskrift

Disse har: margin: 26px; padding: 10px;


w3schools: How TO - Circles

https://www.w3schools.com/howto/howto_css_circles.asp

.dot {
  height: 25px;
  width: 25px;
  background-color: #bbb;
  border-radius: 50%;
  display: inline-block;
}
<span class="dot"></span>
<span class="dot"></span>
<span class="dot"></span>
<span class="dot"></span> 

PB: Modifisert


CSS - Outlines

https://www.tutorialspoint.com/css/css_outlines.htm

Outlines are very similar to borders, but there are few major differences as well −

NOTE − The outline properties are not supported by IE 6 or Netscape 7.

You can set the following outline properties using CSS.

The outline-width Property

The outline-width property specifies the width of the outline to be added to the box. Its value should be a length or one of the values thin, medium, or thick, just like the border-width attribute.

A width of zero pixels means no outline.

The outline-style Property

The outline-style property specifies the style for the line (solid, dotted, or dashed) that goes around an element. It can take one of the following values −

Fra developer.mozilla.org

background-color: #ffd955;
outline: 8px ridge rgba(170, 50, 220, .6);
border-radius: 2rem;
This is a box with an outline around it.
div {
  border: 0.5rem outset pink;
  outline: 0.5rem solid khaki;
  box-shadow: 0 0 0 2rem skyblue;
  border-radius: 12px;
  font: bold 1rem sans-serif;
  margin: 2rem;
  padding: 1rem;
  outline-offset: 0.5rem;
}
I have a border, an outline, and a box shadow! Amazing, isn't it?

Eksempler fra w3schools, andre og egne

CSS has the following outline properties:

Note: Outline differs from borders! Unlike border, the outline is drawn outside the element's border, and may overlap other content. Also, the outline is NOT a part of the element's dimensions; the element's total width and height is not affected by the width of the outline.

Warning: None of the other outline properties will have ANY effect unless the outline-style property is set!

p {
  border: 2px solid black;
  outline: #4CAF50 solid 10px;
  margin: auto;  
  padding: 20px;
  text-align: center;
}

This element has a 2px black border and a green outline with a width of 10px.

p {
  margin: 30px;
  background:yellow;
  border: 1px solid black;
  outline: 1px solid red;
  outline-offset: 15px;
}

This paragraph has an outline of 15px outside the border edge.

Fra stackoverflow.com (forum)

PB: (2020) Ikke mulig å sette rounded corners på outlines. Kom over en måte å lage fake på, med BOX-SHADOW:

div {
  background: #999;
  height: 100px;
  width: 200px;
  border: #999 solid 1px;
  border-radius: 10px;
  margin: 15px;
  box-shadow: 0px 0px 0px 1px #fff inset;
}
.myElement {
  border: 2px solid #0064D2;
  border-radius: 3px;
  box-shadow: 0 0 0 2px #0099f8;
}
Hello World

How to Create Multiple Borders in CSS3

https://blogs.sitepointstatic.com/examples/tech/css3-multiple-borders/index.html

p {
box-shadow: 
	0 0 0 2px #000,
	0 0 0 3px #999,
	0 0 0 9px #fa0,
	0 0 0 10px #666,
	0 0 0 16px #fd0,
	0 0 0 18px #000,
	0 2px 6px 18px rgba(0,0,0,0.5);
}

Multiple Borders using shadows.

LAGET MED ET NETTBASERT SKYGGE og STYLING KIT

https://css3.mikeplate.com/

.element { text-shadow: 3px 3px 5px #888; border: 1px solid #000000; background-color: #CCDDCC; padding: 12px; font-family: Palatino, 'Palatino Linotype', 'Palatino LT STD', 'Book Antiqua', Georgia, serif; font-size: 12pt; color: #040; outline: 3px solid #007700; outline-offset: 3px; }



BOX-SIZING

box-sizing med CSS

https://www.qross.no/blogg/box-sizing-med-css/

Når vi designer nettsider med CSS må vi forholde oss til måten størrelsen på elementer beregnes. Det er ikke så enkelt som at bredden/høyden man setter er den plassen elementet krever på skjermen.

.top {
 width: 200px;
 margin: 10px;
 padding: 10px;
 border: 1px solid #ccc;
}
Header

Som vi ser av dette eksempelet så blir bredden på selve boksen 222px. Dette skyldes at padding (10px+10px) + border (1px+1px) legges til bredden. I tillegg krever margen 10px på hver side, slik at den totale plassen som opptas på skjermen er 242px.

I en responsiv layout vil dette by på utfordringer, da vi setter width i prosent. Resultatet blir at størrelsen blir en kombinasjon av prosent og pixler og vi mister kontrollen. La oss si du skal ha to kolonner på 50% og du legger til 10px padding. Hva blir da resultatet? 50%+10px+10px+50%+10px+10px=?

Løsning: box-sizing: border-box

Ved å bruke box-sizing: border-box endrer vi måten størrelsen beregnes på. Her utelates padding og border fra beregningen (disse verdiene «spiser» heller av width), noe som gjør det enklere å legge til padding og border i pixler, på elementer som har en bredde i prosent.

box-sizing: border-box

.top {
 box-sizing: border-box;
 width: 200px;
 margin: 10px;
 padding: 10px;
 border: 1px solid #ccc;
}
Header

Her har vi nøyaktig samme kode som over, med unntak av box-sizing. I resultatet ser vi at bredden er 200px (det vi har satt som width). Padding og border regnes altså ikke med i bredden slik det gjorde i første eksempel.

Konklusjon

På en responsiv nettside vil box-sizing: border-box gjør det mulig å definere padding og border, uten å bekymre seg for at dette påvirker størrelsen og plasseringen av elementer.

.top {
 box-sizing: border-box;
 width: 90%;
 padding: 10px;
 border: 1px solid #ccc;
}
Header

Det finnes alternative metoder når du jobber med en responsiv side, for eksempel kan du velge å sette margin og padding på innholdet (h1, h2, p, img osv), istedenfor på elementet innholdet er plassert i. Da påvirkes ikke størrelsen på boksen, da verdiene legges på elementer på innsiden. Men, dette kan fort være en mer krevende oppgave, så box-sizing vil sannsynligvis gjøre jobben enklere for deg.


CSS Box Sizing

https://www.w3schools.com/css/css3_box-sizing.asp

The CSS box-sizing property allows us to include the padding and border in an element's total width and height.

Without the CSS box-sizing Property

By default, the width and height of an element is calculated like this:

width + padding + border = actual width of an element
height + padding + border = actual height of an element

This means: When you set the width/height of an element, the element often appears bigger than you have set (because the element's border and padding are added to the element's specified width/height).

The following illustration shows two <div> elements with the same specified width and height:

.div1 {
  width: 300px;
  height: 100px;
  border: 1px solid blue;
}

.div2 {
  width: 300px;
  height: 100px;
  padding: 50px;
  border: 1px solid red;
}
<div class="div1">This div is smaller (width is 300px and height is 100px).</div>
<br>
<div class="div2">This div is bigger (width is also 300px and height is 100px).</div>
This div is smaller (width is 300px and height is 100px).

This div is bigger (width is also 300px and height is 100px).

With the CSS box-sizing Property

The box-sizing property allows us to include the padding and border in an element's total width and height.

If you set box-sizing: border-box; on an element, padding and border are included in the width and height:

.div1 {
  width: 300px;
  height: 100px;
  border: 1px solid blue;
  box-sizing: border-box;
}

.div2 {
  width: 300px;
  height: 100px;
  padding: 50px;
  border: 1px solid red;
  box-sizing: border-box;
}
<div class="div1">Both divs are the same size now!</div>
<br>
<div class="div2">Hooray!</div>
Both divs are the same size now!

Hooray!


CLEAR

clears float

tagindex.net

Property Value Explanation
clear left clears the left (for left floating box)
right clears the right (for right floating box)
both clears the both (for left or right floating box)
none it doesn't clear (default)

Example Box

#example {
width: 100%;
}

#box {
width: 40%;
height: 150px;
background-color: #85b9e9;
float: left;
}

.clear {
clear: left;
}
<div id="example">

<div id="box">The box floats to the left</div>
<p>The text wraps to the right of the box.</p>
<p>This is example text.</p>
<p class="clear">--- Clears the left float ---</p>

</div>
LEGG UT EX HER....
The box floats to the left

The text wraps to the right of the box.

This is example text.

--- Clears the left float ---

Example Image

#example { width: 100%; }
#example img { float: left; }

.clear { clear: left; }
Example

The text wraps to the right of the image.

This is example text.

--- Clears the left float ---

LEGG UT EX HER....og kanskje snu på dette, til et RIGHT eksempel...
Example

The text wraps to the right of the image.

This is example text.

--- Clears the left float ---

PB: Denne har også tilsvarende eksempler med TABLE og IFRAME


w3schools: CSS Layout - clear and clearfix

The clear Property

The clear property specifies what elements can float beside the cleared element and on which side.

The clear property can have one of the following values:

The most common way to use the clear property is after you have used a float property on an element.

When clearing floats, you should match the clear to the float: If an element is floated to the left, then you should clear to the left. Your floated element will continue to float, but the cleared element will appear below it on the web page.

The following example clears the float to the left. Means that no floating elements are allowed on the left side (of the div):

.div1 {
  float: left;
  width: 100px;
  height: 50px;
  margin: 10px;
  border: 3px solid #73AD21;
}

.div2 {
  border: 1px solid red;
}
<h2>Without clear</h2>
<div class="div1">div1</div>
<div class="div2">div2 - Notice that div2 is after div1 in the HTML code. 
However, since div1 floats to the left, the text in div2 flows around div1.</div>

Without clear

div1
div2 - Notice that div2 is after div1 in the HTML code. However, since div1 floats to the left, the text in div2 flows around div1.
.div3 {
  float: left;
  width: 100px;
  height: 50px;
  margin: 10px;
  border: 3px solid #73AD21;
}

.div4 {
  border: 1px solid red;
  clear: left;
}
<h2>With clear</h2>
<div class="div3">div3</div>
<div class="div4">div4 - Here, clear: left; moves div4 down below the floating div3. 
The value "left" clears elements floated to the left. You can also clear "right" and "both".</div>

With clear

div3
div4 - Here, clear: left; moves div4 down below the floating div3. The value "left" clears elements floated to the left. You can also clear "right" and "both".

The clearfix Hack

If an element is taller than the element containing it, and it is floated, it will "overflow" outside of its container.

Then we can add overflow: auto; to the containing element to fix this problem:

div {
  border: 3px solid #4CAF50;
  padding: 5px;
}

.img1 {
  float: right;
}
<p>In this example, the image is taller than the element containing it, 
and it is floated, so it overflows outside of its container:</p>

<div>
<img class="img1" src="pineapple.jpg" alt="Pineapple" width="170" height="170">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
Phasellus imperdiet, nulla et dictum interdum...
</div>

In this example, the image is taller than the element containing it, and it is floated, so it overflows outside of its container:

Test-bilde Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus imperdiet, nulla et dictum interdum...
div {
  border: 3px solid #4CAF50;
  padding: 5px;
}

.clearfix {
  overflow: auto;
}

.img2 {
  float: right;
}
<p style="clear:right">Add a clearfix class with overflow: auto; 
to the containing element, to fix this problem:</p>

<div class="clearfix">
<img class="img2" src="pineapple.jpg" alt="Pineapple" width="170" height="170">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
Phasellus imperdiet, nulla et dictum interdum...
</div>

Add a clearfix class with overflow: auto; to the containing element, to fix this problem:

Test-bilde Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus imperdiet, nulla et dictum interdum...

NB! The overflow: auto clearfix works well as long as you are able to keep control of your margins and padding (else you might see scrollbars).

CLEARFIX

The new, modern clearfix hack however, is safer to use, and the following code is used for most webpages:

.clearfix::after {
  content: "";
  clear: both;
  display: table;
}

PB: Denne legges gjerne inn på DIV som inneholder FLOAT.

.clearfix::after {
  content: "";
  clear: both;
  display: table;
}
<div class="clearfix">
<h2>With Clearfix</h2>
<img class="img2" src="pineapple.jpg" alt="Pineapple" width="170" height="170">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
Phasellus imperdiet, nulla et dictum interdum...
</div>

With Clearfix

Test-bilde Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus imperdiet, nulla et dictum interdum...

LOKAL CLEARFIX

PB: Lokalt må denne legges rett etter, i slutten, eksemeplvis i en DIV-tag (BR-tag kan og brukes, men gir linjeskift).

...Phasellus imperdiet, nulla et dictum interdum...
<div style='content: ""; clear: both; display: table;'></div>
</div>...

The most modern version of the clearfix. Chris Coyier on Aug 16, 2018

This will do you fine these days (IE 8 and up):

.group:after {
  content: "";
  display: table;
  clear: both;
}

Apply it to any parent element in which you need to clear the floats. For example:

<div class="group">
  <div class="is-floated"></div>
  <div class="is-floated"></div>
  <div class="is-floated"></div>
</div>

You would use this instead of clearing the float with something like <br style="clear: both;" /> at the bottom of the parent (easy to forget, not handleable right in CSS, non-semantic) or using something like overflow: hidden; on the parent (you don’t always want to hide overflow).

PB: clearfix

Bruk

<div style='content: ""; clear: both; display: table;'></div>

eventuelt

.clearfix::after { content: ""; display: table; clear: both; }

PB: Resett til default CSS

En annen med det samme. Dersom jeg eksempelvis har en HR med CSS CLASS, og ønsker en inline uten noen style (altså at et element ikke arver egenskaper fra en style/stilsett):

<hr style="all:revert;">

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

PB PB PB PB Hent inn CLEARFIX hit, samles sammen det som ligger spredt!

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx



COLORS

Nettsteder:

(https://cloford.com/resources/colours/index.htm)

(www.w3schools.com/colors/colors_complementary.asp)

(www.w3schools.com/colors/colors_groups.asp)

(en.wikipedia.org/wiki/Web_colors)

(enes.in/sorted-colors/)

(www.workwithcolor.com/)

(davidbau.com/colors/)

<form>
  <input type="color" value="" id="favcolor">
</form> 

<p id="hex"></p>

<script>
var theInput = document.getElementById("favcolor");
 var theColor = theInput.value;
 theInput.addEventListener("input", function() {

 document.getElementById("hex").innerHTML = theInput.value;
 }, false);
</script>

PB: Med JavaScript hentes verdien ut nedenfor i en P-tag.


Navngitte farger:

Blå farger:

#000080; = Navy #00008B; = DarkBlue #0000CD; = MediumBlue #0000FF; = Blue #191970; = MidnightBlue #4169E1; = RoyalBlue #4682B4; = SteelBlue #1E90FF; = DodgerBlue #00BFFF; = DeepSkyBlue #6495ED; = CornflowerBlue #87CEEB; = SkyBlue #87CEFA; = LightSkyBlue #B0C4DE; = LightSteelBlue #ADD8E6; = LightBlue #B0E0E6; = PowderBlue

Blågrønne/Turkise farger:

#008080; = Teal #008B8B; = DarkCyan #20B2AA; = LightSeaGreen #5F9EA0; = CadetBlue #00CED1; = DarkTurquoise #48D1CC; = MediumTurquoise #40E0D0; = Turquoise #00FFFF; = Cyan #7FFFD4; = Aquamarine #AFEEEE; = PaleTurquoise #E0FFFF; = LightCyan

Brune farger:

#800000; = Maroon #A52A2A; = Brown #8B4513; = SaddleBrown #A0522D; = Sienna #D2691E; = Chocolate #B8860B; = DarkGoldenrod #CD853F; = Peru #BC8F8F; = RosyBrown #DAA520; = Goldenrod #F4A460; = SandyBrown #D2B48C; = Tan #DEB887; = BurlyWood #F5DEB3; = Wheat #FFDEAD; = NavajoWhite #FFE4C4; = Bisque #FFEBCD; = BlanchedAlmond #FFF8DC; = Cornsilk

Grønne farger:

#006400; = DarkGreen #008000; = Green #556B2F; = DarkOliveGreen #228B22; = ForestGreen #2E8B57; = SeaGreen #808000; = Olive #6B8E23; = OliveDrab #3CB371; = MediumSeaGreen #32CD32; = LimeGreen #00FF00; = Lime #00FF7F; = SpringGreen #00FA9A; = MediumSpringGreen #8FBC8F; = DarkSeaGreen #66CDAA; = MediumAquamarine #9ACD32; = YellowGreen #7CFC00; = LawnGreen #7FFF00; = Chartreuse #90EE90; = LightGreen #ADFF2F; = GreenYellow #98FB98; = PaleGreen

Grå farger:

#000000; = Black #2F4F4F; = DarkSlateGrey #696969; = DimGray #708090; = SlateGray #808080; = Gray #778899; = LightSlateGray #A9A9A9; = DarkGray #C0C0C0; = Silver #D3D3D3; = LightGray #DCDCDC; = Gainsboro

Gule farger:

#BDB76B; = DarkKhaki #FFD700; = Gold #F0E68C; = Khaki #FFDAB9; = PeachPuff #FFFF00; = Yellow #EEE8AA; = PaleGoldenRod #FFE4B5; = Moccasin #FFEFD5; = PapayaWhip #FAFAD2; = LightGoldenRodYellow #FFFACD; = LemonChiffon #FFFFE0; = LightYellow

Lilla farger:

#4B0082; = Indigo #800080; = Purple #663399; = RebeccaPurple #8B008B; = DarkMagenta #9400D3; = DarkViolet #483D8B; = DarkSlateBlue #8A2BE2; = BlueViolet #9932CC; = DarkOrchid #FF00FF; = Magenta #6A5ACD; = SlateBlue #7B68EE; = MediumSlateBlue #BA55D3; = MediumOrchid #9370DB; = MediumPurple #DA70D6; = Orchid #EE82EE; = Violet #DDA0DD; = Plum #D8BFD8; = Thistle #E6E6FA; = Lavender

Lyse farger:

#FFE4E1; = MistyRose #FAEBD7; = AntiqueWhite #FAF0E6; = Linen #F5F5DC; = Beige #F5F5F5; = WhiteSmoke #FFF0F5; = LavenderBlush #FDF5E6; = OldLace #F0F8FF; = AliceBlue #FFF5EE; = SeaShell #F8F8FF; = GhostWhite #F0FFF0; = HoneyDew #FFFAF0; = FloralWhite #F0FFFF; = Azure #F5FFFA; = MintCream #FFFAFA; = Snow #FFFFF0; = Ivory #FFFFFF; = White

Oransje farger:

#FF4500; = OrangeRed #FF6347; = Tomato #FF7F50; = Coral #FF8C00; = DarkOrange #FFA500; = Orange

Rosa farger:

#C71585; = MediumVioletRed #FF1493; = DeepPink #FF69B4; = HotPink #DB7093; = PaleVioletRed #FFB6C1; = LightPink #FFC0CB; = Pink

Røde farger:

#8B0000; = DarkRed #FF0000; = Red #B22222; = FireBrick #DC143C; = Crimson #CD5C5C; = IndianRed #F08080; = LightCoral #FA8072; = Salmon #E9967A; = DarkSalmon #FFA07A; = LightSalmon

Fra tutorialspoint.com

Format Syntax Example
Hex Code #RRGGBB p{color:#FF0000;}
Short Hex Code #RGB p{color:#6A7;}
RGB % rgb(rrr%,ggg%,bbb%) p{color:rgb(50%,50%,50%);}
RGB Absolute rgb(rrr,ggg,bbb) p{color:rgb(0,0,255);}
keyword aqua, black, etc. p{color:teal;}

The following three <div> elements have their background color set with RGB, HEX, and HSL values:

rgb(255, 99, 71)
#ff6347
hsl(9, 100%, 64%)

Same as color name "Tomato":

rgb(255, 99, 71)

#ff6347

hsl(9, 100%, 64%)

RGBA and HSLA values, which adds an Alpha channel to the color. Same as color name "Tomato", but 50% transparent:

rgba(255, 99, 71, 0.5)

hsla(9, 100%, 64%, 0.5)

#404040

#686868

#a0a0a0

#bebebe

#dcdcdc

#f8f8f8

Nye FARGER for nettstedet

Testing av #303030 som tekstfarge mot bakgrunnens #f3f0f6.
Testing av #303030 som tekstfarge mot bakgrunnens #f6f3f3.
Testing av #245090 som LINK-farge mot bakgrunnens #f6f3f3.
Testing av #f74800 som LINK-farge mot bakgrunnens #f6f3f3.
Testing av #291e16 som tekstfarge mot bakgrunnens #a6bfde.
Testing av #ffffff som tekstfarge mot bakgrunnens #496c96.
Testing av #ffffff som tekstfarge mot bakgrunnens #162646.
Testing av #ffffff som tekstfarge mot bakgrunnens #102040.


COMMENTS CSS/HTML

HTML Comment Tags

Note:Comments are not displayed by the browser, but they can help document your HTML source code.

<!-- This is a comment -->

This is a paragraph. Her ligger det skjult kommentar.

Comments are also great for debugging HTML, because you can comment out HTML lines of code, one at a time, to search for errors.

<!-- Do not display this image at the moment
<img border="0" src="pic_trulli.jpg" alt="Trulli">
-->

PB: Fargen:
#008000;



DISPLAY

The CSS Display property

https://flaviocopes.com/css-display/

The display property of an object determines how it is rendered by the browser.

It’s a very important property, and probably the one with the highest number of values you can use.

Those values include:

plus others you will not likely use, like ruby.

Choosing any of those will considerably alter the behavior of the browser with the element and its children.

In this post I’ll analyze the most important ones not covered elsewhere:

I cover others in separate posts:

inline

Inline is the default display value for every element in CSS.

All the HTML tags are displayed inline out of the box except some elements like div, p and section, which are set as block by the user agent (the browser).

Inline elements don’t have any margin or padding applied.

Same for height and width.

You can add them, but the appearance in the page won’t change - they are calculated and applied automatically by the browser.

inline-block

Similar to inline, but with inline-block width and height are applied as you specified.

block

As mentioned, normally elements are displayed inline, with the exception of some elements, including

which are set as block by the browser.

With display: block, elements are stacked one after each other, vertically, and every element takes up 100% of the page.

The values assigned to the width and height properties are respected, if you set them, along with margin and padding.

none

Using display: none makes an element disappear. It’s still there in the HTML, but just not visible in the browser.


Display

tagindex.net

Property Value Explanation
display block the element is displayed as a block-level element
inline the element is displayed as an inline element
list-item the element is displayed as a list item
none the element is not displayed
h1, span {
background-color: #bde9ba;
}

.example1 { display: inline; }
.example2 { display: block; }
.example3 { display: list-item; margin-left: 1em; }
.example4 { display: none; }

div {
margin-bottom: 30px;
}

BLOCK-LEVEL som INLINE

h1 {
background-color: #bde9ba;
}

.example1 { display: inline; }
<h1 class="example1">The block-level element</h1> is displayed as an inline element.

The block-level element

is displayed as an inline element.

INLINE som BLOCK-LEVEL

span {
background-color: #bde9ba;
}

.example2 { display: block; }
The inline element is <span class="example2">displayed</span> as a block-level element.
The inline element is displayed as a block-level element.

INLINE som LIST-ITEM

span {
background-color: #bde9ba;
}

.example3 { display: list-item; margin-left: 1em; }
<span class="example3">The inline element is </span><span class="example3">displayed as a list item.</span>
The inline element is displayed as a list item.

NOT DISPLAYED

span {
background-color: #bde9ba;
}

.example4 { display: none; }
This text is displayed. <span class="example4">This text is not displayed.</span> This text is displayed.
This text is displayed. This text is displayed.

w3schools: Responsive Equal Height

https://www.w3schools.com/howto/howto_css_equal_height.asp

Bedre enn table. Her er alle kolonnene like lange. I tillegg blir de andre kolonnenen like høye etter der det er mest tekst.

* {
  box-sizing: border-box;
}

.col-container {
  display: table;
  width: 100%;
}
.col {
  display: table-cell;
  padding: 16px;
}

@media only screen and (max-width: 600px) {
  .col { 
    display: block;
    width: 100%;
  }
}
<div class="col-container">
  <div class="col" style="background:orange">
    <h2>Column 1</h2>
    <p>Hello World</p>
  </div>

  <div class="col" style="background:yellow">
    <h2>Column 2</h2>
    <p>Hello World!</p>
    <p>Hello World!</p>
    <p>Hello World!</p>
    <p>Hello World!</p>
  </div>

  <div class="col" style="background:orange">
    <h2>Column 3</h2>
    <p>Some other text..</p>
    <p>Some other text..</p>
  </div>
</div>

PB: Denne har jeg lagt inn med full CSS.

Responsive Equal Height Columns

Resize the browser window to see the result. The columns will automatically stack on screens smaller than 600px.

Column 1

Hello World

Column 2

Hello World!

Hello World!

Hello World!

Hello World!

Column 3

Some other text..

Some other text..

PB: NB!!!!!!!!!!!!!!!!!!!!! For å få denne til å funke må jeg finne ut av hvordan knytte opp MEDIA queries mot EKSTERN CSS. Denne funker dersom CSS legges lokalt på samme siden, men ikke når CSS legges i egen ekstern fil!!!!


w3schools: How TO - Toggle Hide and Show

PB: Se også <details>.

https://www.w3schools.com/howto/howto_js_toggle_hide_show.asp

<button onclick="myFunction()">Click Me</button>

<div id="myDIV">
  This is my DIV element.
</div> 

<script>
function myFunction() {
  var x = document.getElementById("myDIV");
  if (x.style.display === "none") {
    x.style.display = "block";
  } else {
    x.style.display = "none";
  }
}
</script>
This is my DIV element.

w3schools: How TO - Collapse

https://www.w3schools.com/howto/howto_js_collapsible.asp

PB: Vanskelig å reprodusere inline. Må lage egne CLASS, og legge på toppen her...

.collapsible {
  background-color: #777;
  color: white;
  cursor: pointer;
  padding: 18px;
  width: 100%;
  border: none;
  text-align: left;
  outline: none;
  font-size: 15px;
}

.active, .collapsible:hover {
  background-color: #555;
}

.collapsible:after {
  content: '\002B';
  color: white;
  font-weight: bold;
  float: right;
  margin-left: 5px;
}

.active:after {
  content: "\2212";
}

.content {
  padding: 0 18px;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.2s ease-out;
  background-color: #f1f1f1;
}
<p>A Collapsible:</p>
<button class="collapsible">Open Collapsible</button>
<div class="content">
<p>Lorem ipsum dolor sit amet, consectetur adipisi...</p>
</div>
<script>
var coll = document.getElementsByClassName("collapsible");
var i;

for (i = 0; i < coll.length; i++) {
  coll[i].addEventListener("click", function() {
    this.classList.toggle("active");
    var content = this.nextElementSibling;
    if (content.style.maxHeight){
      content.style.maxHeight = null;
    } else {
      content.style.maxHeight = content.scrollHeight + "px";
    } 
  });
}
</script>

Fra stackoverflow.com (forum)

PB: Vanskelig å reprodusere inline. Må lage egne CLASS, og legge på toppen her...

.collapse-below {
    display: inline;
}

p.collapse-below::after {
    content: '\000A0\000A0';
}

p.collapse-below ~ label {
    display: inline;
}

p.collapse-below ~ label:hover {
    color: #ccc;
}

input.collapse-below,
ul.collapsible {
    display: none;
}

input[id^="expanded"]:checked + label::after {
    content: '\025BE';
}

input[id^="expanded"]:not(:checked) + label::after {
    content: '\025B8';
}

input[id^="expanded"]:checked + label + ul.collapsible {
    display: block;
}

input[id^="expanded"]:not(:checked) + label + ul.collapsible {
    display: none;
}
<ul>
  <li>single item a</li>
  <li>single item b</li>
  <li>
    <p class="collapse-below" title="this expands">multiple item a</p>
    <input type="checkbox" id="expanded-1" class="collapse-below" name="toggle">
    <label for="expanded-1" title="click to expand"></label>
    <ul class="collapsible">
      <li>sub item a.1</li>
      <li>sub item a.2</li>
    </ul>
  </li>
  <li>single item c</li>
  <li>
    <p class="collapse-below" title="this expands">multiple item b</p>
    <input type="checkbox" id="expanded-2" class="collapse-below" name="toggle">
    <label for="expanded-2" title="click to expand"></label>
    <ul class="collapsible">
      <li>sub item b.1</li>
      <li>sub item b.2</li>
    </ul>
  </li>
  <li>single item d</li>
  <li>single item e</li>
  <li>
    <p class="collapse-below" title="this expands">multiple item c</p>
    <input type="checkbox" id="expanded-3" class="collapse-below" name="toggle">
    <label for="expanded-3" title="click to expand"></label>
    <ul class="collapsible">
      <li>sub item c.1</li>
      <li>sub item c.2</li>
    </ul>
  </li>
</ul>

Fra stackoverflow.com (forum)

PB: Vanskelig å reprodusere inline. Må lage egne CLASS, og legge på toppen her...

body {
    display: inline-block;
}
.span3 ~ .span2:after{
    content:"";
}
.span3:focus ~ .alert  {
    display:block;
}
.span3:focus ~ .span2:after  {
    content:"Hide Me";
}
.span3:after  {
    content: "Show Me";
}
.span3:focus:after  {
    content: "";
}
.alert  {
    display:none;
}
<span class="span3" tabindex="0"></span>
<span class="span2" tabindex="0"></span>
<p class="alert" >Some message to show here</p>

Fra stackoverflow.com (forum)

PB: Vanskelig å reprodusere inline. Må lage egne CLASS, og legge på toppen her...

PB: Kan også legge "lukkeren" inn sammen med det som åpnes, slik at den kun vises sammen med innholdet!

body { display: block; }
p.alert:target { display: none; }
<a href="#alert" class="span3" tabindex="0">Hide Me</a>
<a href="#" class="span2" tabindex="0">Show Me</a>
<p id="alert" class="alert" >Some alarming information here</p>

https://enmascript.com/articles/2019/09/26/toggle-content-on-click-without-javascript

PB: Vanskelig å reprodusere inline. Må lage egne CLASS, og legge på toppen her...

#hashLink {
    display: none;
}

#hashLink:target {    display: block;}
<div>
<p>This is some expandable content.</p>
<p id="hashLink">
I have expanded like a Pufferfish.
<a href="#">Please collapse this poor fish.</a>
</p>
</div>
<a href="#hashLink">Expand</a>


ELEMENT

An element is a part of a webpage. In XML and HTML, an element may contain a data item or a chunk of text or an image, or perhaps nothing. A typical element includes an opening tag with some attributes, enclosed text content, and a closing tag.

Eksempelvis <p class="name">text</p>, kalles Element, som inneholder:

********************

Selector ** NYTTIG **


It is the name of the element of the Web page (or XML document) we want to give properties for the display:

    Type.
    For example H1, A, P, PRE, etc...
    Identifier.
    Elements with an ID="" attribute. The syntax is:

    #identifier

    Class.
    Elements with a CLASS="" attribute. The syntax is:

    .classname

    Descendant (sub-element).
    This is a style for a tag only when embedded (directly or not) into another defined tag.
    Example for a link when it is displayed inside a table:

    table a

Adjacent (successor with same parent).
Element following immediately another given element. Syntax: x + y
Child.
Element directly embedded into another one, but not its childs. Syntax: body > p
Tag with a given attribute.

Syntax: tagname[attribute="value"]
Example: table[width="100"]

Descriptor ** NYTTIG **


The descriptor is a list of declarations that associate by a colon, an attribute and its value.

h2
{
  font-size:120%;
  color:blue;
} 

Sharing a descriptor:

h2, h3
{
  color:green;
}

Some properties have several values:

.title
{
  border: 2px solid black;
} 

The simple selector ** NYTTIG **


This may be the name of a tag, that of a class preceded by a point, that of an identifier preceded by the # sign.

Example of HTML code:

<div id="identifier" class="box">

The associated style sheet:

div { background:white; }

All layers will have a white background.

#identifier { color:red; }

The unnique layer whose the identifier is "identifier" will have a text in red. The others will have the default text color of the container or the page.

.box { border: 1px solid gray; }

All layers belonging to the class "box" will have an edge of one pixel and gray thick. As all other HTML elements to which we associate this class.

In conclusion, selectors can associate a style to a single element, a tag or different tags but with the same class.

Aggregation rule ** NYTTIG **


If you have two rules whose body is the same, but defining different selectors, for example:

h2 { color: blue; }
h3 { color: blue; }  

They can be grouped into one, by separating the selectors with a comma:

h2, h3 { color: blue; }

Subsets rules ** NYTTIG **


We can define a rule for a tag type for a class or a single object but also more specifically, to a class assigned to a type of tag.

To recap:

    a { }
    is a rule that applies to all <a> tags.
    .blue { }
    is a rule that applies to all elements of the class "blue".
    a.blue { }
    applies only to <a> tags that are class "blue".
    a#ident { }
    applies only to the <a> tag whose id is "ident". An id must be unique anyway.

For exemple, to designate such element:

<a class="blue" href="" >Link</a> 

we use the third rule.

********************



ELEMENT - BLOCK

PB: Block som inline, se DISPLAY.

Block-level Elements always starts on a new line and takes up the full width available (stretches out to the left and right as far as it can).

FRA https://developer.mozilla.org/en-US/docs/Web/HTML/Block-level_elements

The distinction of block-level vs. inline elements was used in HTML specifications up to 4.01. In HTML5, this binary distinction is replaced with a more complex set of content categories. While the "inline" category roughly corresponds to the category of phrasing content, the "block-level" category doesn't directly correspond to any HTML5 content category, but "block-level" and "inline" elements combined together correspond to the flow content in HTML5. There are also additional categories, e.g. interactive content.

Elements

The following is a complete list of all HTML "block-level" elements (although "block-level" is not technically defined for elements that are new in HTML5).

<address>
Contact information.
<article>
Article content.
<aside>
Aside content.
<blockquote>
Long ("block") quotation.
<details>
Disclosure widget.
<dialog>
Dialog box.
<dd>
Describes a term in a description list.
<div>
Document division.
<dl>
Description list.
<dt>
Description list term.
<fieldset>
Field set label.
<figcaption>
Figure caption.
<figure>
Groups media content with a caption (see <figcaption>).
<footer>
Section or page footer.
<form>
Input form.
<h1>, <h2>, <h3>, <h4>, <h5>, <h6>
Heading levels 1-6.
<header>
Section or page header.
<hgroup> UTDATERT!!!
Groups header information.
<hr>
Horizontal rule (dividing line).
<li>
List item.
<main>
Contains the central content unique to this document.
<nav>
Contains navigation links.
<ol>
Ordered list.
<p>
Paragraph.
<pre>
Preformatted text.
<section>
Section of a web page.
<table>
Table.
<ul>
Unordered list.


ELEMENT - BLOCK - details

xxxx

Fra developer.mozilla.org

<details>: The Details disclosure element

The HTML Details Element <details> creates a disclosure widget in which information is visible only when the widget is toggled into an "open" state. A summary or label can be provided using the <summary> element.

A disclosure widget is typically presented onscreen using a small triangle which rotates (or twists) to indicate open/closed status, with a label next to the triangle. If the first child of the <details> element is a <summary>, the contents of the <summary> element are used as the label for the disclosure widget.

Først en uten stilsett, som starter lukket.

Details Something small enough to escape casual notice.

Og en uten stilsett, som starter åpent.

Details Something small enough to escape casual notice.

Litt mer stilsett på dette eksemplet.

details {
    border: 1px solid #aaa;
    border-radius: 4px;
    padding: .5em .5em 0;
}

summary {
    font-weight: bold;
    margin: -.5em -.5em 0;
    padding: .5em;
}

details[open] {
    padding: .5em;
}

details[open] summary {
    border-bottom: 1px solid #aaa;
    margin-bottom: .5em;
}
<details>
    <summary>Details</summary>
    Something small enough to escape casual notice.
</details>

Mye interessant av stilsett på dette eksemplet:

details {
  font: 16px "Open Sans", Calibri, sans-serif;
  width: 620px;
}

details > summary {
  padding: 2px 6px;
  width: 15em;
  background-color: #ddd;
  border: none;
  box-shadow: 3px 3px 4px black;
  cursor: pointer;
}

details > p {
  border-radius: 0 0 10px 10px;
  background-color: #ddd;
  padding: 2px 6px;
  margin: 0;
  box-shadow: 3px 3px 4px black;
}

details[open] > summary {
  background-color: #ccf;
}
<details>
  <summary>System Requirements</summary>
  <p>Requires a computer running an operating system. The computer
  must have some memory and ideally some kind of long-term storage.
  An input device as well as some form of output device is
  recommended.</p>
</details>


ELEMENT - BLOCK - div

The <div> Element

div

The div element has no special meaning at all. It represents its children. It can be used with the class, lang, and title attributes to mark up semantics common to a group of consecutive elements.

<div>
<p>content</p>
</div>

content

.wrapper {
  background-color:black;
  color:white; padding:20px;
}

London

London is the capital city of England. It is the most populous city in the United Kingdom, with a metropolitan area of over 13 million inhabitants.


DIV tilhører gruppen nøytrale container koder. Brukes til selvstendige avsnitt og genererer et linjeskift.

Fin egeskap med fast og samtidig fleksibel bredde. Her følger h.s. etter mot venstre når vinduet blir mindre enn satt bredde.

.wrapper {
  background: #100e17;
  border-radius: 8px;
  height: 250px;
  margin-bottom: 2rem;
  padding: 1rem;
  position: relative;
  width: clamp(300px, 90%, 800px);
}

Hello Dolly!


CSS Max-width

div.ex1 {
  width: 600px;
  margin: auto;
  border: 3px solid #73AD21;
}

div.ex2 {
  max-width: 600px;
  margin: auto;
  border: 3px solid #73AD21;
}
This div element has width: 600px;
This div element has max-width: 600px;

Tip: Drag the browser window to smaller than 600px wide, to see the difference between the two divs!


How TO - Aspect Ratio

https://www.w3schools.com/howto/howto_css_aspect_ratio.asp

Create flexible elements that keep their aspect ratio (4:3, 16:9, etc.) when resized:

What is aspect ratio?

The aspect ratio of an element describes the proportional relationship between its width and its height. Two common video aspect ratios are 4:3 (the universal video format of the 20th century), and 16:9 (universal for HD television and European digital television, and default for YouTube videos).

Example 1:1 Aspect Ratio

.container {
 background-color: red;
 position: relative;
 width: 100%;
 padding-top: 100%; /* 1:1 Aspect Ratio */
}

.text {
 position: absolute;
 top: 0;
 left: 0;
 bottom: 0;
 right: 0;
 text-align: center;
 font-size: 20px;
 color: white;
}
1:1 Aspect ratio

Example 16:9 Aspect Ratio

.container {
 background-color: red;
 position: relative;
 width: 100%;
 padding-top: 56.25%; /* 16:9 Aspect Ratio */
16:9 Aspect ratio

Example 4:3 Aspect Ratio

.container {
 background-color: red;
 position: relative;
 width: 100%;
 padding-top: 75%; /* 4:3 Aspect Ratio */
4:3 Aspect ratio

Example 3:2 Aspect Ratio

.container {
 background-color: red;
 position: relative;
 width: 100%;
 padding-top: 66.66%; /* 3:2 Aspect Ratio (divide 2 by 3 = 0.6666) */
3:2 Aspect ratio

Example 8:5 Aspect Ratio

.container {
 background-color: red;
 position: relative;
 width: 100%;
 padding-top: 62.5%; /* 8:5 Aspect Ratio (divide 5 by 8 = 0.625) */
8:5 Aspect ratio

Viewport Unit Based Typography

(2016) https://zellwk.com/blog/viewport-based-typography/

PB: Kun tatt ut et lite utdrag fra denne nyttige artikkelen.

... Since viewport units are automatically recalculated, it becomes extremely easy to create a component that will always be a quarter of the viewport:

.component {
  width: 50vw;
  height: 50vh;
  background: rgba(255, 0, 0, 0.25)
}

PB: Skallerer seg fleksibelt (responsivt) i forhold til viewport-bredden (og høyden), men ikke som % eller tilpasset når plassert i en PX-basert DIV. Tallet 100 tilsvarer 100%.



ELEMENT - BLOCK - p

A paragraph always starts on a new line, and browsers automatically add some white space (a margin) before and after a paragraph.

This is
a paragraph
with line breaks.

Paragraph unstyled

<p style="font-size:40px;">Paragraph styled</p>

Paragraph styled

Each HTML Paragraph has a default size. However, you can specify the size for any Paragraph with the style attribute.



ELEMENT - BLOCK - pre

The HTML pre Element

The HTML <pre> element defines preformatted text (Preformatert tekst).

  My Bonnie lies over the ocean.

  My Bonnie lies over the sea.

  My Bonnie lies over the ocean.

  Oh, bring back my Bonnie to me.

pre

The pre element represents a block of preformatted text, in which structure is represented by typographic conventions rather than by elements.

The code for a basic JavaScript message is:

<script>alert("hello world");</script>
****

How <pre> Works

In an HTML document, the pre element represents preformatted text. This means your tab indents, double-spaces, newlines, and other typographic formatting will be preserved inside a pre element.

By default, browsers will display the content inside a pre element using a monospaced (or fixed-width) font such as Courier or Monaco. This is typical when displaying code, which, as we’ll see, is one of the primary uses for the pre element.

If you want to represent a block of source code in your HTML document, you should use a code element nested inside a pre element. This is semantic, and functionally, it gives you the opportunity to tell search engine crawlers, social media apps, RSS readers, and other interoperating web services that the content is computer code.

Demo

var total = 0;
// Add 1 to total and display in a paragraph
document.write('<p>Sum: ' + (total + 1) + '</p>');

Overflows

By default, text inside pre elements is displayed as it is in the source, so having a line of text that’s wider than the width of the containing pre element will mean the line will flow out of its container.

In multi-column layouts, and especially in float-based fixed-width layouts, overflow issues are more devastating if not dealt with proactively because they can seriously mess up the layout by pushing adjacent columns down the page to places where they shouldn’t be.

Solution 1: Display a Scrollbar

One way to avoid overflow issues is to display a scrollbar whenever the content of the pre element is too wide. This is done by assigning the element overflow: auto in the CSS.

pre {
    overflow: auto;
}

Solution 2: Text-Wrapping

Text-wrapping can be done using the white-space CSS property. There’s a nifty value for white-space that works well for preelements: pre-wrap.

pre {
    white-space: pre-wrap;
}

Rendering HTML

To display HTML tags in the browser, you’ll usually need to escape reserved HTML characters.

In order to render the ...... inside a pre element verbatim, we can escape many of the reserved HTML characters such as <, >, and " to their corresponding character entities, like so (although the quotes and closing angle brackets technically do not need to be escaped):

<nav class="main-navigation"> 
<ul> 
<li><a href="/">Home</a></li> 
<li><a href="about.html">About Us</a></li> 
<li><a href="contact.html">Contact Us</a></li> 
</ul> 
</nav>
&lt;nav class=&quot;main-navigation&quot;&gt; 
&lt;ul&gt; 
&lt;li&gt;&lt;a href=&quot;/&quot;&gt;Home&lt;/a&gt;&lt;/li&gt; 
&lt;li&gt;&lt;a href=&quot;about.html&quot;&gt;About Us&lt;/a&gt;&lt;/li&gt; 
&lt;li&gt;&lt;a href=&quot;contact.html&quot;&gt;Contact Us&lt;/a&gt;&lt;/li&gt; 
&lt;/ul&gt; 
&lt;/nav&gt;

For å få vist en &lt; byttes & symbolet ut med &amp.

*********

The “pre” of a <pre> tag literally means “preformatted text” – which doesn’t say anything about what that text is. A <code> tag, semantically, says the text within is code. It makes sense to me! I always use it when placing blocks of code, which in my experience is the #1 use case.


<pre><code>Denne starter
øverst i PRE</code></pre>

Denne starter
øverst i PRE
**

<pre><code>
Denne starter
en linje nedenfor i PRE</code></pre>


Denne starter
en linje nedenfor i PRE
*****

VIKTIG! Ved bruk av width: min-content;. Den må stå OVER margin og padding, ellers overstyrer den disse til 0px.

**********************

Fra forumet, en som viser sin style på pre (jeg har gjort linjene enda lysere):

.my-pre{
  line-height:1.2em;
  background:linear-gradient(180deg,#e4e4e4 0,#e4e4e4 1.2em,#efefef 0);
  background-size:2.4em 2.4em;
  background-origin:content-box;
  
  /* some extra styles*/
  padding:0 20px;
  text-align:justify;
  font-family:calibri,arial,sans-serif;
}


ELEMENT - EMPTY

Empty Elements - Fra developer.mozilla.org

An empty element is an element from HTML, SVG, or MathML that cannot have any child nodes (i.e., nested elements or text nodes).

The HTML, SVG, and MathML specifications define very precisely what each element can contain. Many combinations have no semantic meaning, for example an <audio> element nested inside an <hr> element.

In HTML, using a closing tag on an empty element is usually invalid. For example, <input type="text"></input> is invalid HTML.

The empty elements in HTML are as follows:

*******

Close Empty HTML Elements?

In HTML, it is optional to close empty elements.


<meta charset="utf-8">


<meta charset="utf-8" />

In XHTML, empty elements must always be closed, like this:


A break: <br />
A horizontal rule: <hr />
An image: <img src="happy.gif" alt="Happy face" />

Også <meta --- />

If you expect XML/XHTML software to access your page, keep the closing slash (/), because it is required in XML and XHTML.

*

Selvlukkende elementer

Det finnes også noe som kalles for selvlukkende elementer eller void-elements på engelsk. Det mest brukte selvlukkende elementet er for eksempel img-elementet, som brukes for å sette inn bilder. Det er egentlig et krav i HTML at man alltid skal lukke et element med en sluttag. Du må fortelle hvor merkingen starter og hvor merkingen slutter. På noen elementer går ikke dette, som for eksempel img-elementet. To andre selvlukkende elementer som er mye brukt er br og hr. Br står for break eller linebreak og har som funksjon å tvinge frem et linjeskift der hvor du setter koden. Hr står for horisontal rule og lager en tynn strek på tvers av skjermen, en slags skillelinje. Det finnes noen flere også som du vil lære deg etter hvert.

Andre elementer

Andre elementer som er verdt å nevne er code-elementet som forteller at den markerte teksten er kode. Et annet er blockquote, det er ment for store sitater mens q er for korte sitater. abbr står for abbreviation og kan brukes for å merke alle type forkortelser som for eksempel HTML.



ELEMENT - INLINE

PB: Inline som block, se DISPLAY.

FRA https://developer.mozilla.org/en-US/docs/Web/HTML/Inline_elements

HTML (Hypertext Markup Language) elements historically were categorized as either "block-level" elements or "inline-level" elements. Since this is a presentational characteristic it is nowadays specified by CSS in the Flow Layout. Inline elements are those which only occupy the space bounded by the tags defining the element, instead of breaking the flow of the content. In this article, we'll examine HTML inline-level elements and how they differ from block-level elements.

An inline element does not start on a new line and only takes up as much width as necessary.

You can change the visual presentation of an element using the CSS display property. For example, by changing the value of display from \\\"inline\\\" to \\\"block\\\", you can tell the browser to render the inline element in a block box rather than an inline box, and vice versa. However, doing this will not change the category and the content model of the element. For example, even if the display of the span element is changed to \\\"block\\\", it still would not allow to nest a div element inside it.

In brief, here are the basic conceptual differences between inline and block-level elements:

Content model
Generally, inline elements may contain only data and other inline elements. You can't put block elements inside inline elements.
Formatting
By default, inline elements do not force a new line to begin in the document flow. Block elements, on the other hand, typically cause a line break to occur (although, as usual, this can be changed using CSS).

The following elements are inline by default (although block and inline elements are no longer defined in HTML 5, use content categories instead):

<a>
<abbr>
<acronym>
<audio> (if it has visible controls)
<b>
<bdi>
<bdo>
<big>
<br>
<button>
<canvas>
<cite>
<code>
<data>
<datalist>
<del>
<dfn>
<em>
<embed>
<i>
<iframe>
<img>
<input>
<ins>
<kbd>
<label>
<map>
<mark>
<meter>
<noscript>
<object>
<output>
<picture>
<progress>
<q>
<ruby>
<s>
<samp>
<script>
<select>
<slot>
<small>
<span>
<strong>
<sub>
<sup>
<svg>
<template>
<textarea>
<time>
<u>
<tt>
<var>
<video>
<wbr>


ELEMENT - INLINE - code

There is a <code> tag in HTML. I literally just used it to wrap that tag in the previous sentence — so meta. It is an inline-by-default element that denotes any sort of code. It has default (user agent) styles that apply a monospace font-family, which feels like a fine default (as it’s true, most code is looked at in monospace).

/* User agent styles in all browsers */
code {
font-family: monospace;
}

Eller også forslag på (https://css-tricks.com/styling-code-in-and-out-of-blocks/) der det er mer koding på CODE og PRE, men denne viser i alle fall hovedprinsipper.


<pre>
<code>
/* For all <code> */
code {
  font-family: MyFancyCustomFont, monospace;
  font-size: inherit;
}

/* Code in text */
p > code,
li > code,
dd > code,
td > code {
  background: #ffeff0;
  word-wrap: break-word;
  box-decoration-break: clone;
  padding: .1rem .3rem .2rem;
  border-radius: .2rem;
}
</code>
</pre>

<h3>The <code>.cool</code> Class, lagt i en H-tag</h3>
<p>Her er <code>.cool</code> lagt inn i en P-tag</p>

The .cool Class, lagt i en H-tag

Her er .cool lagt inn i en P-tag

****

HTML <code> For Computer Code

The content inside is displayed in the browser's default monospace font. Kan være greit samtidig å pakke innholdet inn i PRE (preserve extra whitespace and line-breaks):


x = 5;
y = 6;
z = x + y;



ELEMENT - INLINE - dfn

***********************

dfn

The dfn element represents the defining instance of a term. The paragraph, description list group, or section that is the nearest ancestor of the dfn element must also contain the definition(s) for the term given by the dfn element.

While they're essential reading material for our job, the W3C specifications are not exactly George R. R. Martin-level reading material.

ANDRE KILDER:

The HTML Definition element (<dfn>) is used to indicate the term being defined within the context of a definition phrase or sentence. The <p> element, the <dt>/<dd> pairing, or the <section> element which is the nearest ancestor of the <dfn> is considered to be the definition of the term.

The term being defined is identified following these rules:

  1. If the <dfn> element has a title attribute, the value of the title attribute is considered to be the term being defined. The element must still have text within it, but that text may be an abbreviation (perhaps using <abbr>) or another form of the term.
  2. If the <dfn> contains a single child element and does not have any text content of its own, and the child element is an <abbr> element with a title attribute itself, then the exact value of the <abbr> element's title is the term being defined.
  3. Otherwise, the text content of the <dfn> element is the term being defined. This is shown in the first example below.

If the <dfn> element has a title attribute, it must contain the term being defined and no other text.

EX: A validator is a program that checks for syntax errors in code or documents.

If you include an id attribute on the <dfn> element, you can then link to it using <a> elements. Such links should be uses of the term, with the intent being that the reader can quickly navigate to the term's definition if they're not already aware of it, by clicking on the term's link.

This is shown in the example under Links to definitions below.

Examples

This example uses a plain <dfn> element to identify the location of a term within the definition.

HTML


<p>
The <strong
>HTML Definition element
</strong
>
(<strong
>
<dfn>
&lt;dfn&gt;
</dfn>
</strong
>) is used to indicate the
term being defined within the context of a definition phrase or
sentence.</p
>

Since the <dfn> element has no title, the text contents of the <dfn> element itself are used as the term being defined.

Result

This looks like this rendered in your browser:

To add links to the definitions, you create the link the same way you always do, with the <a> element.

HTML


<p>
The <strong
>HTML Definition element
</strong>
(<strong
>
<dfn id
=
"definition-dfn"
>
&lt;dfn&gt;
</dfn
>
</strong>) is
used to indicate the term being defined within the context of a
definition phrase or sentence.
</p>

<p
>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Graece
donan, Latine voluptatem vocant. Confecta res esset. Duo Reges:
constructio interrete. Scrupulum, inquam, abeunti; 
</p>

<p
>Negare non possum. Dat enim intervalla et relaxat. Quonam modo?
Equidem e Cn. Quid de Pythagora? In schola desinis. 
</p>

<p
>Ubi ut eam caperet aut quando? Cur iustitia laudatur? Aperiendum
est igitur, quid sit voluptas; Quid enim? Non est igitur voluptas
bonum. Urgent tamen et nihil remittunt. Quid enim possumus hoc
agere divinius? </p
>

<p
>Because of all of that, we decided to use the
<code
>
<a href
=
"#definition-dfn"
>
&lt;dfn&gt;
</a
>
</code> element for
this project.</p
>

Here we see the definition — now with an id attribute, "definition-dfn", which can be used as the target of a link. Later on, a link is created using <a> with the href attribute set to "#definition-dfn" to set up the link back to the definition.

Result

The resulting content looks like this:

Using abbreviations and definitions together

In some cases, you may wish to use an abbreviation for a term when defining it. This can be done by using the <dfn> and <abbr> elements in tandem, like this:

HTML


<p
>The 
<dfn
>
<abbr title
=
"Hubble Space Telescope"
>HST
</abbr>
</dfn
>
is among the most productive scientific instruments ever constructed.
It has been in orbit for over 20 years, scanning the sky and
returning data and photographs of unprecedented quality and
detail.</p
>

<p
>Indeed, the 
<abbr title
=
"Hubble Space Telescope"
>HST
</abbr> has
arguably done more to advance science than any device ever built.
</p
>

Note the <abbr> element nested inside the <dfn>. The former establishes that the term is an abbreviation ("HST") and specifies the full term ("Hubble Space Telescope") in its title attribute. The latter indicates that the abbreviated term represents a term being defined.

Result

The output of the above code looks like this:

ANDRE EX:

HTML is the standard markup language for creating web pages.

HTML is the standard markup language for creating web pages.

HTML is the standard markup language for creating web pages.

HTML is the standard markup language for creating web pages.

This is some text...

This is some text...

Learn HTML now.

***********************



ELEMENT - INLINE - kbd

HTML <kbd> For Keyboard Input

The HTML <kbd> element is used to define keyboard input. The content inside is displayed in the browser's default monospace font.

Example: Save the document by pressing Ctrl + S

***********************

kbd

The kbd element represents user input (typically keyboard input, although it may also be used to represent other input, such as voice commands).

When the kbd element is nested inside a samp element, it represents the input as it was echoed by the system. When the kbd element contains a samp element, it represents input based on system output, for example invoking a menu item.

When the kbd element is nested inside another kbd element, it represents an actual key or other single unit of input as appropriate for the input mechanism.

Mac users: To take a screenshot press Command+Shift+3

***********************

kbd

http://maxdesign.com.au/simplex/elements/k.html

This element represents user input (typically keyboard input, although it may also be used to represent other input, such as voice commands).

<p>This is the <kbd>KBD element</kbd> in a sentence.</p>


ELEMENT - INLINE - span

The <span> Element

My mother has blue eyes and my father has dark green eyes.

*******

SPAN tilhører gruppen nøytrale container koder. Brukes f.eks. når det dreier seg om en tekststreng som er en del av en større tekst.

*******

This element represents an inline generic container.

*******

span

The span element doesn't mean anything on its own, but can be useful when used together with the global attributes, e.g. class, lang, or dir. It represents its children.

This is an example of the span element

FORM

Her ligger KUN form egenskaper som jeg kan trenge på nettsidene mine. Alle andre plasseres der de hører hjemme under diverse stylings

En god guide, med detaljert info, om styling av forms: https://formden.com/bootstrap-form-guide/

tutorialspoint.com: Style select options with CSS

FORM Select styling. Sjekket på mobilen. Gul når en skal velge, men valgene kommer opp i en diger hvit boks med nokså store bokstaver.

<!DOCTYPE html>
<html>
   <head>
      <style>
         select {
            width: 100%;
            padding: 10px 15px;
            border: 1px dashed blue;
            border-radius: 4px;
            background-color: orange;
         }
      </style>
   </head>
   <body>
      <p>Learn,</p>
      <form>
         <select id = "country" name = "country">
            <option value = "java">Java</option>
            <option value = "ruby">Ruby</option>
            <option value = "oracle">Oracle</option>
            <option value = "tableau">Tableau</option>
         </select>
      </form>
   </body>
</html>

*******

Form field border

tagindex.net/

#example1 {
width: 250px;
border: medium #85b9e9 dotted;
}

#example2 {
width: 200px;
border: medium #85b9e9 dashed;
}

#example3 {
width: 250px;
height: 7em;
border: medium #85b9e9 double;
}

#example4 {
border: medium #85b9e9 groove;
}
<form method="POST" action="example.cgi">

<p><input type="text" name="item1" id="example1"></p>

<p><select name="item2" id="example2">
<option value="select1">Select1</option>
<option value="select2">Select2</option>
<option value="select3">Select3</option>
</select></p>

<p><textarea name="item3" cols="50" rows="7" id="example3"></textarea></p>

<p><input type="submit" value="submit" id="example4"></p>

</form>
LEGG TIL EKSEMPLET HER...

color of text in a form field

tagindex.net/

textarea {
width: 250px;
height: 7em;
}

input, select, textarea {
color: red;
}
#example {
color: #0000ff;
}
<form method="POST" action="example.cgi">

<p><input type="text" name="item1" value="Example"></p>

<p><select name="item2">
<option value="select1">Select1</option>
<option value="select2">Select2</option>
<option value="select3" id="example">Select3</option>
<option value="select4">Select4</option>
<option value="select5">Select5</option>
</select></p>

<p><textarea name="item3" cols="50" rows="7">Example</textarea></p>

<p><input type="submit" value="Submit"></p>

</form>
LEGG TIL EKSEMPLET HER...

http://maxdesign.com.au/simplex/elements/i.html

Et eksempel på bruk av CLASS og ID på INPUT i FORMs, med bl.a. FARGEVALG / FARGEVELGER!!! og DATOSJEKK!!!

input type TEXT

<input type="text" class="class-name" id="text-id-name" name="text">

PB: Her kan en også sette inn VALUE, for å presentere med ferdig utfylt felt:

<input type="text" value="Ferdig utfylt tekstinnhold">

input type PASSWORD

<input type="password" class="form-password" id="password-id-name" name="password-id-name">

input type FILE

<input type="file" class="class-name" id="file-id-name" name="file-id-name">

input type SEARCH

<input type="search" class="class-name" id="search-id-name" name="search-id-name">

input type EMAIL

<input type="email" class="class-name" id="email-id-name" name="email-id-name">

input type URL

<input type="url" class="class-name" id="url-id-name" name="url-id-name">

input type TEL

<input type="tel" class="class-name" id="tel-id-name" name="tel-id-name">

input type NUMBER

<input type="number" class="class-name" id="number-id-name" name="number-id-name">

input type RANGE

<input type="range" class="class-name"  id="range-id-name" name="range-id-name" min="1" max="10">

input type C O L O R

<input type="color" class="class-name" id="color-id-name" name="color-id-name">

PB: Eventuelt åpne med kun tekst:

input type WEEK

<input type="week" class="class-name" id="week-id-name" name="week-id-name">

input type MONTH

<input type="month" class="class-name" id="month-id-name" name="month-id-name">

input type TIME

<input type="time" class="class-name" id="time-id-name" name="time-id-name">

input type DATETIME-LOCAL

<input type="datetime-local" class="class-name" id="datetime-id-name" name="datetime-id-name">

Skjemaer

https://www.tutora.no/skjemaer/

Skjemaer kan brukes til mange ting, og som alt annet innen HTML så er det veldig viktig at du tilrettelegger for de med forskjellige handikap og tenker på brukervennlighet. På egenhånd vil ikke et HTML skjema fungere. For at de skal fungere må du i tillegg bruke webteknologier som PHP, JSP, ASP eller lignende.

Måtte skrive inn fra et bilde:
<form>
  <input type="text">
  <input type="text">
</form>

Et skjema består stort sett i 2 grunnleggende elementer, form og input. Det er også 3 andre elementer som blir mye brukt i skjemaer, nemlig textareaselect og option. Ved å sette type-attributtet inne i input-elementet kan det ta mange forskjellige former som for eksempel textpassword,  submitcheckboxradio med flere.

<form>
  <label for="name">Name</label>
  <input id="name" type="text">
  <label for="email">Email</label>
  <input id="email" type="text">
</form>

Dette skjemaet er ikke særlig brukervennlig da du ikke vet hva de forskjellige feltene skal inneholde. Ved å legge på et label-element over hver av input-elementene, vil brukeren av skjemaet umiddelbart forstå hva som skal skrives inn hvor. For at label-elementet skal være riktig skrevet i HTML må det inneholde et for-attributt. Dette for-attributtet skal ha samme verdi som id-attributtet i input-elementet. Det vil si, hvis du ikke har et id-attributt i input-elementet, må du lage det også, hvis du skal bruke label-elementet.

<form>
  <label for="name">Name</label>
  <input id="name" type="text">
  <label for="email">Email</label>
  <input id="email" type="text">
  <select>
    <option>Onion</option>
    <option>Mushroom</option>
    <option>Pepper</option>
  </select>
  <textarea></textarea>
</form>

Det er to elementer til som er vanlig å bruke i et HTML-skjema. En drop down menu eller rullgardinmeny som det heter på norsk og et stort tekstfelt. HTML-elementene er henholdsvis select for rullgardinmenyen og textarea for et stort tekstfelt. Rullgardinmenyen fungerer ikke uten også å inkludere option-elementet, akkurat på samme måte som en HTML-liste.

<form>
  <input id="large" type="radio" name="size" value="large">
  <label for="large">Large</label>
  <input id="medium" type="radio" name="size" value="medium">
  <label for="medium">Medium</label>
  <input id="small" type="radio" name="size" value="small">
  <label for="small">Small</label>
</form>

Som nevnt over kan du endre input-elementet ved å endre type-attributtet. Til nå har du bare sett eksempler på text men det finnes mange andre også. Du kan for eksempel velge radio istedenfor text. Her er det viktig at alle radio-knappene har samme name-attributt, hvis ikke vil det ikke virke.

<form>
  <input id="pepperoni" type="checkbox" value="pepperoni">
  <label for="pepperoni">Pepperoni</label>
  <input id="onion" type="checkbox" value="onion">
  <label for="onion">Onion</label>
  <input id="mushroom" type="checkbox" value="mushroom">
  <label for="mushroom">Mushroom</label>
  <input id="pepper" type="checkbox" value="pepper">
  <label for="pepper">Pepper</label>
  <input id="bacon" type="checkbox" value="bacon">
  <label for="bacon">Bacon</label>
</form>

Du kan også sette type-attributtet til checkbox.

Lag et skjema

<h1>Contact</h1>
<form>
  <label for="name">Name</label>
  <input id="name" type="text">
  <label for="email">Email</label>
  <input id="email" type="text">
  <label for="message">Message</label>
  <textarea id="message"></textarea>
  <input type="submit" value="Send">
</form>

Hvis du ser på den i en nettleser nå så ser den ikke særlig bra ut. Det bryr ikke vi oss om fordi HTML-koden ser perfekt ut. Utseende kommer senere med CSS.



HEAD

HTML - The Head Element

The HTML <head> Element

The HTML <style> Element

The HTML <link> Element

The HTML <meta> Element

Examples

Define the character set used:
<meta charset="UTF-8">
Define keywords for search engines:
<meta name="keywords" content="HTML, CSS, JavaScript">
Define a description of your web page:
<meta name="description" content="Free Web tutorials">
Define the author of a page:
<meta name="author" content="John Doe">
Refresh document every 30 seconds:
<meta http-equiv="refresh" content="30">
Setting the viewport to make your website look good on all devices:
<meta name="viewport" content="width=device-width, initial-scale=1.0">

Rekkefølgen

PB: Det finnes ingen direkte anbefaling på rekkefølgen, bortsett fra de to første, samt TITLE. Generelt sett brukes følgende, der rekkefølgen altså IKKE har noe å si for SEO og Google-roboter, som er relevante for mitt behov:

  1. <head>
  2. <meta charset="utf-8" />
  3. <meta name="viewport" content="width=device-width, initial-scale=1" />
  4. <title>Tittel på enkeltsiden</title>
  5. <meta name="description" content="Beskrivelse av siden, for Google visning" />
  6. <meta name="keywords" content="ord,ord,ord,gjeldende for siden" />
  7. <meta name="author" content="Petrus Bojanowski" />
  8. <meta name="designer" content="Petrus Bojanowski" />
  9. <meta name="publisher" content="Petrus Bojanowski" />
  10. <meta name="robots" content="index, follow" />
  11. <meta name="robots" content="noindex, nofollow, nosnippet" />
  12. <meta name="robots" content="noimageindex" />
  13. <meta name="robots" content="notranslate" />
  14. <meta name="audience" content="all" />
  15. <meta name="subject" content="Personal" />
  16. <meta name="copyright" content="Copyright 2021" />
  17. <link rel="stylesheet" href="zz-testingHTML5.css" type="text/css" />
  18. <script src="/sti/til/min.js"></script>
  19. <style>Interne CSS-koder</style>
  20. </head>

Det finnes også en meta name=generator content="Programvare", som ikke skal benyttes dersom en ikke har brukt en software for kodingen av nettsiden. Altså ikke slik som for mine håndkodete sider.

I tillegg bør følgende ligge over <head>:

<html lang="en">
eller
<html lang="no">

https://html.spec.whatwg.org/multipage/semantics.html#standard-metadata-names

Authors are encouraged to specify a lang attribute on the root html element, giving the document's language. This aids speech synthesis tools to determine what pronunciations to use, translation tools to determine what rules to use, and so forth.

<title>

The title element represents the document's title or name. Authors should use titles that identify their documents even when they are used out of context, for example in a user's history or bookmarks, or in search results. The document's title is often different from its first heading, since the first heading does not have to stand alone when taken out of context.

It is advisable to keep it under 70 characters long.

Here are some examples of appropriate titles, contrasted with the top-level headings that might be used on those same pages.

<title>Introduction to The Mating Rituals of Bees</title>
...
<h1>Introduction</h1>
<p>This companion guide to the highly successful
<cite>Introduction to Medieval Bee-Keeping</cite> book is...

The next page might be a part of the same site. Note how the title describes the subject matter unambiguously, while the first heading assumes the reader knows what the context is and therefore won't wonder if the dances are Salsa or Waltz:

<title>Dances used during bee mating rituals</title>
...
<h1>The Dances</h1>

Description

https://www.w3schools.com/tags/tag_meta.asp

<meta name="description" content="Free Web tutorials for HTML and CSS">

https://htmlhead.dev/

<!-- Short description of the document (limit to 150 characters) -->
<!-- This content *may* be used as a part of search engine results. -->
<meta name="description" content="A description of the page" />

Finally, on December 2017, the snippets passed the 300-character mark.

Keywords

https://www.w3schools.com/tags/tag_meta.asp

<meta name="keywords" content="HTML, CSS, JavaScript">

https://hiof.instructure.com/courses/712/pages/html-tekst-lenker-og-bilder

På en nettside må man minimum ha følgende informasjon:


Search Engines

https://htmlhead.dev/

<!-- Control the behavior of search engine crawling and indexing -->
<meta name="robots" content="index,follow"><!-- All Search Engines -->
<meta name="googlebot" content="index,follow"><!-- Google Specific -->
<!-- Tells Google not to show the sitelinks search box -->
<meta name="google" content="nositelinkssearchbox">

<!-- Tells Google not to provide a translation for this document -->
<meta name="google" content="notranslate">

(2020) https://ahrefs.com/blog/meta-robots/

https://moz.com/learn/seo/robots-meta-directives

Let’s get one thing straight from the beginning. You can’t control indexation with robots.txt. That’s a common misconception.

Both name and content attributes are non-case sensitive.

Meta directives give crawlers instructions about how to crawl and index information they find on a specific webpage.

INDEX

The index and all directives signals to search engine robots that you’d like them to index the page. You don’t have to indicate this, as it’s the default for search engines: unless you specify a different directive search engines will index the page and follow its links.

FOLLOW

Even if the page isn’t indexed, the crawler should follow all the links on a page and pass equity to the linked pages.

The follow and alldirectives tells search engines to follow the links on the page and to pass on link authority. Just like the index directive it’s the default so there’s no absolute need to specify.

PB: Fant en blogg som sa at <meta name="robots" content="index, follow" /> ikke er nødvendig (for dette er default). MEN, dersom en har enkelte sider som ikke skal besøkes av roboter, så kan det være greit å skille dem fra hverandre med denne.

NOINDEX

<meta name="robots" content="noindex" />

Instructs search engines not to index the page. That prevents it from showing in search results.

NOFOLLOW

<meta name="robots" content="nofollow" />

Stops robots from crawling all links on the page. Please note that those URLs still may be indexable, especially if they have backlinks pointing to them.

rel="nofollow"

The rel="nofollow" is an attribute you can set on an HTML <a> link tag, invented by Google, and adopted by others. Those links won't get any credit when Google ranks websites in the search results, thus removing the main incentive behind blog comment spammers robots. ...it sounds like it only affects the ranking, and the Google robot may still follow the links and index them.

NONE

<meta name="robots" content="none" />

The combination of noindex, nofollow. Avoid using this as other search engines (e.g., Bing) don’t support this.

The none directive signals to search engine robots that this page should basically be ignored. It’s sometimes used as a shortcut for noindex and nofollow directives, as well.

Protip: when you’re using either the none directive, or noindex,nofollow directive it’s recommended to disallow access to this page all together using your robots.txt file.

NOARCHIVE

<meta name="robots" content="noarchive" />

Prevents Google from showing a cached copy of the page in the SERP (search engine result pages).

NOTRANSLATE

<meta name="robots" content="notranslate" />

Prevents Google from offering a translation of the page in the SERP (search engine result pages).

NOIMAGEINDEX

<meta name="robots" content="noimageindex" />

Prevents Google from indexing images embedded on the page. Tells a crawler not to index any images on a page.

UNAVAILABLE_AFTER:

<meta name="robots" content="unavailable_after: Sunday, 01-Sep-19 12:34:56 GMT" />

Tells Google not to show a page in search results after a specified date/time. Basically a noindex directive with a timer. The date/time must be specified using the RFC 850 format.

NOSNIPPET

Opts out of all text and video snippets within the SERP (search engine result pages). It also works as noarchive at the same time.

Tells a search engine not to show a snippet of this page (i.e. meta description) of this page on a SERP (search engine result pages).

The nosnippet directive prevents search engines from displaying snippets in the SERPs (search engine result pages) and additionally prevents search engines from caching the page.

PB: Det finnes mye om dette, men detaljene er ikke relevante for mitt vedkommende...

BRUKE FLERE PÅ EN GANG

<meta name="robots" content="noimageindex, nofollow, nosnippet" />

This tag would tell robots not to index any of the images on a page, follow any of the links, or show a snippet of the page when it appears on a SERP (search engine result pages).

If you’re using different meta robots tag directives for different search user-agents, you’ll need to use separate tags for each bot.

https://www.contentkingapp.com/academy/meta-robots-tag/

<mmeta name="robots" content="noindex,follow" />

This specific example tells all search engines not to index the page, but to follow the links it finds on the page and to pass on link authority. These instructions (noindex,follow) are called search engine directives.

Flere eksempler/varianter:

<META NAME="ROBOTS" CONTENT="NOINDEX, FOLLOW">
<META NAME="ROBOTS" CONTENT="INDEX, NOFOLLOW">
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">

Setting The Viewport

<meta name="viewport" content="width=device-width, initial-scale=1.0">

The width=device-width part sets the width of the page to follow the screen-width of the device (which will vary depending on the device).

The initial-scale=1.0 part sets the initial zoom level when the page is first loaded by the browser.


LANG=

Når det gjelder språk, kan LANG= også brukes inline:

<p>Japanese example: <span lang="ja">ご飯が熱い。</span>.</p>

Japanese example: ご飯が熱い。.


What are Meta Tags?

(2020) https://www.inmotionhosting.com/support/website/seo/what-are-meta-tags/

PB: utdrag fra mye info

Meta tags must go in the <head> section of your website.

Adds a description page for search engines

The Description meta tag is what Google uses to display in tehir search engine. Must contain a small Sentence/Paragraph about your site.

Paste the following code after the <title>tag.

<meta name="description" content="This is my website description in a small paragraph.">

Now when your site is found in search engines the description you put will show below the search results.

List keywords for search engines

Below is an example of the keyword meta tag. This allows single words separated by commas to list what the article is focusing on.

<meta name="keywords" content="word1, word2, word3">

<meta name=”keywords” content=”enter your keywords here” />

Keywords are to be separated with a comma and will look something like this:

<meta name=”keywords” content=”web hosting, webhosting, website hosting, web site hosting, inmotion, inmotion hosting, inmotionhosting” />

Typically, you’ll want to limit them to 10 or less in each webpage.

Shows who wrote the document

This meta data supplys the author information.

<meta name="author" content="John Doe">

Refresh or redirect the user to another page

Below will refresh the same page after 45 seconds.

<meta http-equiv="refresh" content="45">

Below will redirect your to Google after 5 seconds.

<meta http-equiv="refresh" content="5;URL=https://www.google.com">


No More Types for Scripts and Links

28 HTML5 Features, Tips, and Techniques you Must Know

Fra: code.tutsplus.com

<link rel="stylesheet" href="path/to/stylesheet.css" type="text/css" />
<script type="text/javascript" src="path/to/script.js"></script>

This is no longer necessary. It's implied that both of these tags refer to stylesheets and scripts, respectively. As such, we can remove the type attribute all together.

<link rel="stylesheet" href="path/to/stylesheet.css" />
<script src="path/to/script.js"></script>


HR

hr

Represents a paragraph-level thematic break. The "paragraph-level" bit means between blocks of text, so it can't be used to separate sections of a site. Instead, hr now separates different topics within a section of prose, or between scenes in a novel.

<p>Lorem Ipsum dolor set amet</p>
<hr />
<p>Lorem Ipsum dolor set amet</p>

Lorem Ipsum dolor set amet


Lorem Ipsum dolor set amet

Her har jeg satt inn <hr style="all:revert;" /> for at HR ikke skal arve CSS egenskapene til siden.


HR width and height

Only the width and height styles are consistent across all browsers so some trial and error may be needed when using other styles. The default width is always 100 percent of the width of the web page or parent element. The default height of the rule is two pixels.

<hr />

hr {
  height: 10px;
}

hr {
  width: 50%;
  height: 2em;
}


Rotert HR med transform

hr {
-moz-transform: rotate(3deg);
-webkit-transform: rotate(3deg);
-o-transform: rotate(3deg);
-ms-transform: rotate(3deg);
transform: rotate(3deg);
} 


HR styling eksempler, som BORDER

   hr{
      margin-bottom: 20px;
   }
   .solid {
      border-top: 5px solid rgb(16, 2, 141);
   }
   .dashed {
      border-top: 5px dashed rgb(190, 13, 146);
   }
   .double {
      border-top: 5px double rgb(22, 145, 11);
   }
   .dotted {
      border: 5px dotted rgb(200, 255, 0);
   }
   .round {
      border: 5px solid rgb(35, 196, 142);
      border-radius: 5px;
   }
<h2 style="text-align: center;">HR styling example</h2>
<hr class="solid" />
<hr class="dashed" />
<hr class="double" />
<hr class="dotted" />
<hr class="round" />
SOLID

border-top: 5px solid rgb(16, 2, 141);

DASHED

border-top: 5px dashed rgb(190, 13, 146);

DOUBLE

border-top: 5px double rgb(22, 145, 11);

DOTTED

border: 5px dotted rgb(200, 255, 0);

ROUND

border: 5px solid rgb(35, 196, 142); border-radius: 5px;


Alignment of the horizontal rule

FRA: tagindex.net

The text-align property sets the text horizontal alignment, and the margin property sets the margins of an element.

For MSIE and Opera
The alignment of the horizontal rule can be specified by applying the text-align property to the HR element.

For Chrome, Safari, Firefox
The alignment of the horizontal rule can be specified by applying the margin property to the HR element.

PB: Fargelagt disse slik: all:revert; for at de ikke skal arve sidens CSS, og så gitt dem RØD farge border: 1px solid red;.

hr { width: 50%; }


hr { width: 30%; text-align: left; margin-left: 0; }


hr { width: 30%; text-align: right; margin-right: 0; }



tagindex.net

HR element

hr.example1 {
border: 1px #ff0000 solid;
background-color: #ffdfe2;
height: 10px;
}
<hr class="example1">

hr.example2 {
border-style: solid;
border-width: 4px;
border-color: #c40000 #ffdfe2 #ffdfe2 #c40000;
background-color: #ff8080;
height: 10px;
}
<hr class="example2">

hr.example3 {
border-style: dotted none none none;
border-top-width: 2px;
border-top-color: #ff0000;
height: 2px;
}
<hr class="example3">



IFRAMES

HTML Iframes

An HTML iframe is used to display a web page within a web page.

PB: Denne er tilpasset for å likne min Samsung Galaxy S8+ kjøpt høsten 2017.



POSITIONING

Position child element directly under parent element

Fra stackoverflow.com (forum)

#father {
  position: relative;
  background: green;
  height: 50px;
}
#son {
  position: absolute;
  top: 100%;
  background: lightblue;
  height: 30px;
}
<div id="father">
  content
  <div id="son">
  content
  </div>
</div>
content
content

https://tomelliott.com/html-css/css-position-child-div-parent

1. Child div positioned at bottom right of parent

The HTML and CSS for this is pretty simple. The parent container is set to relative position and the child is set to absolute. To align the child to the bottom right we use bottom:0px; and right:0px;

If the parent div did not have the position CSS proerty set in this case, then it would align with the bottom of the page.

PB: Modifisert størrelsene.

.parent {
  width:100px;
  height:100px;
  background-color:#CCCCCC;
  position:relative;
}
 
.child {
  width:50px;
  height:50px;
  background-color:#999999;
  position:absolute;
  bottom:0px;
  right:0px;
}
<div class="parent">
<div class="child"></div>
</div>

2. Child div positioned top right of parent and parent bottom left

Let’s add another child box in this example. We’ll call these elements grandparent (large box), parent and child (small box).

As the parent is positioned relative to the grandparent with bottom:0px; then it is given a position:absolute. The child which is positioned top right of it’s parent is also position:absolute; with top:0px; and right:0px; and the grandparent has the CSS property position:relative;.

.grandparent {
  width:100px;
  height:100px;
  background-color:#CCCCCC;
  position:relative;
}
 
.parent {
  width:50px;
  height:50px;
  background-color:#999999;
  position:absolute;
  bottom:0px;
}
.child {
  width:25px;
  height:25px;
  background-color:#666666;
  position:absolute;
  right:0px;
  top:0px;
}
<div class="grandparent">
<div class="parent">
<div class="child"></div>
</div>
</div>

3. Child div positioned top right when parent has no position

In the 3rd and final example, we see what happens with exactly the same setup as example 2 but with the position:absolute; CSS style removed from the middle ‘parent’ div container.

As the parent is not absolutely positioned, it will appear in the default top left position. The child however still has it’s absolute positioning set to the top right, so it is positioned relative to the next parent div that has position:absolute; or position: relative. In this case, the next parent container div is the grandparent.

.grandparent {
  width:100px;
  height:100px;
  background-color:#CCCCCC;
  position:relative;
}
 
.parent {
  width:50px;
  height:50px;
  background-color:#999999;
  /*position:absolute;*/
  bottom:0px;
}
.child {
  width:25px;
  height:25px;
  background-color:#666666;
  position:absolute;
  right:0px;
  top:0px;
}
<div class="grandparent">
<div class="parent">
<div class="child"></div>
</div>
</div>

CSS Position: Relative vs Position Absolute

https://dzone.com/articles/css-position-relative-vs-position-absolute

There is a thing you should keep in mind while setting position - relative to an element limits the scope of absolutely positioned child elements. This means that any element that is the child of this element can be absolutely positioned within this block.

In this example, you will see how the relatively positioned element moves when its attributes are changed. The first element moves to the left and top from its normal position, while the second element stays in the same place because none of the additional positioning attributes were changed.

#first_element {
  position: relative;
  left: 30px;
  top: 70px;
  width: 500px;
  background-color: #fafafa;
  border: solid 3px #ff7347;
  font-size: 24px;
  text-align: center;
}

#second_element {
  position: relative;
  width: 500px;
  background-color: #fafafa;
  border: solid 3px #ff7347;
  font-size: 24px;
  text-align: center;
}
<div id="first_element">First element</div>
<div id="second_element">Second element</div>
First element
Second element


This type of positioning allows you to place your element precisely where you want it.

The positioning is done relative to the first relatively (or absolutely) positioned parent element. In the case when there is no positioned parent element, it will be positioned related directly to the HTML element (the page itself).

An important thing to keep in mind while using absolute positioning is to make sure it is not overused, otherwise, it can lead to a maintenance nightmare.

The next thing, yet again, is to show an example.

In the example, the parent element has the position set to relative. Now, when you set the position of the child element to absolute, any additional positioning will be done relative to the parent element. The child element moves relative to the top of the parent element by 100px and right of the parent element by 40px.

#parent {
  position: relative;
  width: 250px;
  height: 200px;
  background-color: #fafafa;
  border: solid 3px #9e70ba;
  font-size: 24px;
  text-align: center;
}

#child {
  position: absolute;
  right: 40px;
  top: 100px;
  width: 50px;
  height: 50px;
  background-color: #fafafa;
  border: solid 3px #78e382;
  font-size: 24px;
  text-align: center;
}
<div id="parent">
<div id="child"></div>
</div>

https://leannezhang.medium.com/difference-between-css-position-absolute-versus-relative

.parent {
 border:2px black dotted;
 display:inline-block;
}
.box {
 display:inline-block;
 background:red;
 color:white;
 width:100px;
 height:100px;
}
#two {
  background:green;
}
<div class="parent">
 <div class="box" id="one">One</div>
 <div class="box" id="two">Two</div>
 <div class="box" id="three">Three</div>
 <div class="box" id="four">Four</div>
</div>

By default, position is set to static. It positions based on the layout in the flow.

One
Two
Three
Four

Position Relative Example

What happens when we want to move the GreenBox but do not want to affect the layout around it?

#two {
  background: green;
  position: relative;
  top: 20px;
  left: 20px;
}
One
Two
Three
Four

Position: absolute is the opposite.

By applying position: absolute to the GreenBox, it will not leave any gap where it would have been. The position of the GreenBox is based on its parent position (the dotted border). Thus, moving 20px to the left and bottom from the top-left origin of the dotted border.

#two {
  background: green;
  position: absolute;
  top: 20px;
  left: 20px;
}
One
Two
Three
Four

PB: Her måtte jeg faktisk hjelpe til. Uten position:relative; satt på DIV som denne skulle relateres position:absolute; til, så forsvant den selvfølgelig til toppen av siden!


CSS Position Property

FRA https://love2dev.com/blog/absolutely-fixing-the-mobile-fixed-positioned-toolbar/

Each HTML element has a CSS position property. The default value is static, which means it is just rendered where it is within the DOM. Static position does not honor left, right, top or bottom properties.

Relative Positioning

The next position value is relative, which allows you to set positioning relative to its natural location. For example if you set the left, right, top or bottom properties to the following values:

.target{ position:relative; top: 25px; left: 25px;}

The element will render 25 pixels below and 25pixels to the right of its natural position. This can be combined with a CSS animation or transition to create a nice movement animation experience.

position:absolute test

Absolute Positioning

Similar to relative absolute positioning honors the top, right, bottom and left properties. The difference is absolute positions the element relative to the document or the nearest parent element utilizing relative positioning. If we change the previous example to use absolute positioning the target element now positions itself 25pixels from the top left corner of the view port.

.target{ position:absolute; top: 25px; left: 25px;}

PB: Simulert, ved bruk av position: relative; til P, for å unngå at den gikk til toppen av siden!

position:absolute test




Legger seg over alt annet (og skjuler det med sin z-inde). Husk å lage plass rundt, eller gjør gjennomsiktig!

Fixed

Last there is Fixed positioning, which behave similarly to absolute positioned elements. The big difference is they do not scroll when the window is scrolled. This is why web developers default to fixed positioning for things like toolbar navigation widgets.

.target{ position:fixed; top: 10px; left: 10px;}

So why not just use fixed positioning? Well mobile browsers has not been so kind to fixed positioning, the reasons are sort of abstract complicated. Instead of getting lost in the weeds with the details lets just assume fixed positioning is broken in mobile browsers. This threw a monkey wrench at the best intended web developers, including myself. ....

This approach creates the experience of fixed positioned elements that do not scroll as the user scrolls the content up, down, left or right. The secret to this experience is to leverage overflow scrolling and other touch CSS properties to allow the user to move the content into view. Instead of making the content scroll at the document level it scrolls within the container element.

PB: Denne løsningen fungerer ikke bra den heller, ikke en gang på PC!


.site-header {
  position: absolute;
  top: 0px;
  right: 0px;
  left: 0px;
  height: 60px;
  line-height: 60px;
  vertical-align: middle;
  color: #3a1b48;
  background-color: #d575ff;
}
.main-content {
  position: absolute;
  overflow: hidden;
  left: 0px;
  right: 0px;
}
.toolbar {
  position: absolute;
  right: 0px;
  bottom: 0px;
  left: 0px;
  background-color: #48195c;
  color: #fff;
  height: 35px;
  overflow: hidden;
  text-align: center;
}

position: fixed;

An element with position: fixed; is positioned relative to the viewport, which means it always stays in the same place even if the page is scrolled:

This div element has position: fixed;

div.fixed {
  position: fixed;
  bottom: 0;
  right: 0;
  width: 300px;
  border: 3px solid #73AD21;
}

PB: Denne er kun fremvist som innhold, altså ikke låst den til høyre bunnsiden av nettleseren!

tekst

w3schools: How TO - Fixed Footer

https://www.w3schools.com/howto/howto_css_fixed_footer.asp

.footer {
   position: fixed;
   left: 0;
   bottom: 0;
   width: 100%;
   background-color: red;
   color: white;
   text-align: center;
}
<div class="footer">
  <p>Footer</p>
</div>

PB: Testet denne. Virker til dels. Men teksten forsvinner langt ut mot høyre. Må scrolle sideveis.


a:hover {
position: relative;
top: 1px;
left: 1px;
text-decoration: none;
}
<p><a href="index.html">Link Styles</a></p>

********************

********************

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

position:fixed test

Følgende ligger nederst på siden, V.S.

FLOAT H.S. fungerer ikke på MOBILEN.

Testing, med ren tekst. Øverst ligger med PIL OPP!

<div style="position: fixed;
  color: #696969;
  bottom: 0;
  left: 0;
  padding:4px 2%;
  border: 2px solid #D3D3D3;">
 <a style="color:#696969" href="zz-testingHTML5.html">
 zz-testingHTML5</a></div>

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

How To Create a Notification Button

Fra w3schools.com

body {
  font-family: Arial, Helvetica, sans-serif;
}

.notification {
  background-color: #555;
  color: white;
  text-decoration: none;
  padding: 15px 26px;
  position: relative;
  display: inline-block;
  border-radius: 2px;
}

.notification:hover {
  background: red;
}

.notification .badge {
  position: absolute;
  top: -10px;
  right: -10px;
  padding: 5px 10px;
  border-radius: 50%;
  background-color: red;
  color: white;
}
<a href="#" class="notification">
  <span>Inbox</span>
  <span class="badge">3</span>
</a>

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

En veldig god forklaring, med bilder.

https://ishadeed.com/article/learn-css-positioning/

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Hvordan bruke media-queries i CSS

Før trengte man ikke bry seg så mye med skjermstørrelser og oppløsninger når man drev med webutvikling. Det største problemet da var at ikke alle nettlesere tolket CSS-reglene likt. Etterhvert som det problemet ble mindre og mindre dukket det opp en ny utfordring.

Vi hadde fått hundrevis av nye skjermstørrelser og folk hadde nå begynt å surfe på nettet med bittesmå skjermer som de holdt i hendene sine.

For å løse denne nye utfordringen kom noen opp med ideen om å bruke noe som heter Media Queries. Da kan siden din spørre nettleseren hva slags medium den skal vises på og hva slags oppløsning det mediumet har. Dette var ikke noe nytt i CSS, men å bruke det til å lage forskjellig CSS til forskjellige oppløsninger var en relativt ny ide.

For å lage din første Media Query skriver du følgende kode i bunnen av CSS-filen din.

@media (max-width: 769px) {
  header {
    display: block;
  }
}

Det denne regelen gjør er at den sier at så lenge skjermen er smalere enn 769px så skal disse reglene gjelde. Så hvis du drar vindu til siden for å gjøre det smalere så vil du se at når du kommer til 768px, så vil ikke lenger header være flex men vil da bytte til block.

Prøv å putte inn en bakgrunnsfarge i Media Query-et for å se hva som skjer. Her er det bare fantasien som setter grenser.

Denne metoden løste et stort problem for webutviklere som da var godt i gang med å designe en side for mobil, en for nettbrett og en tredje for PC. Denne metoden gjør at du kun trenger en nettside med en CSS-fil, men det er ikke alle CSS-reglene som gjelder hele tiden, avhengig av oppløsningen på skjermen din.


box positioning

https://www.tagindex.net/css/box/top_right_bottom_left.html

Property Value Explanation
position static the normal position (default)
relative the relative position from the normal position
absolute the absolute position from the parent element
fixed the absolute and fixed position from the window

Example

body {
margin: 0;
padding: 0;
background-color: #ffffff;
background-image: url(image/graf.gif);
background-repeat: no-repeat;
}

div {
width: 300px;
height: 100px;
background-color: #85b9e9;
position: absolute;
}

#example1 {
top: 50px;
left: 150px;
}

#example2 {
top: 200px;
left: 50px;
}
<div id="example1">The first box</div>
<div id="example2">The second box</div>

PB: Her har jeg tilpasset og endret litt. Bl.a. IKKE position: absolute; til BODY, men position: relative; til DIV. Og så har jeg IKKE background-repeat: no-repeat; fordi jeg laget et eget bilde bilder/50x50.gif av rutenettets ene rute.

width: 200px;
height: 100px;
top: 100px;
left: 50px;

Example

CSS:
div {
width: 200px;
height: 100px;
}

HTML:
<div style="background-color: #85b9e9;">The first box</div>
<div style="background-color: #ffd78c;">The second box</div>
<div style="background-color: #bde9ba; position: absolute; top: 50px; left:100px;">The third box</div>

PB: Denne måtte jukses til, med RELATIVE, for å passe inn lokalt innenfor min DIV. Ville med ABSOLUTE ha blitt plassert tilsvarende øverst på denne siden:

...position: relative; top: 0px; left:0px;
...position: relative; top: 0px; left:0px;
...position: relative; top: -150px; left:100px;
The first box
The second box
The third box

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

z-index: Stack order of the boxes

FRA: tagindex.net

div {
width: 200px;
height: 100px;
position: absolute;
}

#example1 {
z-index: 1;
background-color: #85b9e9;
top: 100px;
left: 50px;
}
#example2 {
z-index: 2;
background-color: #ffd78c;
top: 150px;
left: 200px;
}
#example3 {
z-index: 0;
background-color: #bde9ba;
top: 50px;
left: 150px;
}
<div id="example1">The first box</div>
<div id="example2">The second box</div>
<div id="example3">The third box</div>


SENTRERING

How to Use CSS to Center Images and Other HTML Objects

Fra: lifewire.com

Centering Text With CSS

.center {
  text-align: center;
}
<p class="center">This text is centered.</p>

This text is centered.

Centering Blocks of Content With CSS

.center {
  margin: auto;
  width: 20em;
}
<div>This entire block is centered, <br />
but the text inside it is left aligned.</div>
This entire block is centered,
but the text inside it is left aligned.

Centering Images With CSS

img.center {
  display: block;
  margin-left: auto;
  margin-right: auto;
}

Centering Elements Vertically With CSS (CSS3)

.vcenter {
  vertical-align: middle;
} 

Denne ligger i midten, vertikalt sett.


Sentrere inline elementer

PB: For å sentrere inline elementer må en gjøre dem om til block elementer med display: block;.

.span-center {
  margin: 0 auto;
  width: 50%;
  display: block;
  background-color:yellow;
} 
testing

Eksempel med Header og Nav

Fant denne på en side, som omhandlet problemer med sentrering. Her ligger det en artig liten bolk for sentrering av menylinker.

body {
  background: #f06d06;
}

header, nav {
  text-align: center;
  background: white;
  margin: 20px 0;
  padding: 10px;
}

nav a {
  text-decoration: none;
  background: #333;
  border-radius: 5px;
  color: white;
  padding: 3px 8px;
}
<header>
  This text is centered.
</header>

<nav role='navigation'>
  <a href="#0">One</a>
  <a href="#0">Two</a>
  <a href="#0">Three</a>
  <a href="#0">Four</a>
</nav>  
This text is centered.

11 Ways to Center Div or Text in Div in CSS

https://blog.hubspot.com/website/center-div-css

Using the Justify-Content Property

.center {
  display: flex;
  justify-content: center;
}
TH 1 TH 2 TH 3
1a 1b 1c
2a 2b 2c

Center testing

Sentrering av DIV med fullt innhold, uten å sentrere tekst innenfor.

TIPS: Legg innholdet i en DIV, og en DIV utenpå som sentrerer!

  • Coffee
  • Tea
  • Milk

How to Center a Div Horizontally

To center a div horizontally on a page, simply set the width of the element and the margin property to auto. That way, the div will take up whatever width is specified in the CSS and the browser will ensure the remaining space is split equally between the two margins.

.center {
 margin: auto;
 width: 40%;
}

PB: Tilpass breddens prosenter til innholdet.

Center testing

Sentrering av DIV med fullt innhold, uten å sentrere tekst innenfor.

TIPS: Legg innholdet i en DIV, og en DIV utenpå som senterer!

  • Coffee
  • Tea
  • Milk

How to Center Text in Div Vertically

.center {
padding: 50px 0;
}

Center testing

Sentrering av DIV med fullt innhold, uten å sentrere tekst innenfor.

TIPS: Legg innholdet i en DIV, og en DIV utenpå som senterer!

  • Coffee
  • Tea
  • Milk

Using the Line-Height Property

.center {
 line-height: 350px;
 height: 350px;
}
.center div {
 display: inline-block;
 line-height: normal;
 vertical-align: middle;
}

PB: Legges i hver sin DIV, utenpå hverandre. Den nederste var opprinnelig vist med P, ikke DIV. Måtte i tillegg øke verdien på høyden, som bør være større enn det som innholdet opptar.

Center testing

PB: Sentrering av DIV med fullt innhold, uten å sentrere tekst innenfor.

TIPS: Legg innholdet i en DIV, og en DIV utenpå som senterer!

  • Coffee
  • Tea
  • Milk

Using the Position, Top, Left, and Margin Properties

.parent {
 background: #CCCCCC;
 height: 200px;
 width: 200px;
 position: relative;
}
.child {
 background: #FFFF00;
 width: 70px;
 height: 70px;
 position: absolute;
 top: 50%;
 left: 50%;
 margin: -35px 0 0 -35px;
}
<div class="parent">
<div class="child">This div is centered vertically.</div> 
</div>

PB: Her har jeg i tillegg lagt til display: flex; og justify-content: center; på en egen ytre DIV, for å sentrere det hele horisontalt (de to indre DIV-boksene).

This div is centered vertically.

Sentrering UTEN bruk av FLEX og POSISJONERING

PB: Her er det en annen tilnærming. margin: 20px auto; sentrerer med AUTO, den ytre boksen. Og for sentrering av den indre PRE boksen, legges den i en egen DIV som sentreres. Deretter må innholdet tilbakestilles til VENSTRE.

<div style="width: 50%; margin: 20px auto;">
<div style="text-align: center;"> 
<pre style="display: inline-block; text-align: left;">
.multiple-gray-shadows-btm {
  box-shadow: 
  0 10px 0 -5px #be6700, 
  0 20px 0 -10px #66ccff, 
  0 30px 0 -16px #dedcb9;
}

Midt i midten

html, body, #wrapper {
   height:100%;
   width: 100%;
   margin: 0;
   padding: 0;
   border: 0;
}
#wrapper td {
   vertical-align: middle;
   text-align: center;
}
<table id="wrapper">
  <tr>
    <td>Plasser et bilde eller tekst - midt på siden - som gjelder i alle retninger</td>
  </tr>
</table>
Plasser et bilde eller tekst - midt på siden - som gjelder i alle retninger


TEKST - abbr

w3schools: HTML <abbr> Tag

Definition and Usage

The <abbr> tag defines an abbreviation or an acronym, like "HTML", "CSS", "Mr.", "Dr.", "ASAP", "ATM".

Tip: Use the global title attribute to show the description for the abbreviation/acronym when you mouse over the element.

<p>The <abbr title="World Health Organization">WHO</abbr> was founded in 1948.</p>

The WHO was founded in 1948.

<abbr> can also be used with <dfn> to define an abbreviation:

<p><dfn><abbr title="Cascading Style Sheets">CSS</abbr></dfn> 
is a language that describes the style of an HTML document.</p>

CSS is a language that describes the style of an HTML document.

Fra tutora.no

<abbr> står for abbreviation og kan brukes for å merke alle type forkortelser som for eksempel HTML.



TEKST - address

w3schools: HTML <address> Tag

The HTML <address> tag defines the contact information for the author/owner of a document or an article.

The contact information can be an email address, URL, physical address, phone number, social media handle, etc.

The text in the <address> element usually renders in italic, and browsers will always add a line break before and after the <address> element.

<address>
Written by John Doe.<br />
Visit us at:<br />
Example.com<br />
Box 564, Disneyland<br />
USA
</address>
Written by John Doe.
Visit us at:
Example.com
Box 564, Disneyland
USA


TEKST - align

w3schools: CSS Text Alignment

https://www.w3schools.com/css/css_text_align.asp

Text Alignment

Definition and Usage

The text-align property is used to set the horizontal alignment of a text.

A text can be left or right aligned, centered, or justified (PB: Se egen).

Example

h1 {
  text-align: center;
}

h2 {
  text-align: left;
}

h3 {
  text-align: right;
}

PB: Modfisert av meg.

text-align: center;

text-align: left;

text-align: right;



TEKST - b

w3schools: Text Color and Background Color

https://www.w3schools.com/tags/tag_b.asp

HTML <b> Tag

The <b> tag specifies bold text without any extra importance.

Note: According to the HTML5 specification, the <b> tag should be used as a LAST resort when no other tag is more appropriate. The specification states that headings should be denoted with the <h1> to <h6> tags, emphasized text should be denoted with the <em> tag, important text should be denoted with the <strong> tag, and marked/highlighted text should be denoted with the <mark> tag.

Tip: You can also use the following CSS to set bold text: "font-weight: bold;".

Example

p {
  font-weight:bold;
}

PB: Modifisert.

This is normal text - <b>and this is bold text</b>.

This is normal text - <span style="font-weight:bold;">and this is bold text</span>.


<b>

fra: http://html5doctor.com/

Represents a span of text to be stylistically offset from the normal prose without conveying any extra importance. Examples are key words in a document abstract, product names in a review, or other spans of text whose typical typographic presentation is bold.

The <b> element should be used as a last resort when no other element is more appropriate. In particular, headings should use the <h1> to <h6> elements, stress emphasis should use the <em> element, importance should be denoted with the <strong> element, and text marked or highlighted should use the <mark> element.

Deckard: The report would be routine retirement of a replicant which didn't make me feel any better about shooting a woman in the back. There it was again. Feeling, in myself. For her, for Rachael.


TEKST - blockquote

w3schools: HTML <blockquote> Tag

https://www.w3schools.com/tags/tag_blockquote.asp

Definition and Usage

The <blockquote> tag specifies a section that is quoted from another source.

Browsers usually indent <blockquote> elements (look at example below to see how to remove the indentation).

Tip: Use <q> or inline (short) quotations.

A short quotation example:

<p>WWF's goal is to: <q>Build a future where people live in harmony with nature.</q></p>

WWF's goal is to: Build a future where people live in harmony with nature.

The <cite> attribute specifies the source of a quotation.

Syntax

<blockquote cite="URL"> 

Possible values:

Tip: It's a good habit to always add the source of a quotation, if any.

The <cite> attribute does not render as anything special in any of the major browsers, but it can be used by search engines to get more information about the quotation.

Example

Use CSS to remove the indentation from the blockquote element:

blockquote {
  margin-left: 0;
}
<p>Here is a quote from WWF's website:</p>

<blockquote cite="http://www.worldwildlife.org/who/index.html">
For 50 years, WWF has been protecting the future of nature. 
The world's leading conservation organization, 
WWF works in 100 countries and is supported by 1.2 million members 
in the United States and close to 5 million globally.
</blockquote>

PB: Modifisert.

Here is a quote from WWF's website:

For 50 years, WWF has been protecting the future of nature. The world's leading conservation organization, WWF works in 100 countries and is supported by 1.2 million members in the United States and close to 5 million globally.
For 50 years, WWF has been protecting the future of nature. The world's leading conservation organization, WWF works in 100 countries and is supported by 1.2 million members in the United States and close to 5 million globally.

Blockquote

fra: http://html5doctor.com/

The blockquote element represents a section that is quoted from another source.

Content inside a blockquote must be quoted from another source, whose address, if it has one, may be cited in the cite attribute.

<blockquote>What we have here is a quotation from another source.</blockquote>
What we have here is a quotation from another source.

Diverse eksempler

fra: https://freefrontend.com/css-quote-styles/

Quote Container

body{background:#1D1F20;}
#ct{height:150px; width:370px;border:1px solid #f1c40f;
  margin: 100px auto;text-align:center;position:relative;
  color:#fff;padding:15px;}
span{
  background:#1D1F20;
  color:#f1c40f;
  padding:0 10px;
  font-size:20px;
  position:relative; 
  top:-28px;
}
.corner{height:30px;
  width:30px;
  border-radius:50%;
  border:1px solid #fff;
  transform:rotate(-45deg);  
  position:absolute;
  background:#1D1F20;
}

#left_top{
  top:-16px;
  left:-16px;
  border-color:transparent transparent #f1c40f transparent;
}
#right_top{
  top:-16px;
  right:-16px;
  border-color:transparent transparent transparent #f1c40f;
}
#left_bottom{
  bottom:-16px;
  left:-16px;
  border-color:transparent #f1c40f transparent transparent;
}
#right_bottom{
  bottom:-16px;
  right:-16px;
  border-color:#f1c40f transparent transparent transparent;
}
p{padding-top:13px;font-size:18px}
<div id="ct">
  <div class="corner "id="left_top"></div>
  <div class="corner" id="left_bottom"></div>
  <div class="corner" id="right_top"></div>
  <div class="corner" id="right_bottom"></div>
  <span>Winston Churchill</span>
  <blockquote>
    <p><i>“Success consists of going from failure 
	to failure without loss of enthusiasm.” </i></p>
  </blockquote>
</div>
Winston Churchill

“Success consists of going from failure to failure without loss of enthusiasm.”

fra: https://css-tricks.com/snippets/css/simple-and-nice-blockquote-styling/

Simple and Nice Blockquote Styling

blockquote {
  background: #f9f9f9;
  border-left: 10px solid #ccc;
  margin: 1.5em 10px;
  padding: 0.5em 10px;
  quotes: "\201C""\201D""\2018""\2019";
}
blockquote:before {
  color: #ccc;
  content: open-quote;
  font-size: 4em;
  line-height: 0.1em;
  margin-right: 0.25em;
  vertical-align: -0.4em;
}
blockquote p {
  display: inline;
}
<blockquote>
<p>
Pellentesque habitant morbi...
</p>
</blockquote>
LEGG INN ...

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.

https://isotropic.co/the-best-css-styling-for-blockquotes/

blockquote{
  display:block;
  background: #fff;
  padding: 15px 20px 15px 45px;
  margin: 0 0 20px;
  position: relative;
  
  /*Font*/
  font-family: Georgia, serif;
  font-size: 16px;
  line-height: 1.2;
  color: #666;
  text-align: justify;
  
  /*Borders - (Optional)*/
  border-left: 15px solid #c76c0c;
  border-right: 2px solid #c76c0c;
  
  /*Box Shadow - (Optional)*/
  -moz-box-shadow: 2px 2px 15px #ccc;
  -webkit-box-shadow: 2px 2px 15px #ccc;
  box-shadow: 2px 2px 15px #ccc;
}

blockquote::before{
  content: "\201C"; /*Unicode for Left Double Quote*/
  
  /*Font*/
  font-family: Georgia, serif;
  font-size: 60px;
  font-weight: bold;
  color: #999;
  
  /*Positioning*/
  position: absolute;
  left: 10px;
  top:5px;
}

blockquote::after{
  /*Reset to make sure*/
  content: "";
}
LEGG INN ...
Morbi placerat imperdiet risus quis blandit. Ut lobortis elit luctus, feugiat erat vitae, interdum diam. Nam sit amet arcu vitae justo lacinia ultricies nec eget tellus. Curabitur id sapien massa. In hac habitasse platea dictumst. Integer tristique leo consectetur libero pretium pretium. Nunc sed mauris magna. Praesent varius purus id turpis iaculis iaculis. Nulla convallis magna nunc, id rhoncus massa ornare in. Donec et feugiat sem, ac rhoncus mauris. Quisque eget tempor massa.
UNDER ARBEID modifisert

" Her har jeg laget en helt egen, inspirert av mange, og lekt med både gråfarger, float og shadows. Dette er da heller ikke lenger en sitering, men en test-info-tekst.



TEKST - br

<br>

fra: http://html5doctor.com/

The <br /> element represents a line break. <br /> elements must be used only for line breaks that are actually part of the content, as in poems or addresses. <br /> elements must not be used for separating thematic groups in a paragraph.

<br />


TEKST - characters

Heading med et TEGN FORAN

https://www.w3schools.com/cssref/css_entities.asp

Se også:

h2:before { content: ' \266B'; } <h2> Tekst</h2>

♫ Tekst

Den over er laget med CSS-code \266B. Det finnes en tilsvarende HTML-code (dec): &#9835;.

Bruk av Entity koder kan være mer sårbart med hensyn til web-browsers, eksempelvis:

¢ &cent; $ &dollar;&euro; > &gt; < &lt;   &nbsp; £ &pound; ¥ &yen; etc.

Det beste er å bruke HTML-koder, og med <meta charset="UTF-8"> så finnes de fleste der. Her er noen kjekt-å-ha:

! &#33;

# &#35;

% &#37;

& &#38;

/ &#47;

@ &#64;

[ &#91;

] &#93;

© &#169;

° &#176;

˂ &#706;

˃ &#707;

˄ &#708;

˅ &#709;

˯ &#751;

˰ &#752;

˱ &#753;

˲ &#754;

&#8226;

&#8259;

&#8364;

&#8451;

&#8452;

&#8453;

&#8470;

&#8634;

&#8635;

&#8656;

&#8657;

&#8658;

&#8659;

&#8660;

&#8672;

&#8673;

&#8674;

&#8675;

&#8728;

&#8743;

&#8744;

&#8882;

&#8883;

&#8896;

&#8897;

&#9650;

&#9652;

&#9654;

&#9655;

&#9656;

&#9657;

&#9658;

&#9659;

&#9660;

&#9662;

&#9664;

&#9666;

&#9698;

&#9699;

&#9700;

&#9701;

&#9733;

&#9734;

&#9742;

&#9743;

&#9744;

&#9745;

&#9746;

&#9754;

&#9755;

&#9756;

&#9757;

&#9758;

&#9759;

&#9760;

&#9761;

&#9763;

&#9759;

&#9786;

&#9787;

&#9833;

&#9834;

&#9835;

&#9836;

&#9837;

&#9838;

&#9839;

&#9856;

&#9857;

&#9858;

&#9859;

&#9860;

&#9861;

&#9919;

&#9940;

&#9985;

&#9986;

&#9987;

&#9988;

&#9989;

&#9993;

&#10003;

&#10004;

&#10005;

&#10006;

&#10007;

&#10060;

&#10062;

&#10084;

&#10098;

&#10099;

&#10102;

&#10103;

&#10104;

&#10105;

&#10106;

&#10107;

&#10108;

&#10109;

&#10110;

&#10111;

&#10112;

&#10113;

&#10114;

&#10115;

&#10116;

&#10117;

&#10118;

&#10119;

&#10120;

&#10121;

&#10122;

&#10123;

&#10124;

&#10125;

&#10126;

&#10127;

&#10128;

&#10129;

&#10130;

&#10131;


Some Useful HTML Character Entities

Tip: The non-breaking hyphen (&#8209;) is used to define a hyphen character (-) that does not break into a new line.

ResultDescriptionEntity NameEntity Number
non-breaking space&nbsp;&#160;
<less than&lt;&#60;
>greater than&gt;&#62;
&ampersand&amp;&#38;
"double quotation mark&quot;&#34;
'single quotation mark (apostrophe)&apos;&#39;
¢cent&cent;&#162;
£pound&pound;&#163;
¥yen&yen;&#165;
euro&euro;&#8364;
©copyright&copy;&#169;
®registered trademark&reg;&#174;


TEKST - cite

***********************

cite

fra: http://html5doctor.com/

The cite element represents the title of a work (e.g. a book, a paper, an essay, a poem, a score, a song, a script, a film, a TV show, a game, a sculpture, a painting, a theatre production, a play, an opera, a musical, an exhibition, a legal case report, etc). This can be a work that is being quoted or referenced in detail (i.e. a citation), or it can just be a work that is mentioned in passing.

A person's name is not the title of a work — even if people call that person a piece of work — and the element must therefore not be used to mark up people's names. (In some cases, the b element might be appropriate for names; e.g. in a gossip article where the names of famous people are keywords rendered with a different style to draw attention to them. In other cases, if an element is really needed, the span element can be used.)

My favourite book is Introducing HTML5 by Bruce and Remy

***********************

The HTML <cite> tag defines the title of a creative work (e.g. a book, a poem, a song, a movie, a painting, a sculpture, etc.).

The Scream by Edvard Munch. Painted in 1893.



TEKST - color

w3schools: Text Color and Background Color

https://www.w3schools.com/css/css_text.asp

Definition and Usage

The color property is used to set the color of the text.

With CSS, a color is most often specified by:

Note: For W3C compliant CSS: If you define the color property, you must also define the background-color property.

The default text color for a page is defined in the body selector.

Example

body {
  background-color: lightgrey;
  color: blue;
}

h3 {
  background-color: black;
  color: white;
}

This Heading is Black with White Text

This page has a grey background color and a blue text.

Another paragraph.



TEKST - contenteditable

ContentEditable is the native widget for editing rich text in a web browser.

<h2> To-Do List </h2>
<ul contenteditable="true">
 <li> Break mechanical cab driver.</li>
 <li> Drive to abandoned factory.</li>
 <li> Watch video of self.</li>
</ul>

To-Do List

<div contenteditable="true">
This text can be edited by the user.
</div>
This text can be edited by the user.

https://blog.frankmtaylor.com/2012/01/23/html5-contenteditable-and-css/

Yep, you can edit these words right now. Just go crazy and type whatever you want. The only thing you can’t do is create new HTML elements; everything you type into contenteditable is a text string.

https://codepen.io/GiorgioMalvone/pen/vHCds

<h2>Edit the text below!</h2>
<div>
<pre>
<style  spellcheck="false" contenteditable="true">
body{background-color:mediumseagreen; color:#F5F5F5;}
  
#styleMe{height:150px; width:150px; background-color:#ffab59;}
</style>
</pre>
</div>
<div id="styleMe">Try styling me! #styleMe</div>
body{
  font-family: 'Roboto', sans-serif;
}
h2{
  font-weight:100;
  text-align:center;
  margin-bottom:-1.2em;
}
style{
  white-space:pre-wrap; 
  display:block;
  outline:none;
  text-align: center;
  margin-top:4em;
  font-size:1.4em;
  height:3em;
}
#styleMe{
  display:block;
  text-align:center;
  line-height:1.3;
  font-size:1.2em;
  color:#34495e;
  margin:auto;
  margin-top:6em;
}
style[type="text/css"]{display: none;}

PB: Modifisert

Edit the text below!

Try styling me! #malvone_styleMe


TEKST - decoration

w3schools: CSS Text Decoration

https://www.w3schools.com/css/css_text_decoration.asp

Text Decoration

The text-decoration property is used to set or remove decorations from text.

The value text-decoration: none; s often used to remove underlines from links:

Example

a {
  text-decoration: none;
}

A link with no underline: W3Schools.com

The other text-decoration values are used to decorate text:

Example

h1 {
  text-decoration: overline;
}

h2 {
  text-decoration: line-through;
}

h3 {
  text-decoration: underline;
}

PB: Modifisert.

This is heading 3

This is heading 3

This is heading 3

Note: It is not recommended to underline text that is not a link, as this often confuses the reader.

w3schools: CSS text-decoration-style Property

Example

div.a {
  text-decoration-line: underline;
  text-decoration-style: solid;
}

div.b {
  text-decoration-line: underline;
  text-decoration-style: wavy;
}

div.c {
  text-decoration-line: underline;
  text-decoration-style: double;
}

div.d {
  text-decoration-line: overline underline;
  text-decoration-style: wavy;
}
<div class="a">This is some text with a solid underline.</div>
<br>
<div class="b">This is some text with a wavy underline.</div>
<br>
<div class="c">This is some text with a double underline.</div>
<br>
<div class="d">This is some text with a wavy over- and underline.</div>
<p><b>Note:</b> The text-decoration-line property is not 
supported in Edge prior 79.</p>
This is some text with a solid underline.

This is some text with a wavy underline.

This is some text with a double underline.

This is some text with a wavy over- and underline.

Note: The text-decoration-line property is not supported in Edge prior 79.


Fra developer.mozilla.org

<span>I'd far rather be 
<span style="text-decoration: underline overline rgb(255, 48, 40);">
happy than right</span> any day.</span>
I'd far rather be happy than right any day.

Kombinert. Kombinasjoner er også mulig:

<span style="text-decoration: line-through red wavy;">
<code>text-decoration: line-through red wavy</code>.</span>
text-decoration: line-through red wavy.


TEKST - del

w3schools: HTML <del> Tag

https://www.w3schools.com/tags/tag_del.asp

Definition and Usage

The <del> tag defines text that has been deleted from a document. Browsers will usually strike a line through deleted text.

Tip: Also look at the <ins> tag to markup inserted text.

A text with a deleted part, and a new, inserted part:

Example

del {
  color: #0000FF;
  background-color: yellow;
}

PB: Modifisert.

My favorite color is <del>blue</del> <ins>red</ins>!



TEKST - direction

w3schools: CSS Text Alignment

https://www.w3schools.com/css/css_text_align.asp

Text Direction

The direction and unicode-bidi properties can be used to change the text direction of an element:

Example

p.ex1 {
  direction: rtl;
  unicode-bidi: bidi-override;
}

This is the default text direction. (PB tillegg, testing: ♫ ✔)

This is right-to-left text direction. (PB tillegg, testing: ♫ ✔)

HTML <bdo>

The HTML <bdo> tag is used to override the current text direction:

BDO stands for Bi-Directional Override.

<bdo dir="rtl">This text will be written from right to left</bdo>
This text will be written from right to left
<bdo dir="rtl">Don't cheat by reading this in a mirror!</bdo>

Don't cheat by reading this in a mirror!


Text direction and unicode direction

tagindex.net

The direction property

Specifies the text direction.

Property Value Explanation
direction ltr from left to right (default)
rtl from right to left

The unicode-bidi property

Specifies the unicode direction.

Property Value Explanation
unicode-bidi normal normal direction (default)
embed embedding the direction property's value
bidi-override the direction property's value overrides the unicode direction
p { direction: rtl; }

.example1 { unicode-bidi: embed; }
.example2 { unicode-bidi: bidi-override; }
<p class="example1">The direction and unicode-bidi properties.</p>
<p class="example2">The direction and unicode-bidi properties.</p>

<p>The <span class="example1">direction and unicode-bidi</span> properties.</p>
<p>The <span class="example2">direction and unicode-bidi</span> properties.</p>
LEGG UT EKSEMPLET HER.....

TEKST - em

w3schools: HTML <em> Tag

https://www.w3schools.com/tags/tag_em.asp

The <em> tag is used to define emphasized text. The content inside is typically displayed in italic.

A screen reader will pronounce the words in <em> with an emphasis, using verbal stress.

Example

em {
  font-style: italic;
}

PB: Modifisert.

You <em>have</em> to hurry up!

We <span style="font-style: italic;">cannot</span> live like this.


<em>

Represents stress emphasis of its contents. The level of emphasis that a particular piece of content has is given by its number of ancestor em elements. The 'stress' being referred to is linguistic. If spoken, this stress would be emphasised pronunciation on a word that can change the nuance of a sentence.

<p>Call a doctor <em>now</em></p>

Call a doctor now



TEKST FONT

CSS Fonts

https://flaviocopes.com/css-fonts/

...If we add other properties, they need to be put in the correct order.

This is the order (rekkefølgen):

font: <font-stretch> <font-style> <font-variant> <font-weight> <font-size> <line-height> <font-family>;

Example:

body {
  font: italic bold 20px Helvetica;
}

section {
  font: small-caps bold 20px Helvetica;
}

Font

Sets all font properties

tagindex.net

The font property is a shorthand property for setting all font properties.

Example Code

p {
  font: italic normal bold 80%/150% "Century Gothic";
}

The values other than the font-size and font-family properties can be omitted.



Fra developer.mozilla.org

Font shorthand

Many font properties can also be set through the shorthand property font. These are written in the following order:

  1. font-style
  2. font-variant
  3. font-weight
  4. font-stretch
  5. font-size
  6. line-height
  7. font-family

Among all those properties, only font-size and font-family are required when using the font shorthand property.

A forward slash has to be put in between the font-size and line-height properties.

A full example would look like this:

font: italic normal bold normal 3em/1.5 Helvetica, Arial, sans-serif;


TEKST FONT - family

w3schools: CSS Web Safe Fonts

Best Web Safe Fonts for HTML and CSS

The following list are the best web safe fonts for HTML and CSS:

Note: Before you publish your website, always check how your fonts appear on different browsers and devices, and always use fallback fonts!

Commonly Used Font Fallbacks


30+ Best Web Safe Fonts for Your Next Design in 2021

https://kinsta.com/blog/web-safe-fonts/

PB: Plukket ut Recommended Font Stack, og fant egen for 'Franklin Gothic' som var mengelfull.


lifewire.com (2020): Web Safe Font Stacks

Sans Serif Web Safe Font Stacks

Sans serif text is good for reading on web pages because there are no serifs to get blurry on the screen.

font-family: Arial, Helvetica, sans-serif;
font-family: 'Arial Black', Gadget, sans-serif;
font-family: Impact, Charcoal, sans-serif;
font-family: 'MS Sans Serif', Geneva, sans-serif;
font-family: Tahoma, Geneva, sans-serif;
font-family: 'Trebuchet MS', Helvetica, sans-serif;
font-family: Verdana, Geneva, sans-serif;

Serif Web Safe Font Stacks

Serif fonts work great for headlines. The larger type of headlines means the serifs won't get blurry on monitors.

font-family: 'Book Antiqua', 'Palatino Linotype', Palatino, serif;
font-family: Bookman, serif;
font-family: Georgia, serif;
font-family: 'MS Serif', 'New York', serif;
font-family: 'Times New Roman', Times, serif;

Monospace Font Stacks

Monospace fonts are usually used to render code and other type styles that look best in a font where all the characters are the same width — like typewriter fonts.

font-family: Courier, monospace;
font-family: 'Courier New', Courier, monospace;
font-family: 'Lucida Console', Monaco, monospace;

Cursive Font Stacks

Cursive fonts can be difficult to read, and the most commonly found one on most systems (Comic Sans) is disliked by as many people as like it.

font-family: 'Comic Sans MS', cursive;

Fantasy Font Stacks

Like cursive fonts, fantasy fonts can be hard to read, and they are even less common across most systems. In fact, you may notice that I'm using the same font stack as one I used above in the sans serif category, that's because impact and charcoal are so distinctive that some people consider them fantasy fonts.

font-family: Impact, Charcoal, fantasy;

Fra en gammel norsk CSS2-oversikt:

Fonter

font-family
Ordnet liste av fontnavn
– nettleseren bruker den første som er tilgjengelig
Hensiktsmessig å avslutte med et generisk fontnavn
Sett fontnavn med mellomrom i anførselstegn: "Arial Black"
div.arial { font-family: Arial, Helvetica, sans-serif; }
font-size
Verdier: larger, smaller, eller spesifikk høyde
div.big { font-size: 5em; }
font-style
Verdier: normal eller italic
div.emph { font-style: italic; }
font-weight
Verdier: normal, lighter, bold, eller bolder
div.bolder { font-weight: bolder; }

The Ultimate List of Web-Safe HTML and CSS Fonts

blog.hubspot.com/website/web-safe-html-css-fonts (2020)

  1. Arial (sans-serif)
  2. Arial Black (sans-serif)
  3. Verdana (sans-serif)
  4. Tahoma (sans-serif)
  5. Trebuchet MS (sans-serif)
  6. Impact (sans-serif)
  7. Times New Roman (serif)
  8. Didot (serif)
  9. Georgia (serif)
  10. American Typewriter (serif)
  11. Andalé Mono (monospace) / Fin monospace fra Apple
  12. Courier (monospace)
  13. Lucida Console (monospace)
  14. Monaco (monospace)
  15. Bradley Hand (cursive)
  16. Brush Script MT (cursive)
  17. Luminari (fantasy)
  18. Comic Sans MS (cursive)
0123456789, fF, iI, mM, oO, æøå, ÆØÅ (Arial)
0123456789, fF, iI, mM, oO, æøå, ÆØÅ ('Arial Black')
0123456789, fF, iI, mM, oO, æøå, ÆØÅ (Verdana)
0123456789, fF, iI, mM, oO, æøå, ÆØÅ (Tahoma)
0123456789, fF, iI, mM, oO, æøå, ÆØÅ ('Trebuchet MS')
0123456789, fF, iI, mM, oO, æøå, ÆØÅ (Impact)
0123456789, fF, iI, mM, oO, æøå, ÆØÅ ('Times New Roman')
0123456789, fF, iI, mM, oO, æøå, ÆØÅ (Didot)
0123456789, fF, iI, mM, oO, æøå, ÆØÅ (Georgia)
0123456789, fF, iI, mM, oO, æøå, ÆØÅ ('American Typewriter')
0123456789, fF, iI, mM, oO, æøå, ÆØÅ ('Courier New')
0123456789, fF, iI, mM, oO, æøå, ÆØÅ ('Andale Mono')
0123456789, fF, iI, mM, oO, æøå, ÆØÅ ('Lucida Console')
0123456789, fF, iI, mM, oO, æøå, ÆØÅ (Monaco)
0123456789, fF, iI, mM, oO, æøå, ÆØÅ ('Bradley Hand')
0123456789, fF, iI, mM, oO, æøå, ÆØÅ ('Brush Script MT')
0123456789, fF, iI, mM, oO, æøå, ÆØÅ (Luminari)
0123456789, fF, iI, mM, oO, æøå, ÆØÅ ('Comic Sans MS')


TEKST FONT - size

font-size

PB: Har satt sammen litt fra nettstedet, fra andre og eget.

Har sett at det ofte resettes for både BODY, P etc. for så å styres kontrollert i stilsettingen.

Der settes det enten 100% eller 1em, slik at følgende kan benyttes helt uavhengig av hva som settes i CSS (% eller EM):

<p>font-size: 100%;</p>

The font size is 200%

The font size is 2em

The font size is 150%

The font size is 1.5em

The font size is 75%

The font size is 0.75em

The font size is smaller

The font size is x-small

The font size is larger

The font size is x-large

PB: Pass på arveligheten!!! Uavhengig om det er EM eller PROSENT.

<p>font-size: 100%;</p>

The font-size Property

This is some text.


The font-size Property (150%)

This is some text. (150%)


The font-size Property (1.5em;)

This is some text. (1.5em;)


Måleenheter

Pixel er en måleenhet som vi bruker til å forklare hvor stort et element skal være eller hvor det skal plasseres på siden. Hvis du endrer right fra 100px til 101px, så ser vi at den blir ikke flyttet veldig langt. Derfor gjør pixler det enklere for oss å designe nettsiden så detaljert vi vil.

Em er en måleenhet som vi låner fra typografi, som er handler om utsende på bokstaver og tekst. Én em er det samme som den gjeldende skriftstørrelsen. Legg merke til at på toppen av CSS-en, definerte vi font-size i body-taggen som 20px, så én em vil være 20px.


Størrelser


Fra developer.mozilla.org

/* <absolute-size> values */ font-size: xx-small; font-size: x-small; font-size: small; font-size: medium; font-size: large; font-size: x-large; font-size: xx-large; font-size: xxx-large; /* <relative-size> values */ font-size: smaller; font-size: larger; /* <length> values */ font-size: 12px; font-size: 0.8em; /* <percentage> values */ font-size: 80%; /* Global values */ font-size: inherit; font-size: initial; font-size: unset;


CSS - Measurement Units

Fra tutorialspoint.com

Unit Description Example
% Defines a measurement as a percentage relative to another value, typically an enclosing element. p {font-size: 16pt; line-height: 125%;}
cm Defines a measurement in centimeters. div {margin-bottom: 2cm;}
em A relative measurement for the height of a font in em spaces. Because an em unit is equivalent to the size of a given font, if you assign a font to 12pt, each "em" unit would be 12pt; thus, 2em would be 24pt. p {letter-spacing: 7em;}
ex This value defines a measurement relative to a font's x-height. The x-height is determined by the height of the font's lowercase letter x. p {font-size: 24pt; line-height: 3ex;}
in Defines a measurement in inches. p {word-spacing: .15in;}
mm Defines a measurement in millimeters. p {word-spacing: 15mm;}
pc Defines a measurement in picas. A pica is equivalent to 12 points; thus, there are 6 picas per inch. p {font-size: 20pc;}
pt Defines a measurement in points. A point is defined as 1/72nd of an inch. body {font-size: 18pt;}
px Defines a measurement in screen pixels. p {padding: 25px;}
vh 1% of viewport height. h2 { font-size: 3.0vh; }
vw 1% of viewport width h1 { font-size: 5.9vw; }
vmin 1vw or 1vh, whichever is smaller p { font-size: 2vmin;}

Responsive size

PB: Testet litt responsive, men det finnes alt for mange motstridende forslag, med diverse som muligens enda ikke er 100% etablert. En fra et forum var denne: font-size: calc(0.75em + 1vmin); tilsynelatende ok, men jeg tok den vekk igjen.

PB: Kom over diverse andre, som generelt konkluderer med at PX, faste låste verdier, anbefales minst, og bruk av EM, REM samt Viewports anbefales mest. Det skilles mellom responsive text og fluid text. Her er noen andre forslag, testet men ikke helt fornøyd:

html { font-size: 100% }

h1 {
  font-size: calc(1.3rem + 3.6vw);
}

Og denne:

:root {
  font-size: calc(16px + 3vw);
}

Samt følgende, som nærmet seg hva jeg var ute etter:

body {
  font-size: calc(14px + (26 - 14) * ((100vw - 300px) / (1600 - 300)));
}

100% Responsive Typography System using a Modular Scale

Så fant jeg denne, som falt i smak og fungerer tilsynelatende sømløst og bra, selv med alle mulige verdier på testsidene og uten å legge den i en DIV-container med class="main-ctnr":

/*------------------------------------*\
    100% Responsive Typography System using a Modular Scale
    Ricardo Zea
    Published Feb 18, 2019
    https://www.codementor.io/@ricardozea/100-responsive-typography-system-using-a-modular-scale-s5rhft58g
\*------------------------------------*/


body {
  font-family: Arial, Helvetica, sans-serif;
  font-size: calc(12px + 0.35vw); /* Responsive base font size */
  line-height: calc(12px + 1.05vw); /* Responsive Vertical Rhythm */
}

.main-ctnr {
  width: 100%; /* For small screens */
  max-width: 1140px; /* For large screens */
  margin: auto; /* Center the container in the viewport */
}

h1 {
  font-size: 1.912em;
  line-height: calc(18px + 1.8vw); /* Responsive Vertical Rhythm */
}

h2 {
  font-size: 1.616em;
  line-height: calc(18px + 1vw); /* Responsive Vertical Rhythm */
}

h3 {
  font-size: 1.471em;
  line-height: calc(18px + 0.7vw); /* Responsive Vertical Rhythm */
}

h4 { font-size: 1.3em; }
h5 { font-size: 1.243em; }
h6 { font-size: 1.132em; }

h4, h5, h6 { 
  line-height: calc(18px + .2vw); /* Responsive Vertical Rhythm */
}

h1, h2, h3, h4, h5, h6 {
  margin: calc(12px + 1.05vw) 0; /* Responsive margins */
}


TEKST FONT - weight

PB: En test også på FONT-WEIGHT, der 400 er NORMAL og maks 900 tilsvarer BOLD.

<p>font-weight: 400;</p>

The font weight is BOLD (900)

The font weight is BOLD (900)

The font weight is 100

The font weight is 100

The font weight is 400

The font weight is 400

The font weight is 600

The font weight is 600

M1 M2 M3 M4 M5 M6 M7 M8 M9


TEKST <h1> - <h6>

Headings Are Important

Search engines use the headings to index the structure and content of your web pages.

Note:Use HTML headings for headings only. Don't use headings to make text BIG or bold.

<h1>Heading</h1>

<p>This is a paragraph.</p>

<h2>Heading</h2>

<p>This is a paragraph.</p>

<h3>Heading</h3>

<p>This is a paragraph.</p>

<h4>Heading</h4>

<p>This is a paragraph.</p>

<h5>Heading</h5>

<p>This is a paragraph.</p>

<h6>Heading</h6>

<p>This is a paragraph.</p>

SEO-tips: Heading tags for logical content creation with only one h1 per page!


Fra studocu.com

Overskrifter
- Seks ulike nivåer med overskrifter: <h1> til <h6>.
- Bruk overskrifter hierarkisk etter dokumentets struktur.
- start med <h1> - hopp aldri over nivåer!.

Viktige elementer

https://www.tutora.no/viktige-elementer/

Overskrifter i HTML er delt inn i 6 nivåer fra h1 til h6. De er ikke rangert etter størrelse men etter hvor viktige de er for resten av teksten. Noen overskrifter er bare underoverskrifter mens andre er for å dele inn i kapitler eller seksjoner.

Hvis du ser for deg en av lærebøkene dine så har den en hovedtittel, som da vil være den viktigste. Det er navnet på boka og står først på forsiden. Det er en h1-overskrift. Under hovedtittelen er boken delt inn i flere kapitler som har hver sin tittel. De kan for eksempel være h2-overskrifter. Inne i hvert kapittel er teksten delt opp i forskjellige seksjoner for at det skal bli lettere å lese. Det kan for eksempel være h3-overskrifter.

Diverse eksempler funnet her og der, og egne tester

h2 {
color: #999999;
font-family: arial, sans-serif;
font-size: 16px;
font-weight: bold;
margin-top: 0px;
margin-bottom: 1px;
}

Head 2 tekst

h2 { margin-top: 0px; margin-bottom: 1px; }

Head 2 margins i topp og bunn

h2.test1 {
  font-family: Georgia, sans-serif;
  font-size: 5em;
  letter-spacing: -2px;
}

test1

h2.test2 {
  font-family: "Trebuchet MS", sans-serif;
  font-size: 5em;
  letter-spacing: -2px;
  border-bottom: 2px solid black;
  text-transform: uppercase;
}

test2

h2.test3 {
  font-family: "Arial Black", sans-serif;
  font-size: 4.5em;
  letter-spacing: -1px;
  background-color: black;
  color: white;
}

test3

<h2 style="font-family:verdana;">This is a heading</h2>
<p style="font-family:courier;">This is a paragraph.</p>

This is a heading

This is a paragraph.

<h2 style="font-size:300%;">This is a heading</h2>
<p style="font-size:160%;">This is a paragraph.</p>

This is a heading

This is a paragraph.

<h2 style="text-align:center;">Centered Heading</h2>
<p style="text-align:center;">Centered paragraph.</p>

Centered Heading

Centered paragraph.

<h2 style="text-align:right;">Right Heading</h2>
<p style="text-align:right;">Right paragraph.</p>

Right Heading

Right paragraph.



TEKST - i

w3schools: HTML <i> Tag

https://www.w3schools.com/tags/tag_i.asp

The <i> tag defines a part of text in an alternate voice or mood. The content inside is typically displayed in italic.

The <i> tag is often used to indicate a technical term, a phrase from another language, a thought, a ship name, etc.

Use the <i> element only when there is not a more appropriate semantic element, such as:

Example

i {
  font-style: italic;
}

PB: Modifisert.

<i>Lorem ipsum</i> is the most popular filler text in history.

The <span style="font-style: italic;">RMS Titanic</span>, a luxury steamship, sank on April 15, 1912 after striking an iceberg.


<i>

Represents a span of text in an alternate voice or mood, or otherwise offset from the normal prose, such as a taxonomic designation, a technical term, an idiomatic phrase from another language, a thought, a ship name, or some other prose whose typical typographic presentation is italicized.

Only use i when nothing more suitable is available — e.g., <em> for text with stress emphasis, <strong> for text with semantic importance, <cite> for titles in a citation or bibliography, <dfn> for defining a word, and <var> for mathematical variables.



TEKST - indent

w3schools: Text Indentation

https://www.w3schools.com/css/css_text_spacing.asp

Text Transformation

The text-indent property is used to specify the indentation of the first line of a text:

Example

p {
  text-indent: 50px;
}

In my younger and more vulnerable years my father gave me some advice that I've been turning over in my mind ever since. 'Whenever you feel like criticizing anyone,' he told me, 'just remember that all the people in this world haven't had the advantages that you've had.'

p {
  text-indent: 1cm;
}

Denne har jeg satt opp for test med andre måleenheter. Her er det brukt cm fremfor px som måleenhet. Teksten ligger i en ramme satt til 50%, for å vise effekten på større skjermer.



TEKST - ins

w3schools: HTML <ins> Tag

https://www.w3schools.com/tags/tag_ins.asp

Definition and Usage

The <ins> tag defines a text that has been inserted into a document. Browsers will usually underline inserted text.

Tip: Also look at the <del> tag to markup deleted text.

Example

A text with a deleted part, and a new, inserted part:

ins {
  color: #FF0000;
  background-color: yellow;
}

PB: Modifisert.

My favorite color is <del>blue</del> <ins>red</ins>!


Funnet annet sted:

The ins element represents an addition to the document. The ins elements should not cross implied paragraph boundaries.

<p>My favourite colour is 
<del datetime="2010-10-11T01:25-07:00">blue</del> 
<ins datetime="2010-10-11T01:25-07:01">red</ins>, 
but I also like green and yellow.</p>

My favourite colour is blue red, but I also like green and yellow.


Kom over denne, et sted:

P og FONT eksempel med blå BORDER-linje midt igjennom teksten, modifisert fargene på fremvisningen.

<!DOCTYPE html>
<html>
<head>
<style>
p {
   font: oblique 5deg small-caps bold 1.3em/0.5px cursive;
   border: 3px solid lightcyan;
}
</style>
</head>
<body>
<p>This is demo text</p>
<p>This is another demo text</p>
</body>
</html>

This is demo text

This is another demo text


Kom over dette, et sted:

Kom over noen triks for å få egen underline på H1:

body {
  background: #fafafa;
  line-height: 1.5;
  font-family: "Arial";
  padding: 4rem;
}

.wrapper {
  max-width: 800px;
  padding: 0 1rem;
  margin: 0 auto;
}

.title {
  margin: 0 auto;
  font-size: 1.5rem;
  font-weight: bold;
  width: fit-content;
  border-bottom: 3px solid #e2deed;
}

* {
  box-sizing: border-box;
}
<div class="wrapper">
  <h1 class="title">A title for an awesome article</h1>
</div>

A title for an awesome article

PB: Modifisert. Erstattet den mer diskret underlinjen og presenterer at header heller ikke har noen marger. Størrelsen er også låst, uavhengig av om en setter H1 eller H4.

.pb-title {
  margin: 0 auto;
  font-size: 1.5rem;
  font-weight: bold;
  width: fit-content;
  border-bottom: 3px solid #00FF00;
}

CSS eksemplets hoved-enhet.



TEKST - justify

w3schools: CSS Text Alignment

https://www.w3schools.com/css/css_text_align.asp

Justify

When the text-align property is set to "justify", each line is stretched so that every line has equal width, and the left and right margins are straight (like in magazines and newspapers).

Example

div {
  border: 1px solid black;
  padding: 10px;
  width: 200px;
  height: 200px;
  text-align: justify;
}
In my younger and more vulnerable years my father gave me some advice that I've been turning over in my mind ever since. 'Whenever you feel like criticizing anyone,' he told me, 'just remember that all the people in this world haven't had the advantages that you've had.'


TEKST - letter-spacing

w3schools: Letter Spacing

https://www.w3schools.com/css/css_text_spacing.asp

Letter Spacing

The letter-spacing property is used to specify the space between the characters in a text.

The following example demonstrates how to increase or decrease the space between characters:

Example

h1 {
  letter-spacing: 3px;
}

h2 {
  letter-spacing: -3px;
}

PB: Modifisert

This is heading 3

This is heading 3



TEKST - line-height

w3schools: Line Height

https://www.w3schools.com/css/css_text_spacing.asp

Line Height

The line-height property is used to specify the space between lines.

Example

p.small {
  line-height: 0.7;
}

p.big {
  line-height: 1.8;
}
<p>
This is a paragraph with a standard line-height.<br>
The default line height in most browsers is about 110% to 120%.<br>
</p>

This is a paragraph with a standard line-height.
The default line height in most browsers is about 110% to 120%.

<p class="small">
This is a paragraph with a smaller line-height.<br>
This is a paragraph with a smaller line-height.<br>
</p>

This is a paragraph with a smaller line-height.
This is a paragraph with a smaller line-height.

<p class="big">
This is a paragraph with a bigger line-height.<br>
This is a paragraph with a bigger line-height.<br>
</p>

This is a paragraph with a bigger line-height.
This is a paragraph with a bigger line-height.


lifewire.com (2020): Values of CSS Line Spacing

CSS line spacing is affected by the CSS style property line-height. This property takes up to 5 different values:

Which Value Should You Use for CSS Line Spacing

In most cases, the best choice for line spacing is to leave it at the default or "normal." This is generally the most readable and doesn't require that you do anything special. But changing the line spacing can give your text a different feel to it.

If your font size is defined as ems or percentages, your line-height should also be defined that way. This is the most flexible form of line spacing because it allows the reader to resize their fonts and keeps the same ratio on your line spacing.



TEKST - mark

w3schools: HTML <mark> Tag

https://www.w3schools.com/tags/tag_mark.asp

Definition and Usage

The <mark> tag defines text that should be marked or highlighted.

Most browsers will display the <mark> element with the following default values:

mark {
  background-color: yellow;
  color: black;
}

Example

The HTML <mark> element defines text that should be marked or highlighted:

Do not forget to buy <mark>milk</mark> today.



TEKST - overflow

w3schools: CSS text-overflow Property

https://www.w3schools.com/cssref/css3_pr_text-overflow.asp

Definition and Usage

The text-overflow property specifies how overflowed content that is not displayed should be signaled to the user. It can be clipped, display an ellipsis (...), or display a custom string.

Both of the following properties are required for text-overflow:

Example

div.a {
  white-space: nowrap; 
  width: 50px; 
  overflow: hidden;
  text-overflow: clip; 
  border: 1px solid #000000;
}

div.b {
  white-space: nowrap; 
  width: 50px; 
  overflow: hidden;
  text-overflow: ellipsis; 
  border: 1px solid #000000;
}

div.c {
  white-space: nowrap; 
  width: 50px; 
  overflow: hidden;
  text-overflow: "----"; 
  border: 1px solid #000000;
}

div.d {
  white-space: nowrap; 
  width: 100px; 
  overflow: hidden;
  text-overflow: ellipsis;
  border: 1px solid #000000;
}

div.d:hover {
  overflow: visible;
}
<p>The following two divs contains a text that will not fit in the box.</p>

<h2>text-overflow: clip (default):</h2>
<div class="a">Hello world!</div>

<h2>text-overflow: ellipsis:</h2>
<div class="b">Hello world!</div>

<h2>text-overflow: "----" (user defined string):</h2>
<div class="c">Hello world!</div>

<p><strong>Note:</strong> The text-overflow: "<em>string</em>" only works in 
Firefox.</p>

<p>Hover over the div below, to see the entire text.</p>

<div class="d">This is some long text that will not fit in the box.</div>

The following two divs contains a text that will not fit in the box.

text-overflow: clip (default):

Hello world!

text-overflow: ellipsis:

Hello world!

text-overflow: "----" (user defined string):

Hello world!

Note: The text-overflow: "string" only works in Firefox.

Hover over the div below, to see the entire text.

This is some long text that will not fit in the box.


TEKST - samp

HTML <samp> For Program Output

The HTML <samp> element is used to define sample output from a computer program. The content inside is displayed in the browser's default monospace font.

<p>Message from my computer:</p>
<p><samp>File not found.<br />
Press F1 to continue</samp></p>

Message from my computer:

File not found.
Press F1 to continue



TEKST - shadow

w3schools: CSS text-shadow Property

https://www.w3schools.com/cssref/css3_pr_text-shadow.asp

The text-shadow property adds shadow to text.

This property accepts a comma-separated list of shadows to be applied to the text.

Note: To add more than one shadow to the text, add a comma-separated list of shadows.

CSS Syntax

text-shadow: h-shadow v-shadow blur-radius color|none|initial|inherit;

Property Values

Value Description
h-shadow Required. The position of the horizontal shadow. Negative values are allowed
v-shadow Required. The position of the vertical shadow. Negative values are allowed
blur-radius Optional. The blur radius. Default value is 0
color Optional. The color of the shadow.
none Default value. No shadow
initial Sets this property to its default value.
inherit Inherits this property from its parent element.

Eksempler

h1 {
  text-shadow: 2px 2px #FF0000;
}

Eksempel med shadow på H1 tekst.

h1.skygger {
  text-shadow: 2px 2px 5px red;
}

Eksempel med shadow på H1 tekst.

h1 {
  text-shadow: 2px 2px 8px #FF0000;
}

Eksempel med shadow på H1 tekst.

h1 {
  color: white;
  text-shadow: 2px 2px 4px #000000;
}

Eksempel med shadow på H1 tekst.

h1 {
  color: black;
  text-shadow: 3px 3px 5px #888;
}

Eksempel med shadow på H1 tekst.

h1 {
  text-shadow: 0 0 3px #FF0000;
}

Eksempel med shadow på H1 tekst.

h1 {
  text-shadow: 5px 5px 10px black;
}

Eksempel med shadow på H1 tekst.

h1 {
  text-shadow:4px 4px 8px blue;
}

Eksempel med shadow på H1 tekst.

h1 {
  text-shadow: 0 0 3px #FF0000, 0 0 5px #0000FF;
}

Eksempel med shadow på H1 tekst.

.glows {
  text-shadow: 0 0 4px #00FF9C;
}

Eksempel med shadow på H1 tekst.

.tofargede {
  color: white;
  text-shadow: 0 0 3px #F10D58, 0 0 7px #4578D5;
}

Eksempel med shadow på H1 tekst.

Annet kult eksempel

SHADOW-effekt som fungerer i Edge! Teksten i første har en blå skygge som kan justeres i posisjon. Den andre har en ramme rundt med en utflytende skygge-effekt. DIV er nokså standard BAKGRUNNS-effekt.

<!DOCTYPE html>
<html>
<head>
<style>
p {
   font: 1.6em arial;
   text-shadow: -3px -12px lightblue;
}
p + p {
   font: italic bold 12px/30px menu;
   text-shadow: unset;
   box-shadow: 0 0 5px 1px black;
}
div {
   width: 30%;
   font-size: 1.4em;
   font-family: cursive;
   background-color: tomato;
}
</style>
</head>
<body>
<h2>Demo Heading</h2>
<p>This is demo text</p>
<p>This text is for demo and included here to display different font styles in CSS.</p>
<div>Another text with different font style.</div>
</body>
</html>

This is demo text

This text is for demo and included here to display different font styles in CSS.

Another text with different font style.

Bruk av display:inline slik at tekst som utvides linjevis, havner i hver sin boks

h1
{
  font-size: 32px;
  line-height: 150px;
  text-shadow: -1px -1px #fb6, 1px 1px #d60, -3px 0 4px #000;
  font-family:"Segoe print", Arial, Helvetica, sans-serif;
  color: #FF9933; 
  padding:32px;
  font-weight:lighter;
  -moz-box-shadow: 2px 2px 6px #888;  
  -webkit-box-shadow: 2px 2px 6px #888;  
  box-shadow:2px 2px 6px #888;  
  text-align:center;
  display:inline;
}

Dette er en interessant skyggetesting, med isolerte bokser som følger teksten linjevis

css-tricks: Adding Stroke to Web Text

https://css-tricks.com/adding-stroke-to-web-text/

@import url('https://fonts.googleapis.com/css?family=Notable&display=swap');

body {
  font: 40px/1 'Notable', sans-serif;
  margin: 1rem;
}

h1 {
  margin: 0;
/*   animation: colorchange 2s infinite; */
}
h1.bonus {
  text-shadow:
     3px  3px 0 #000,
    -1px -1px 0 #000,  
     1px -1px 0 #000,
    -1px  1px 0 #000,
     1px  1px 0 #000;
}

@supports (-webkit-text-stroke: 1px black) {
  h1 {
    -webkit-text-stroke: 1px black;
    -webkit-text-fill-color: white;
  }
}

/* @keyframes colorchange {
  0% {
    -webkit-text-stroke: 10px red;
  }
  100% {
    -webkit-text-stroke: 20px green;
  }
} */
<h1>
  STROKE OF GENIUS
</h1>

<h1 class="bonus">
  STROKE OF GENIUS
</h1>

STROKE OF GENIUS

STROKE OF GENIUS

Buttons - Simple CSS for buttons.

Fra (purecss.io/buttons/)

.pure-button {
  color: white;
  border-radius: 4px;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);
}

.button-success {
  background: rgb(28, 184, 65);
  /* this is a green */
}

.button-error {
  background: rgb(202, 60, 60);
  /* this is a maroon */
}

.button-warning {
  background: rgb(223, 117, 20);
  /* this is an orange */
}

.button-secondary {
  background: rgb(66, 184, 221);
  /* this is a light blue */
}
<div>
  <button class="button-success pure-button">Success Button</button>
  <button class="button-error pure-button">Error Button</button>
  <button class="button-warning pure-button">Warning Button</button>
  <button class="button-secondary pure-button">Secondary Button</button>
</div>

PB: Modifisert



TEKST - small

w3schools: HTML <small> Tag

https://www.w3schools.com/tags/tag_small.asp

The <small> tag defines smaller text (like copyright and other side-comments).

Tip: This tag is not deprecated, but it is possible to achieve richer (or the same) effect with CSS.

Most browsers will display the <small> element with the following default values:

small {
  font-size: smaller;
}

Example

span.small {
  font-size: smaller;
}
<p>This is some normal text.</p>
<p><span class="small">This is some smaller text.</span></p>

PB: Modifisert.

This is some normal text.

This is some smaller text.

This is some small text.


small

Represents side comments such as small print. It is not intended to be presentational. The small element should not be used for extended spans of text such as multiple paragraphs, lists, or sections of text. It is only intended for short runs of text.

<footer> <address> For more details, contact <a href="mailto:hello@html5doctor.com">HTML5 Doctor</a>. </address> <small> © copyright HTML5 Doctor.</small> </footer>


TEKST - strong

w3schools: HTML <strong> Tag

https://www.w3schools.com/tags/tag_strong.asp

The <strong> tag is used to define text with strong importance. The content inside is typically displayed in bold.

Use the <b> tag to specify bold text without any extra importance!

Example

strong { 
  font-weight: bold;
}

PB: Modifisert.

This text is normal.

<strong>This text is important!</strong>

<span style="font-style: bold;">This text is important!</span>.


<strong> (STRONG)

The HTML <strong> element defines text with strong importance. The content inside is typically displayed in bold.

Represents strong importance for its contents. Indicate relative importance by nesting strong elements; each strong element increases the importance of its contents. Changing the importance of a piece of text with the strong element does not change the meaning of the sentence.

<p><strong>Warning</strong>. 
This dungeon is dangerous. 
<strong>Avoid the ducks.</strong> 
Take any gold you find.</p>

Warning. This dungeon is dangerous. Avoid the ducks. Take any gold you find.



TEKST - sub

w3schools: HTML <sub> Tag

https://www.w3schools.com/tags/tag_strong.asp

Definition and Usage

The <sub> tag defines subscript text (Senket skrift). Subscript text appears half a character below the normal line, and is sometimes rendered in a smaller font. Subscript text can be used for chemical formulas, like H2O.

Tip: Use the <sup> tag to define superscripted text.

Most browsers will display the <sup> element with the following default values:

Example

sub {
  vertical-align: sub;
  font-size: smaller;
}

This text contains <sub>subscript</sub> text.

Kom over denne, et sted:

.sub {
  vertical-align:sub
}

Denne H2O har standard bokstaver, i motsetning til H2O som er i en <sub>.



TEKST - sup

w3schools: HTML <sup> Tag

https://www.w3schools.com/tags/tag_sup.asp

Definition and Usage

The <sup> tag defines superscript text (Hevet skrift). Superscript text appears half a character above the normal line, and is sometimes rendered in a smaller font. Superscript text can be used for footnotes, like WWW[1].

Tip: Use the <sub> tag to define subscript text.

Most browsers will display the <sup> element with the following default values:

Example

sup {
  vertical-align: super;
  font-size: smaller;
}

Med CSS (default)

This text contains <sup>superscript text</sup> text. Today is the 2nd of May.

Vanlig visning

This text contains <sup>superscript text</sup> text. Today is the 2nd of May.



TEKST - transform

w3schools: CSS Text Transformation

https://www.w3schools.com/css/css_text_transformation.asp

Text Transformation

The text-transform property is used to specify uppercase and lowercase letters in a text.

It can be used to turn everything into uppercase or lowercase letters, or capitalize the first letter of each word:

Example

p.uppercase {
  text-transform: uppercase;
}

p.lowercase {
  text-transform: lowercase;
}

p.capitalize {
  text-transform: capitalize;
}
<p class="uppercase">This is some text.</p>
<p class="lowercase">This is some text.</p>
<p class="capitalize">This is some text.</p>

This is some text (uppercase).

This is some text (lowercase).

This is some text (capitalize).

The font-variant-caps Property

PB: Det finnes en ny (CCS3) variant, som muligens fortsatt ikke støttes av (kun) Safari:

p.small {font-variant-caps: small-caps;}
<p class="small">Mitt navn er Petrus. Jeg bor i Grimstad.</p>

Mitt navn er Petrus. Jeg bor i Grimstad.



TEKST - white-space

w3schools: CSS white-space Property

https://www.w3schools.com/cssref/pr_text_white-space.asp

Definition and Usage

The white-space property specifies how white-space inside an element is handled.

Property Values

normal
- Sequences of whitespace will collapse into a single whitespace. Text will wrap when necessary. This is default.
nowrap
- Sequences of whitespace will collapse into a single whitespace. Text will never wrap to the next line. The text continues on the same line until a <br> tag is encountered.
pre
- Whitespace is preserved by the browser. Text will only wrap on line breaks. Acts like the <pre> tag in HTML.
pre-line
- Sequences of whitespace will collapse into a single whitespace. Text will wrap when necessary, and on line breaks.
pre-wrap
- Whitespace is preserved by the browser. Text will wrap when necessary, and on line breaks.
initial
- Sets this property to its default value.
inherit
- Inherits this property from its parent element.

Example

Demonstrate different values of the white-space property:

p.a {
  white-space: nowrap;
}
<h2>white-space: nowrap:</h2>
<p class="a">
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
</p>

white-space: nowrap:

This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text.

p.b {
  white-space: normal;
}
<h2>white-space: normal:</h2>
<p class="b">
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
</p>

white-space: normal:

This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text.

p.c {
  white-space: pre;
}
<h2>white-space: pre:</h2>
<p class="c">
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
</p>

white-space: pre:

This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text.

white-space: pre

PB: Denne er meget NYTTIG, som alternativ til PRE.

ALTERNATIV TIL <PRE> <p style="white-space: pre;"> This text has a line break and the white-space pre setting tells the browser to honor it just like the HTML pre tag.</p>



TEKST - word-break

w3schools: CSS word-break Property

https://www.w3schools.com/cssref/css3_pr_word-break.asp

Definition and Usage

The word-break property specifies how words should break when reaching the end of a line.

Property Values

normal
- Default value. Uses default line break rules.
break-all
- To prevent overflow, word may be broken at any character.
keep-all
- Word breaks should not be used for Chinese/Japanese/Korean (CJK) text. Non-CJK text behavior is the same as value "normal".
break-word
- To prevent overflow, word may be broken at arbitrary points.
initial
- Sets this property to its default value.
inherit
- Inherits this property from its parent element.

Example

Break words at any character:

p {
  width: 140px; 
  border: 1px solid #000000;
}

p.a {
  word-break: normal;
}

p.b {
  word-break: keep-all;
}

p.c {
  word-break: break-all;
}

word-break: normal (default), Thisissomeveryveryverylong word. Words will break according to usual rules.


word-break: keep-all, Thisissomeveryveryverylong word. This text will-break-at-hyphens.


word-break: break-all, Thisissomeveryveryverylong word. This text will break at any character.


Word Break

https://css-tricks.com/almanac/properties/w/word-break/

The word-break property in CSS can be used to change when line breaks ought to occur. Normally, line breaks in text can only occur in certain spaces, like when there is a space or a hyphen.

In the example below we can make the word-break between letters instead:

p {
  word-break: break-all;
}

If we then set the width of the text to one em, the word will break by each letter:

.txt {
  word-break: break-all;
  line-height: 1;
  text-transform: uppercase;
  text-align: center;
  font-size: 40px;
  font-weight: bold;
  color: #eee;
  width: 1em;
}

html, body {
  height: 100%;
}

body {
  font-family: Palatino, serif;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #0074d9;
}
<h1 class="txt">Marco</h1>

Marco

This value is often used in places with user generated content so that long strings don’t risk breaking the layout. One very common example is a long copy and pasted URL. If that URL has no hyphens, it can extend beyond the parent box and look bad or worse, cause layout problems.

.txt {
  line-height: 1.3;
  font-size: 16px;
  width: 500px;
  background-color: #eee;
  padding: 10px;
}

.break {
  word-break: break-all;
}

html, body {
  height: 100%;
}

body {
  font-family: Palatino, serif;
}
<p class="txt">
  By default links will 'break' through the containing wrapper element: 
  <a href="#">www.abdpaoeg[apeoaepogjapeojgpaokcojaoejpfjaepofjapoefjapefjapeapceuhja[ekg.com</a> 
  if you are interested in more information.
</p>

<p class="txt">
  Alternatively we can make the link break with the word-break property: 
  <a href="#" class="break">www.abdpaoeg[apeoaepogjapeojgpaokcojaoejpfjaepofjapoefjapefjapeapceuhja[ekg.com</a> 
  if you are interested in more information.
</p>

By default links will 'break' through the containing wrapper element: www.abdpaoeg[apeoaepogjapeojgpaokcojaoejpfjaepofjapoefjapefjapeapceuhja[ekg.com if you are interested in more information.

Alternatively we can make the link break with the word-break property: www.abdpaoeg[apeoaepogjapeojgpaokcojaoejpfjaepofjapoefjapefjapeapceuhja[ekg.com if you are interested in more information.

Values

This property is also often used in conjunction with the hyphens property so that when breaks occur a hypen is inserted, as per the standard in books.

The full usage, with needed vendor prefixes, is:

-ms-word-break: break-all;
    word-break: break-all;

/* Non standard for WebKit */
    word-break: break-word;

-webkit-hyphens: auto;
   -moz-hyphens: auto;
        hyphens: auto;

Using these properties on the universal selector can be useful if you have a site with a lot of user-generated content. Although fair warning, it can look weird on titles and pre-formatted text (<pre>).



TEKST - word-spacing

w3schools: CSS word-spacing Property

https://www.w3schools.com/cssref/pr_text_word-spacing.asp

Definition and Usage

The word-spacing property increases or decreases the white space between words.

Note: Negative values are allowed.

Property Values

normal
- Defines normal space between words (0.25em). This is default.
length
- Defines an additional space between words (in px, pt, cm, em, etc). Negative values are allowed.
initial
- Sets this property to its default value.
inherit
- Inherits this property from its parent element.

Example

Specify that the space between words in <p> elements should be 30 pixels:

p.a { 
  word-spacing: normal;
}

p.b { 
  word-spacing: 30px;
}

p.c { 
  word-spacing: 1cm;
}

p.d { 
  word-spacing: -5px;
}

PB: Modifisert

word-spacing: normal, This is some text.

word-spacing: 30px, This is some text.

word-spacing: 1cm, This is some text.

word-spacing: -5px, This is some text.


Word Spacing

Fra css-tricks.com

The word-spacing property is similar to letter-spacing, though naturally its use governs the amount of space between the words in a piece of text, not the individual characters.

p {
  word-spacing: 2em;
}

word-spacing can receive three different values:

  1. the “normal” keyword, which resets the default spacing
  2. length values using any CSS units (most commonly px, em, rem)
  3. the “inherit” keyword, which applies the word-spacing of the parent element

Best practice at this time would be to use em. Font size can be adjusted, so using pixels for this could cause problems at the spacing between words wouldn’t scale as their size did. rem is great usually, but browser support is lower and in this use case it’s probably best the spacing is relevant directly to the words it is being applied to, not the root.

It is important to note that “word” in this context actually refers a singular piece of inline content—which means that word-spacing affects inline-block elements as well as inline elements. In this example, several such elements are spaced by setting the word-spacing of their parent container:

.wrap {
  word-spacing: 1em;
  padding: 1em 0 0;
}
.module {
  background: lightsteelblue;
  height: 5em;
  width: 5em;
  display: inline-block;
  /* reset word-spacing so that text inside this box is spaced normally */
  word-spacing: normal;
}
<div class="wrap">
  <div class="module"></div>
  <div class="module"></div>
  <div class="module"></div>
  <div class="module"></div>
</div>
Hei. Jeg har litt tekst i denne boksen her.
Hei. Jeg har litt tekst i denne boksen her.
Hei. Jeg har litt tekst i denne boksen her.
Hei. Jeg har litt tekst i denne boksen her.

Points of Interest



TEKST - word-wrap

w3schools: CSS word-wrap Property

https://www.w3schools.com/cssref/css3_pr_word-wrap.asp

Definition and Usage

The word-wrap property allows long words to be able to be broken and wrap onto the next line.

Property Values

normal
- Break words only at allowed break points.
break-word
- Allows unbreakable words to be broken.
initial
- Sets this property to its default value.
inherit
- Inherits this property from its parent element.

Example

Allow long words to be able to break and wrap onto the next line:

div {
  width: 150px; 
  border: 1px solid #000000;
}

div.a {
  word-wrap: normal;
}

div.b {
  word-wrap: break-word;
}
<h2>word-wrap: normal (default):</h2>
<div class="a"> This div contains a very long word: 
thisisaveryveryveryveryveryverylongword. 
The long word will break and wrap to the next line.</div>

<h2>word-wrap: break-word:</h2>
<div class="b"> This div contains a very long word: 
thisisaveryveryveryveryveryverylongword. 
The long word will break and wrap to the next line.</div>

word-wrap: normal (default):

This div contains a very long word: thisisaveryveryveryveryveryverylongword. The long word will break and wrap to the next line.

word-wrap: break-word:

This div contains a very long word: thisisaveryveryveryveryveryverylongword. The long word will break and wrap to the next line.


TEKST - writing-mode

w3schools: CSS Text Effects

https://www.w3schools.com/css/css3_text_effects.asp

CSS Writing Mode

The writing-mode property specifies whether lines of text are laid out horizontally or vertically.

The following example shows some different writing modes:

Example

p.test1 {
  writing-mode: horizontal-tb;
}

span.test2 {
  writing-mode: vertical-rl;
}

p.test2 {
  writing-mode: vertical-rl;
}
<p class="test1">Some text with 
default writing-mode.</p>

<p>Some text with a span element with 
a <span class="test2">vertical-rl</span> 
writing-mode.</p>

<p class="test2">Some text with 
writing-mode: vertical-rl.</p>

Some text with default writing-mode.

Some text with a span element with a vertical-rl writing-mode.

Some text with writing-mode: vertical-rl.



TITLE

The title attribute specifies extra information about an element. The information is most often shown as a tooltip text when the mouse moves over the element.

<h2 title="I'm a header">The TITLE Attribute</h2>

<p title="I'm a tooltip">Mouse over this paragraph, 
to display the title attribute as a tooltip.</p>
<p title="John 'ShotGun' Nelson">John "ShotGun" Nelson. 
Double quotes / Single quotes.</p>

The TITLE Attribute

Mouse over this paragraph, to display the title attribute as a tooltip.

John "ShotGun" Nelson. Double quotes / Single quotes.

TOOLTIP laget av CSS - Fra stackoverflow.com (forum)




The tooltip centers with variable width or height.
For more buttons, visit me at btn.ninja.

The HTML <title> Element

The <title> element represents the document's title or name. Authors should use titles that identify their documents even when they are used out of context, for example in a user's history or bookmarks, or in search results. The document's title is often different from its first heading, since the first heading does not have to stand alone when taken out of context.



Z-INDEX

w3schools: CSS z-index Property

Definition and Usage

The z-index property specifies the stack order of an element.

An element with greater stack order is always in front of an element with a lower stack order.

Note: z-index only works on positioned elements (position: absolute, position: relative, position: fixed, or position: sticky).

Property Values

Value Description
auto Sets the stack order equal to its parents. This is default
number Sets the stack order of the element. Negative numbers are allowed
initial Sets this property to its default value.
inherit Inherits this property from its parent element.

Example

img {
  position: absolute;
  left: 0px;
  top: 0px;
  z-index: -1;
}
<h1>The z-index Property</h1>

<img src="w3css.gif" width="100" height="140">

<p>Because the image has a z-index of -1, it will be placed behind the heading.</p>

PB: Her har jeg jukset med plaseringen. Byttet ut ABSOLUTE med RELATIVE positioning, og endret verdiene for å simulere positioning plasseringen.

<h1>The z-index Property</h1>

<img style="position: relative; left: -16px; top: -100px; z-index: -1;" src="bilder/w3css.png" width="100" height="140">

<p style="margin-top: -140px;">Because the image has a z-index of -1, it will be placed behind the heading.</p>

The z-index Property

Because the image has a z-index of -1, it will be placed behind the heading.


The CSS z-index property

https://flaviocopes.com/css-z-index/

This property takes a number (without decimals) and uses that number to calculate which elements appear nearer to the user, in the Z axis.

The higher the z-index value, the more an element is positioned nearer to the user.

When deciding which element should be visible and which one should be positioned behind it, the browser does a calculation on the z-index value.

The default value is auto, a special keyword. Using auto, the Z axis order is determined by the position of the HTML element in the page - the last sibling appears first, as it’s defined last.

By default elements have the static value for the position property. In this case, the z-index property does not make any difference - it must be set to absolute, relative or fixed to work.

PB: Modifisert

.my-first-div {
 background-color:red;
 position: relative;
 top: 0;
 left: 0;
 width: 200px;
 height: 200px;
 z-index: 10;
}

.my-second-div {
 background-color:green;
 position: absolute;
 top: 0;
 left: 0;
 width: 100px;
 height: 100px;
 z-index: 20;
}
<div class="my-first-div">
<div class="my-second-div">
</div>
</div>

The element with class .my-second-div will be displayed, and behind it .my-first-div.

Here we used 10 and 20, but you can use any number. Negative numbers too. It’s common to pick non-consecutive numbers, so you can position elements in the middle. If you use consecutive numbers instead, you would need to re-calculate the z-index of each element involved in the positioning.





















CSS - Cascading Style Sheets

En gammel (1999) men meget god introduksjon til CSS forklarer veldig bra de forskjellige ting på NORSK: (https://www.garshol.priv.no/download/text/css-intro.html). Prinsippene er gamle men ordene er de samme på norsk:

En liste jeg samler opp med engelsk til norsk:

CSS (Cascading Style Sheets)
- Stilsett
????
- HTML-markeringer
TAG
- Tag
WEB-Browser
- Nettleser
KLADD, andre ord og begrep på NORSK:
avstand mellom elementer
skrift-størrelse
Fra andre kilder:
sluttagen har en skråstrek inni seg
<p>Tekstinnholdet</p>
STARTTAG = P
SLUTTAG = /P
ELEMENT = <p>Tekstinnholdet</p>

...en starttag, 
   innholdet som skal merkes og
   en sluttag,
   kalles for et element.

**

Obligatoriske elementer

html-elementet. Inne i det, 
må det være minst 2 elementer som heter 
head og body. 
Inne i head-elementet må det 
også være et title-element.

I tillegg må det være en 
doctype-deklarasjon øverst i alle HTML-filer.
<!DOCTYPE html>

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

FRA håkon.org/wp/avanserte-css-selektorer/

Cascading

CSS står for cascading style sheets, og delen cascading kan oversettes til fossefall på norsk. Hvis man ser for seg en foss som deler seg og faller over flere nivåer nedover, er tanken at noe som bestemmes lenger opp i fossen også er gjeldende i utspring nedenfor, helt til det blir bestemt noe annet. Det betyr også at når noe bestemmes nede i fossen vil det overstyre eventuelle regler for det samme som er satt lenger opp. Dette er grunnprinsippet for CSS.

Prioritering:

I CSS prioriteres regler etter følgende faktorer: rekkefølge (når det lastes), spesifikkhet (hvor spesifikk selectoren er) og viktighet (normal eller !important).

Det vil si at viktighet har høyeste prioritet, deretter hvor spesifikt noe er deklarert, deretter rekkefølgen det lastes inn.

Rekkefølge: Har man to regler for samme elementer og samme properties, vil det som lastes inn sist, overstyre det andre.

p { color: red; }
p { color: green; }

Her vil den nederste regelen prioriteres, ettersom de har helt lik viktighet og spesifikkhet. Tekstfargen på alle p-elementer vil bli grønn.

Spesifikkhet: Det mest spesifikke gjelder. En regel for a-elementer inne i et p-element, vil overstyre en regel for alle p-elementer, siden det er mer spesifikt.

p a { color: red; }
a { color: green; }

Den første regelen sier at alle a-elementer inne i et p-element skal ha rød tekst, mens den nederste sier at alle a-elementer (mindre spesifikt) skal være grønne. Det mest spesifikke prioriteres, og teksten blir rød. Selv om grønn blir bestemt sist.

Viktighet: En deklarasjon med “!important” etter verdien vil overstyre samme deklarasjon uten, uavhengig av hvor spesifikt det er valgt via selector eller i hvilken rekkefølge de lastes inn.

p { color: red!important; }
p#text { color: green; }
p {color: blue; }

I eksemplet over, vil p-elementet med id “text” få rød tekst siden det er satt som !important, selv om regelen som sier at den skal være grønn er mer spesifikk, og også selv om regelen som sier den skal være blå lastes inn etter.

Bruk av !important bør uansett være siste utvei, og ikke bli en vane for å være sikker på at regelen skal gjelde. Dette er hovedsakelig fordi det skaper en uoversiktlig kode som gjør endringer og feilsøking vanskeligere. Bruk heller mer spesifikke selectorer der det er mulig.

Ekstern, intern og inline CSS

CSS kan brukes på tre måter: inline, internt og eksternt. Inline har høyest prioritet, og vil overstyre både interne og eksterne stiler. Interne stiler har høyrere prioritet enn eksterne stiler.

Inline CSS settes direkte i HTML-koden på elementet som skal styles, ved å lage en atributt med navn style og CSS-kode som verdi.

Eksempel:

<body style="background: #000;">

Intern CSS skrives inne i <head>-taggen i HTML-dokumentet og legges i en <style>-tag.

<style>
 body {
 background: #000;
 }
 </style>

Ekstern CSS skrives i eksterne .css-filer som linkes til fra HTML-dokumentet i <head>-taggen.

Eksempel:

<link rel="stylesheet" href="css/global.css">

Stilark kan også importeres, både i en <style>-tag og i eksterne stilark, ved å bruke @import. Importerte stiler vektlegges likt som stilene der de importeres fra, men skal legges først i stilarket og leses dermed først og blir overstyrt av like regler som leses senere.

Prioritering i forhold brukerstiler og nettleserstiler

I tillegg til CSS vi angir som inline, intern og ekstern CSS, finnes også stilregler hos brukeren. Både i nettleserens standard stilark, og eventuelle egendefinerte stiler. Standardstilene har vi noenlunde oversikt over, men egendefinerte brukerstiler kan vi naturlig nok ikke vite om. Stiler angitt på en side (Author styles) overstyrer imidlertid eventuelle brukerstiler (User styles) som er satt i nettleseren, som igjen overstyrer stilarket til selve nettleseren (User Agent styles). Unntaket er hvis en brukerstil er satt til !important. I så fåll vil denne brukerstilen prioriteres foran samme forfatterstil (nettsidestilen) selv om denne også er satt til !important.

Vanligvis har ikke folk satt egne brukerstiler for nettleseren, så det man ikke selv bestemmer i CSS, bestemmes ofte av nettleserens stilark. Alle nettlesere har sine egne stilark, og selv om de er like på mye, er de også forskjellige for mange elementer. Vil du være sikker på hvordan ting skal se ut, bør du definere det selv i CSS, slik at dine regler overstyrer nettleserens regler. Mange bruker ofte en såkalt CSS-reset for å resette alle stilene til nettleseren (og brukerdefinerte stiler). Dette lastes inn først i CSS-en din og overstyrer verdiene som er angitt for alle elementer som angis. Slik får man et likt utgangspunkt, uavhengig av brukerens nettleser. For mindre arbeider, som f.eks. bannere, er dette imidlertid overkill, da man vanligvis ikke bruker så mange ulike elementer og uansett vil angi mer spesifikke selektorer som vil overstyre nettleser- og brukerstiler. Og i tillegg tester man selvsagt at det man lager vises som man ønsker i alle miljøer.

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

********************************************************************************************

********************************************************************************************

Fra (https://www.smashingmagazine.com/2007/07/css-specificity-things-you-should-know/)

Never use !important. “If you’re having specificity issues, there’s some quick ways to solve it. First, avoid !important.” “The !important declaration overrides normal declarations, but is unstructured and rarely required in an author’s style sheet.” [Understanding Specificity, Selector Specificity]

********************************************************************************************

********************************************************************************************

Tip: The word cascading means that a style applied to a parent element will also apply to all children elements within the parent. So, if you set the color of the body text to "blue", all headings, paragraphs, and other text elements within the body will also get the same color (unless you specify something else)!

HTML Styles

I am normal

I am red

I am blue

I am a big P-TAG

***********************

style

The style element allows authors to embed style information in their documents. The style element is one of several inputs to the styling processing model. The element does not represent content for the user.

<style>
  article { width:640px; margin-bottom:10px; }
</style>

***********************

The HTML style attribute has the following syntax:

< tagname style="property:value;" >

The property is a CSS property. The value is a CSS value.

This is a heading

This is a paragraph.

This is a heading

This is a paragraph.


-- DIVs nedenfor er lagt til av meg, innholdet er kopiert fra www.w3schools.com --------------------
<style >
h1 {
  color : blue ;
  font-family : verdana ;
  font-size : 300% ;
}
{
  color : red ;
  font-family : courier ;
  font-size : 160% ;
}
</style >
p {
  border : 2px solid powderblue;
}

Resultat


-- PRE er lagt til av meg, resten er kopiert fra www.w3schools.com -----------------------------

p {
  border: 2px solid powderblue;
  padding: 30px;
}


-- PRE er lagt til av meg, resten er kopiert fra www.w3schools.com -----------------------------

p {
  border: 2px solid powderblue;
  margin: 50px;
}

This is a heading

This is a paragraph.

This is a heading

This is a paragraph.





Litt om navnene på enhetene i CSS på norsk

Hentet fra (https://oppgaver.kidsakoder.no/web/style_nettsider/style_nettsider)

I seksjonen <head> trenger vi en style-tag.

<style>
</style>

Alle stiler skal legges mellom disse elementene. Generelt ser css-kode slik ut:

selector {
  property: value;
}

Selektorer kan være html-element som h1, p, img, a, eller id-er og klasser, men disse skal vi se på senere. Selektorer brukes for å fortelle CSS-en hvilke HTML-objekter vi skal sette stil på. Hvilken stil selektoren får avheniger av hva man setter på property og value.

Property eller attributt er gjerne en egenskap man kan tilegne selektoren, sammen med en verdi, value. Eksempler på property og value kan være color: blue;, background-color: red; og font-family: "Times New Roman", Serif;.

Hva om vi vil gjøre sånn at ordet oransje i setningen Pelsen hans er oransje får oransje farge? Ikke hele setningen, men akkurat det ordet. Da bruker vi en tag som heter <span>. Vi legger taggen rundt ordet vi vil sette farge på slik:

<span>oransje</span>

I <head> kan vi nå gjøre at alle <span>-taggene blir oransje slik:

span {
  color:orange;
}

PB: Litt om tekst (H1) også, hentet fra samme sted (samt annet, nedenfor). Det nevnes også at text-decoration:underline; kan byttes ut med text-decoration:blink;.

Kanskje skulle tittelen være større og med store bokstaver. Vi kan spesifisere størrelsen på teksten gjennom å bruke font-size. Verdiene kan være forskjellige, men de mest brukte er 12, 14, 16, 32, 48 og 72 piksler.

Inne i <img> taggen har vi src og alt attributter:

<img src="katt.png" alt="Katt">

PB: Også plukket ut om linker, med navn på norsk

Når vi har linket til deler av den samme siden, kunne vi bare peke linken til en bestemt id på siden, som dette:

<a href="#kattunge">Klikk for å se en kattunge</a>

Som da tok deg til noe sånt som dette:

<div id="kattunge">
  <img src="kattunge.jpg" alt="Dette er en kattunge." />

Hvis du vil koble til en annen side, trenger vi ikke å inkludere hashsymbolet (#), men i stedet må vi si hvilken fil vi vil linken skal ta oss til.

Så for å linke fra om_meg_side_2.html til om_meg.html skriver vi slik:

<a href="om_meg.html">Gå til Om Meg siden</a>

Du kan endre anker teksten til noe annet, som tittelen på siden hvis du har endret det.

For å linke tilbake fra om_meg.html til om_meg_side_2.html må du skrive det slik:

<a href="om_meg_side_2.html">Gå til min andre side</a>

PB: Plukket også ut litt om HTML navnene på norsk

Tagger ser sånn ut:

<p>Dette er litt tekst.</p>

<p> er en forkortelse for paragraf, som er et annet ord for avsnitt. Den har en åpning, som er <p>, og en tilsvarende avslutning med skråstrek, </p>. Nettleseren vet da at alt imellom de to taggene er en paragraf med tekst.

Tagger kan også ha attributter, som er informasjon om elementet. La oss se på link-taggen:

<a href="http://kodeklubben.no/">Besøk nettsiden til Kodeklubben</a>

<a> betyr anker, som er det linker ble kalt før. Den har åpningen <a> og avslutningen </a>. I åpningstaggen la vi til attributten href med verdien http://kodeklubben.no/. href står for hypertekst referanse. En tekst som linket til andre tekster ble en gang kalt hypertekst, fordi den kunne peke til bilder, lyd og andre tekster. Det gjorde anker annerledes enn annen vanlig tekst. href forteller nettleseren hvor linken skal føre deg, og teksten i mellom taggene vil bli synlig som en link.

Vi har allerede nevnt taggene <p> og <a>, men det finnes mange flere. Her er noen tagger som ofte brukes:

PB: Litt mer på norsk, i tillegg til at de også har kalt border for kanter.

< >



Elementtyper

HTML-elementer kommer i en av to typer. Enten er de block level (som de fleste er) eller så er de inline level. Et block level element vil alltid lage et linjeskift før og etter seg selv mens inline level vil ikke gjøre det.

Et p-element er et block level element mens et a-element er et inline level element. Det er mulig å sette flere a-elementer ved siden av hverandre men du kan ikke ha to avsnitt med tekst ved siden av hverandre. De vil alltid dytte det neste elementet ned på en ny linje under.

Siden a-elementet er inline level vil det stå ved siden av hverandre uansett, så lenge det er plass i vinduet. P-elementet er block level og vil alltid komme på sin egen linje og bruker hele bredden av vinduet selv om det kanskje ikke trenger det.

Her er en kort oppsummering av de to forskjellige gruppene.

Block level

Inline level

Det finnes flere levels også, som flex og inline-block for eksempel. Eneste måten å bruke dem på er med CSS så det er noe du skal lære mer om når du kommer til CSS.

********

Oppsummering til HTML

Gratulerer, du kan nå HTML. Til slutt i denne leksjonen får du en oppsummering over hva du bør kunne etter å ha lest alt i denne leksjonen. Du har nå en grunnleggende forståelse for hva HTML er og hvordan det brukes. Med kunnskapen du har tilegnet deg så langt er det ikke noe problem for deg å lage sider som fungerer med linker og bilder etc, og mye bra innhold med riktig HTML. Hvis du vil gjøre noe med utseende på siden din må du lære deg CSS.

Du skal nå vite hva følgende HTML-elementer brukes til:

Hvis noe av det som står i listen over ikke høres kjent ut bør du se gjennom kurset en gang til.



Using Style Sheets

Short CSS rules can be written compressed, like this:


p.intro {font-family:Verdana;font-size:16em;}

Long CSS rules should be written over multiple lines:


body {
  background-color: lightgrey;
  font-family: "Arial Black", Helvetica, sans-serif;
  font-size: 16em;
  color: black;
}


********************************* *********************************



****** DIVERSE CSS TIPS OG TRICKS ******

CENTER

CSS background-image Technique:


html { 
   width:100%; 
   height:100%; 
   background:url(logo.png) center center no-repeat;
}

CSS + Inline Image Technique:


img {
   position: absolute;
   top: 50%;
   left: 50%;
   width: 500px;
   height: 500px;
   margin-top: -250px; /* Half the height */
   margin-left: -250px; /* Half the width */
}

Positon Sticky to Bottom:


CSS:

body{color:#fff; font-family:arial; font-weight:bold; font-size:40px; }
.main-container{ max-width:600px; margin:0 auto; border:solid 10px green; padding:10px; margin-top:40px;}
.main-container *{padding:10px;background:#aaa; border:dashed 5px #000;}
.main-container * + *{margin-top:20px;}
.main-header{
  height:50px; background:#aaa;
}
.main-content{
  min-height:1000px;
}

.main-footer{position:-webkit-sticky; position:sticky; bottom:0; border-color:red;}


OBS!

For Safari browsers you will need to add the -webkit prefix.

position: -webkit-sticky; /* Safari */  
position: sticky;


HTML:

<main class="main-container">
  <header class="main-header">HEADER</header>
  <div class="main-content">MAIN CONTENT</div>
  <footer class="main-footer">FOOTER</footer>
</main>


****
     SCSS 

    Result
    Skip Results Iframe

EDIT ON

// Learn about this technique:
// @link https://moderncss.dev/pure-css-smooth-scroll-back-to-top/

$color: #254568;
$main-width: 50rem;

// How far of a scroll travel within 
prior to the // link appearing $scrollLength: 100vh; * { box-sizing: border-box; } // Smooth scrolling IF user doesn't have a preference due to motion sensitivities @media (prefers-reduced-motion: no-preference) { html { scroll-behavior: smooth; } } main { // leave room for the "scroll track" padding: 0 3rem; // required to make sure the `absolute` positioning of // the anchor wrapper is indeed `relative` to this element vs. the body position: relative; max-width: $main-width; margin: 2rem auto; // Optional, clears margin if last element is a block item *:last-child { margin-bottom: 0; } } .back-to-top-wrapper { // uncomment to visualize "track" // outline: 1px solid red; position: absolute; top: $scrollLength; right: 0.25rem; bottom: -5em; width: 3em; pointer-events: none; } .back-to-top-link { // `fixed` is fallback position: fixed; // preferred positioning, requires prefixing for most support, and not supported on Safari // @link https://caniuse.com/#search=position%3A%20sticky position: sticky; // reinstate clicks pointer-events: all; // achieves desired positioning within the viewport // relative to the top of the viewport once `sticky` takes over, or always if `fixed` fallback is used top: calc(100vh - 5rem); // basic styling display: inline-block; text-decoration: none; font-size: 2rem; line-height: 3rem; text-align: center; width: 3rem; height: 3rem; border-radius: 50%; padding: 0.25rem; // "pretty" styles, including states border: 1px solid $color; background-color: scale-color($color, $lightness: 85%); transition: transform 80ms ease-in; &:hover, &:focus { transform: scale(1.1); } &:focus { outline: none; box-shadow: 0 0 0 3px scale-color($color, $lightness: 35%); } } body { font-family: "Baloo 2", sans-serif; min-height: 100vh; height: 100%; display: grid; grid-template-rows: auto 1fr auto auto; } header, footer { display: grid; place-items: center; background-color: $color; color: #fff; } header { background-image: url(https://images.unsplash.com/photo-1513628253....); background-position: center; background-size: cover; background-repeat: no-repeat; } h1 { font-size: 4rem; text-align: center; } p { font-size: 1.125rem; line-height: 1.5; } +++++ <header id="top"> <h1>The Star</h1> <h2><cite>H.G. Wells</cite></h2> </header> <main> <article> <p>It was on the first day of the New Year that the announcement was made, almost simultaneously from three observatories, that the motion of the planet Neptune, the outermost of all the planets that wheel about the sun, had become very erratic. Ogilvy had already called attention to a suspected retardation in its velocity in December. Such a piece of news was scarcely calculated to interest a world the greater portion of whose inhabitants were unaware of the existence of the planet Neptune, nor outside the astronomical profession did the subsequent discovery of a faint remote speck of light in the region of the perturbed planet cause any very great excitement. Scientific people, however, found the intelligence remarkable enough, even before it became known that the new body was rapidly growing larger and brighter, that its motion was quite different from the orderly progress of the planets, and that the deflection of Neptune and its satellite was becoming now of an unprecedented kind. </p> <p>Few people without a training in science can realise the huge isolation of the solar system. The sun with its specks of planets, its dust of planetoids, and its impalpable comets, swims in a vacant immensity that almost defeats the imagination. Beyond the orbit of Neptune there is space, vacant so far as human observation has penetrated, without warmth or light or sound, blank emptiness, for twenty million times a million miles. That is the smallest estimate of the distance to be traversed before the very nearest of the stars is attained. And, saving a few comets more unsubstantial than the thinnest flame, no matter had ever to human knowledge crossed this gulf of space, until early in the twentieth century this strange wanderer appeared. A vast mass of matter it was, bulky, heavy, rushing without warning out of the black mystery of the sky into the radiance of the sun. By the second day it was clearly visible to any decent instrument, as a speck with a barely sensible diameter, in the constellation Leo near Regulus. In a little while an opera glass could attain it. </p> <p>On the third day of the new year the newspaper readers of two hemispheres were made aware for the first time of the real importance of this unusual apparition in the heavens. 'A Planetary Collision,' one London paper headed the news, and proclaimed Duchaine's opinion that this strange new planet would probably collide with Neptune. The leader writers enlarged upon the topic; so that in most of the capitals of the world, on January 3rd, there was an expectation, however vague of some imminent phenomenon in the sky; and as the night followed the sunset round the globe, thousands of men turned their eyes skyward to see--the old familiar stars just as they had always been. </p> <p> Until it was dawn in London and Pollux setting and the stars overhead grown pale. The Winter's dawn it was, a sickly filtering accumulation of daylight, and the light of gas and candles shone yellow in the windows to show where people were astir. But the yawning policeman saw the thing, the busy crowds in the markets stopped agape, workmen going to their work betimes, milkmen, the drivers of news-carts, dissipation going home jaded and pale, homeless wanderers, sentinels on their beats, and in the country, labourers trudging afield, poachers slinking home, all over the dusky quickening country it could be seen--and out at sea by seamen watching for the day--a great white star, come suddenly into the westward sky! </p> <p> Brighter it was than any star in our skies; brighter than the evening star at its brightest. It still glowed out white and large, no mere twinkling spot of light, but a small round clear shining disc, an hour after the day had come. And where science has not reached, men stared and feared, telling one another of the wars and pestilences that are foreshadowed by these fiery signs in the Heavens. Sturdy Boers, dusky Hottentots, Gold Coast Negroes, Frenchmen, Spaniards, Portuguese, stood in the warmth of the sunrise watching the setting of this strange new star. <p> <p> And in a hundred observatories there had been suppressed excitement, rising almost to shouting pitch, as the two remote bodies had rushed together; and a hurrying to and fro, to gather photographic apparatus and spectroscope, and this appliance and that, to record this novel astonishing sight, the destruction of a world. For it was a world, a sister planet of our earth, far greater than our earth indeed, that had so suddenly flashed into flaming death. Neptune it was, had been struck, fairly and squarely, by the strange planet from outer space and the heat of the concussion had incontinently turned two solid globes into one vast mass of incandescence. Round the world that day, two hours before the dawn, went the pallid great white star, fading only as it sank westward and the sun mounted above it. Everywhere men marvelled at it, but of all those who saw it none could have marvelled more than those sailors, habitual watchers of the stars, who far away at sea had heard nothing of its advent and saw it now rise like a pigmy moon and climb zenithward and hang overhead and sink westward with the passing of the night. <p> <p> And when next it rose over Europe everywhere were crowds of watchers on hilly slopes, on house-roofs, in open spaces, staring eastward for the rising of the great new star. It rose with a white glow in front of it, like the glare of a white fire, and those who had seen it come into existence the night before cried out at the sight of it. "It is larger," they cried. "It is brighter!" And, indeed the moon a quarter full and sinking in the west was in its apparent size beyond comparison, but scarcely in all its breadth had it as much brightness now as the little circle of the strange new star. <p> <p>"It is brighter!"" cried the people clustering in the streets. But in the dim observatories the watchers held their breath and peered at one another. "<em>It is nearer</em>," they said. "<em>Nearer!</em>" <p> <a href="https://commapress.co.uk/resources/online-short-stories/the-star-h.g.-wells/" target="_blank">Continue reading...</a> </article> <div class="back-to-top-wrapper"> <a href="#top" class="back-to-top-link" aria-label="Scroll to Top">?? </div> </main> <footer> <p>© ACME</p> </footer>
**** **************** -------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------

Note: Do not add a space between the property value and the unit (such as margin-left: 20 px;). The correct way is: margin-left: 20px;


body {
  background-color: lightgrey;
  color: blue;
}

h1 {
  background-color: black;
  color: white;
}


h1 {
  text-align: center;
}

h2 {
  text-align: left;
}

h3 {
  text-align: right;
}


div {
  text-align: justify;
}


img.top {
  vertical-align: top;
}

img.middle {
  vertical-align: middle;
}

img.bottom {
  vertical-align: bottom;
}


h1 {
  text-decoration: overline;
}

h2 {
  text-decoration: line-through;
}

h3 {
  text-decoration: underline;
}


p {
  text-indent: 50px;
}


h1 {
  letter-spacing: 3px;
}

h2 {
  letter-spacing: -3px;
}


p.small {
  line-height: 0.8;
}

p.big {
  line-height: 1.8;
}


h1 {
  word-spacing: 10px;
}

h2 {
  word-spacing: -5px;
}


p {
  white-space: nowrap;
}


h1 {
  text-shadow: 2px 2px red;
}

Example


h1 {
  text-shadow: 2px 2px 5px red;
}

h2 {
  font-family: 'Brush Script MT', cursive;
  font-size: 30px;
  text-shadow: 3px 3px 3px #ababab;
}



body {
  font-family: 'Brush Script MT', cursive;
}
p {
font-family: Tahoma, Verdana, sans-serif;
}

.p1 {
  font-family: "Times New Roman", Times, serif;
}

.p2 {
  font-family: Arial, Helvetica, sans-serif;
}

.p3 {
  font-family: "Lucida Console", "Courier New", monospace;
}


p.normal {
  font-style: normal;
}

p.italic {
  font-style: italic;
}

p.oblique {
  font-style: oblique;
}


p.normal {
  font-weight: normal;
}

p.thick {
  font-weight: bold;
}


body {
  font-size: 100%;
}

h1 {
  font-size: 2.5em;
}

h2 {
  font-size: 1.875em;
}

p {
  font-size: 0.875em;
}

FOR VIDERE BRUK, kun en KLADD kopi !!!

Header 2 kopi nedenfra for videre arbeid oppover

Header 2

Artig font-bruk på denne P med linjehøyde og marginer. Har lagt dette i en noe mørkere DIV.

Link Link hover

body {
  background-color: black;
  font-family: Verdana, sans-serif;
  font-size: 16px;
  color: gray;
}

h1 {
  font-family: Georgia, serif;
  font-size: 60px;
  color: white;
}


body  {
  font-family: Verdana, sans-serif;
  font-size: 16px;
}

h1 {
  font-family: Georgia, serif;
  font-size: 46px;  
}

Note: The font-size and font-family values are required. If one of the other values is missing, their default value are used.


The font property is a shorthand property for:
font-style
font-variant
font-weight
font-size/line-height
font-family

p.a {
  font: 20px Arial, sans-serif;
}

p.b {
  font: italic small-caps bold 12px/30px Georgia, serif;
}

********************

********************

********************

********************

********************

********************

********************

********************

********************

********************

********************

********************

********************

********************

********************

********************

********************

fra: http://html5doctor.com/

Head:
doctype
html
head
title
base
link
meta
style
script
noscript
Sections:
body
article
nav
aside
section
header
footer
h1-h6
main
address
Grouping:
p
hr
pre
blockquote
ol
ul
li
dl, dt, dd
figure
figcaption
div
Tables:
table
caption
thead
tbody
tfoot
tr
th
td
col
colgroup
Forms:
form
fieldset
legend
label
input
button
select
datalist
optgroup
option
textarea
Forms 2:
keygen
output
progress
meter
Interactive:
details
summary
command
menu
Edits:
del, ins
Embedded:
img
iframe
embed
object
param
video
audio
source
canvas
track
map
area
Text-level:
a
em
strong
i, b
u
s
small
abbr
q
cite
dfn
sub, sup
Text-level 2:
time
code
kbd
samp
var
mark
bdi
bdo
ruby, rt, rp
span
br
wbr

***********************

***********************

***********************

***********************

***********************

***********************

***********************


E N D R I N G S P L A N E R


RYDD TEST HTML5:
Slå sammen tilhørende emner.
Rydd i H-tags.
Vis både eksemplene + oppskriftene.


ØVERSTE DIV:
Lag ny DIV for det øverste feltet.
Fjern flygelet.
Sentrer teksten og lag den til HOME-link.


DIV:
Endre TABLE for hovedoppsettet, hele siden, til en DIV eller nyere enhet for innhold


RYDD CSS:
Slå sammen / samle sammen tags i CSS.


LINKER:
Alle linker til felles, slipper CLASS hvert sted.
De som skiller seg ut får heller egen CLASS


H-TAGS:
Rydd både rekkefølgen og bruken samt   som avstandseffekt.
Har brukt NESTE SIDE med en H-tag. Helt feil.


BILDER:
Rydd i rekkefølgen.
Legg inn ALT-info.
 /> for XHTML.
 

BEHOLD, SETT INN IGJEN
 /> for XHTML.


TITLE (les deg opp mer på dette før bruk!!!!!):
Fant artikkel som sa at en bør unngå TITLE attribute.
Bruke heller; <nav>, <section>, <article> and <header> (men også der finnes det advarsler).
https://css-tricks.com/how-to-section-your-html/

ikke gått igjennom men virker bra

https://www.htmldog.com/references/css/selectors/

https://www.cssportal.com/html-tags/tag-body.php







xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

FRA (https://www.multitek.no/innlegg/hvordan-virker-nettsider-2/)

element {
  regel1: verdi;
  regel2: verdi;
}

Eller

element {regel1: verdi;regel2: verdi;}

Her er element navnet på et HTML-element (som p eller div). 
regel1 og regel2 er navn på CSS-regler, 
mens verdi er verdien du ønsker å sette.


/* Forresten, kommentarer skrives på denne måten i CSS */
.eksempel {
  /* Bredde */
  width: 100%;

  /* Høyde */
  height: 500px;

  /* Gjennomsiktighet */
  opacity: 0.85;

  /* Bakgrunnsfarge */
  background-color: orange;

  /* Kantlinje */
  border: 1px solid black;

  /* Avstand mellom kantlinje og andre elementer */
  margin: 4px;

  /* Avstand mellom innhold og kantlinje */
  padding: 8px;
}CSS

**

<element id="elementID" class="elementKlasse"></element>

Her er elementID id-en du ønsker og elementKlasse klassen du ønsker. 
Hvis du skal lage CSS-regler som bruker id-er og klasser, må du plassere et spesielt tegn foran, 
henholdsvis # for id og . for klasser. 
Hvis du velger et element med id elementID, kan CSS-reglene se slik ut:

#elementID {
  regel1: verdi;
  regel2: verdi;
}

Her er et lignende eksempel for et element med klassen elementKlasse:

.elementKlasse {
  regel1: verdi;
  regel2: verdi;
}



I mange tilfeller vil man foretrekke å bruke klasser, 
med mindre man er sikker på at det ikke vil være flere elementer med samme id.

Tilknytning til HTML

<element style="regel1:verdi;"></element>

En litt mer oversiktlig måte er å plassere CSS-reglene i et eget <style>-element.

<style>
element {
  regel1: verdi;
  regel2: verdi;
}
</style>

...blir informasjonen om hvilket bilde som skal vises plassert i en attributt, eller egenskap. 
Egenskaper skrives på formen <element egenskap="verdi"></element> (der element fortsatt er elementet, 
egenskap er egenskapen og verdi er verdien til egenskapen). Et bilde vil derfor kunne settes inn med følgende HTML-kode:

<img src="bilde.png">


Vi kan definere CSS-klasser for å angi ulikt utseende til like elementer. I HTML-dokumentet legger vi til class="klassenavn", mens vi i CSSdokumentet legger til .klassenavn (ikke glem punktumet).

Sammendrag
Vi angir en nettsides struktur med HTML.
I HTML angis avsnitt med <p>-elementet. Linjeskift angis med <br>-
elementet.
Overskrifter angis med elementene <h1> til <h6>, der <h1> gir den største
overskriften.
Vi angir en nettsides utseende med CSS.
Alle HTML-elementer kan få nytt utseende ved hjelp av CSS.
Vi plasserer CSS-kode i egne dokumenter som vi henter inn i HTMLdokumenter ved hjelp av <link>-elementet.

*********FORTSETTER hovedomhandlingen

Grunnleggende terminologi

De fleste som snakker om HTML er litt unøyaktige i bruken av ordet "tag", så det er antagelig best å rydde opp i det før vi fortsetter for å unngå misforståelser. For å ta et eksempel: <P>Dette er et <EM>enkelt</EM> avsnitt.</P> Hele eksempelet består av ett element, nemlig P-elementet, som strekker seg fra start-taggen (<P>) til slutt-taggen (</P>). Inne i elementet finner vi tekst og et EM-element. Dersom man hekter en stilregel på P-elementene ville den gjelde hele eksempelet over.

Det er vanlig å kalle et element som inneholder et annet som "forelderen" til det innerste elementet, som er "barnet" til det ytterste. I dette eksempelet er P foreldre-elementet til EM, mens EM er et barn av P.

Et attributt er slike ting som HREF på A-elementet og SRC på IMG-elementet. I dette eksempelet: <P ALIGN=center>Dette er et sentrert avsnitt</P>. har jeg brukt ALIGN-attributtet på P og satt det til verdien center. Attributt-verdier skal settes i anførselstegn hvis de inneholder noe annet enn tall og bokstaver.

Dette er egentlig ord og uttrykk som er eldre enn HTML og skriver seg fra SGML, som er standarden HTML er laget i. Det er lurt å bruke disse uttrykkene korrekt fordi nye standarder som CSS og XML (se lenger ned) gjør bruk av dem.

Kort om hvordan CSS virker og skrives

CSS-stilsett består ganske enkelt av en liste med stilregler. En stilregel har to deler: selektoren som forteller hvor den gjelder og deklarasjons-listen som forteller hvordan formateringen skal være. Selektoren kan gjelde slike ting som ett bestemt element, alle H1-elementer, eller alle EM-elementer inne i et A-element.

Stilsettet kan skrives i en vanlig teksteditor (som f.eks. Notepad, eller forsåvidt Emacs, selv om det ikke akkurat er noen vanlig editor) og enten lagres i en .css-fil og henvises til fra HTML-sidene eller settes rett inn i en HTML-side innpakket i et STYLE-element. Mer om dette senere.

Syntaksen i en ekstern CSS-fil og i et STYLE-element er akkurat den samme, dvs at man kan ha en HTML-kommentar rundt alle stilreglene, men ellers skal stilsettet kun bestå av stilregler og eventuelle CSS-kommentarer. (Merk at CSS-kommentarer har en annen syntaks enn HTML-kommentarer.) Detaljene følger nå...

Syntaksen i enkle stil-regler

En stil-regel ser slik ut: selektor { deklarasjon; deklarasjon; osv... } Selektoren angir hvilke elementer deklarasjonene som er ramset opp inne i klamme-parentesene gjelder. Deklarasjonene har formen egenskap: verdi.

Hvis vi for eksempel vil at de viktigste overskriftene på en side skal være i fet 26-punkt Times New Roman og sentrert kan vi angi det slik: H1 { font-weight: bold; font-size: 26pt; font-family: "Times New Roman"; text-align: center } Denne regelen vil nå gjelde alle H1-elementene i dokumentet som bruker stilsettet.

Verre er det faktisk ikke å skrive enkle CSS-regler. Man har imidlertid mer avanserte muligheter, og det finnes en hærskare av forskjellige egenskaper. Disse kan du finne en oversikt over lenger nede.

Arv av egenskaper

Et viktig prinsipp i CSS er at elementer arver stilegenskaper fra foreldrene. Det betyr at om man skriver: <H1>Dette er en <EM>kuul</EM> overskrift</H1> og bruker stilregelen i eksempelet over vil "kuul" inne i EM se ut akkurat som teksten inne i H1, men den vil i tillegg være uthevet på en eller annen måte. (Vanligvis i kursiv.)

Ikke alle egenskaper arves, men hvilke som ikke gjør det er stort sett intuitivt. F.eks. arves ikke bakgrunnsbilder, i stedet skinner de gjennom fra forelderen siden alle elementer som har gjennomsiktig bakgrunn som standard-verdi.

Hvordan koble stil-regler til HTML-dokumenter

Dette kan gjøres på mange måter, men jeg tar bare de vanligste her. Den kanskje nyttigste lar deg koble en egen CSS-fil til HTML-siden din. Jeg har gjort det på hjemmesidene mine for å gi dem et felles utseende. Alle mine sider deler altså CSS-stilsett, slik at jeg kan endre utseendet på alle sammen samtidig. Du angir hvilken fil som skal brukes med følgende HTML-markering: <LINK REL="Stylesheet" TYPE="text/css" MEDIA="screen" HREF="url"> LINK-elementet skal alltid stå inne i HEAD-elementet til siden. HREF angir altså URLen til stilsettet, akkurat som om det skulle vært en side man linket til med A HREF.

MEDIA-attributtet angir hva slags medium dette stilsettet skal gjelde. SCREEN angir at dette stilsettet gjelder visning på skjerm. Andre verdier kan være:

PRINT
Utskrift på papir eller andre ugjennomsiktige materialer.
PROJECTION
Utskrift for overhead. (Inndelt i sider, ikke sammenhengende rull.)
BRAILLE
For leselist som viser siden i blindeskrift.
AURAL
For tekst-til-tale-systemer. (Se ACSS-spesifikasjonen nederst.)
ALL
Dette er standardverdien, og angir at stilsettet gjelder alle medier.

TYPE-attributtet forteller vevleseren at det er snakk om et CSS-stilsett. Denne jobben skal egentlig webserveren gjøre, men det gjør den ikke alltid og da er TYPE en grei måte å løse problemet på. Bare så det er sagt, det finnes andre typer stilsett, f.eks. DSSSL (brukes ikke på web) og XSL (ikke ferdig enda, brukes med XML som det står mer om lenger ned).

Style-elementet

STYLE er et vanlig HTML-element som du kan bruke til å sette inn stilregler rett i HTML-dokumentet ditt. STYLE skal stå inne i HEAD-elementet, og du kan ha flere STYLE-elementer i samme dokument. STYLE har også et MEDIA-attributt i likhet med LINK, og det fungerer på akkurat samme måte.

Et eksempel på stilsett med STYLE:


<HTML>
<HEAD>
  <TITLE>Lite eksempel</TITLE>
  <STYLE>
    <!-- Skjuler for vevlesere som ikke forstår STYLE

    ...stilregler inn her på samme måte som i en .css-fil...    
    
    -->
  </STYLE>
<HEAD>

<BODY>
...resten av dokumentet kommer her...

STYLE-attributt

Det er også mulig å sette en stilregel direkte på et HTML-element, i stedet for å gjøre det i et STYLE-element eller i en separat fil. Dette kan f.eks. gjøres slik: <P STYLE="color: red">Dette avsnittet ville blitt vist i rødt.</P>

I dette tilfellet er det ikke nødvendig å angi noen selektor, fordi det er helt åpenbart hvilket element deklarasjonene gjelder. Man skriver med andre ord bare det som ellers ville stått inne i klammeparentesene.

Å kombinere flere stilsett

Man kan godt kombinere flere stilsett og f.eks. ha et eksternt i en .css-fil, flere skutt inn i STYLE-elementer og noen satt på STYLE-attributter. (I tillegg kan brukeren ha laget et eget bruker-stilsett som kombineres med alle sider brukeren ser på.) Da blir stilreglene kombinert med hverandre etter kaskade-reglene jeg beskriver lenger ned.

Manglende elementer: klasser

Noen ganger opplever man at HTML mangler et element for det man ønsker å uttrykke. Tenk deg f.eks. at du vil legge ut et intervju i HTML og vil vise intervjuerens spørsmål i en annen stil enn intervjuobjektets svar.

Den perfekte løsningen hadde sett omtrent slik ut:


<QUESTION>Hva følte du da du gikk i mål og visste du hadde vunnet?
</QUESTION>

<ANSWER>Helt topp, blahabklahbalbaahbhablabhalbahblalb.
</ANSWER>

Da kunne du hektet stilregler på QUESTION og ANSWER-elementene og det hele ville ha vært svært greit. Nå mangler imidlertid HTML slike elementer, men heldigvis har W3C forutsett dette problemet og laget en løsning på det.

Alle elementer i HTML 4.0 (ikke HTML 3.2) har et valgfritt attributt som heter CLASS. Det kunne vært brukt i eksempelet over på denne måten:


<P CLASS=question>Hva følte du da du gikk i mål og visste du hadde vunnet?
</P>

<P CLASS=answer>Helt topp, blahabklahbalbaahbhablabhalbahblalb.
</P>

Dette gjør at du kan sette på følgende regler i stilsettet ditt:


P.question { font-weight: bold;   margin-left: 2em }
P.answer   { font-weight: normal; margin-left: 4em }

Vevlesere som ikke forstår CSS bare overser dette CLASS-attributtet, slik at du kan bruke det helt uten å bekymre deg for virkningen i gammeldagse vevlesere. Du bør imidlertid bruke CLASS med forsiktighet, fordi dokumentet ditt skal helst være skrevet slik at man kan lese det med et helt generelt stilsett også. Du kan med andre ord ikke være 100% sikker på at leseren vil ha egne stilregler for klassene question og answer, og må ta hensyn til det når du skriver dokumentet.

Det finnes en annen løsning på dette problemet, som ikke er ferdig utformet ennå. Den heter XML (eXtensible Markup Language) og lar deg definere dine egne elementer. Du finner mer informasjon om XML under referansene.

Detaljerte stilregler: IDer

Noen ganger vil du ha en stilregel som bare gjelder ett bestemt element. Dette gjelder særlig slike ting som plassering av elementer i dokumentet, men av og til trenger man det også til andre ting. Som regel bør slike problemer løses så generelt som mulig, slik at man ikke er avhengig av å bruke ditt stilsett for å se siden.

Dersom det ikke finnes noen generell løsning kan du bruke ID-attributtet, som i likhet med CLASS ble introdusert i HTML 4.0 og finnes på alle elementer. For å hekte en stilregel på ett bestemt element må du først gi det elementet et unikt navn. Slik: <DFN ID=CSSDEF>CSS</DFN> er en ny standard fra W3C.. Nå heter DFN-elementet i eksempelet CSSDEF, og dette navnet kan nå brukes som selektor i en stilregel slik: #CSSDEF { color: kufiolilla }

Vær klar over at et ID-attributt skal identifisere elementet det står på, slik at du ikke kan ha to like IDer i et dokument.

Kommentarer

Det er også mulighet for å sette inn tekst i CSS-stilsett som ignoreres av vev-leserne. Dette kalles kommentarer og brukes stort sett til beskjeder og påminnelser til deg selv og andre, eller til å gjøre det lettere å holde oversikten. Kommentarer begynner med /* og slutter med */. Følgende er en fullstendig kommentar: /* Dette kan ingen se */.

Oversikt over CSS-egenskaper

Dette er en liten oversikt over noen av de viktigste CSS-egenskapene. Den er ikke komplett, men skulle gi et utgangspunkt for å skrive CSS-stilsett. Mer komplette oversikter finnes i referansene.

Enheter i CSS

Relative og absolutte enheter

Størrelsesenhetene i CSS er av to typer: absolutte og relative. Dersom du bruker en relativ enhet angir du hvor stort noe skal være i forhold til noe annet. Dette kan utnyttes for å få ting til å tilpasse seg varierende størrelser. Absolutte størrelser, derimot, er alltid de samme og angis direkte. 1.5 cm er en absolutt størrelse, mens 120 % (av et eller annet) er en relativ størrelse.

Størrelsesenhetene

Det er tre relative størrelses-enheter:

em
Høyden på skriften i elementet.
ex
X-høyde, dvs høyden på bokstaven x i elementet.
px
Pixler, dvs: punkter på skjermen. Størrelsen på disse vil variere med oppløsningen.

Det er fem absolutte størrelses-enheter. Disse bør brukes med forsiktighet, ettersom de ikke tilpasser seg leserens omgivelser på noen måte:

in
Tommer. (En tomme er 2.54 cm.)
cm
Centimeter.
mm
Millimeter.
pt
Punkter. (Ett punkt er 1/72 tomme, altså 0.0352 cm.)
pc
Pica. (En pica er 12 punkter, altså 1/6 tomme, eller 0.423 cm.)

Prosent-enheter

Prosent-enheter i CSS skrives uten mellomrom, f.eks. slik: font-size: 90%. Negative prosenttall er i noen sammenhenger tillatt.

Egenskaper som påvirker skriften

font-family
Denne egenskapen brukes til å angi skriftype.
font-style
Kan ha tre verdier: normal, italic (kursiv), oblique (hellende)
font-weight
Brukes til å angi hvor fet skriften skal være. Verdiene kan være normal, bold (fet), bolder (fetere enn elementet rundt), lighter (mindre fet enn elementet rundt) eller 100, 200, 300, ..., 900.
font-size
Angir hvor stor skriften kan være, enten relativt eller absolutt. For å angi størrelse i forhold til elementet rundt brukes larger, smaller eller en prosent-størrelse. For å sette størrelse uavhengig av størrelsen på skriften i elementet rundt (men likevel skalerbart) kan du bruke xx-small, x-small, small, medium, large, x-large, xx-large. Man kan også bruke en av lengde-enhetene, både de relative og de absolutte.

Farge-egenskaper

Hvordan angi farger i CSS

Farger i CSS kan angis enten med en fargekode eller med et av seksten fargenavn: aqua, black, blue, fuchsia, gray, green, lime, maroon, navy, olive, purple, red, silver, teal, white eller yellow.

Fargekodene er de samme som i HTML, nemlig #RRGGBB, der RR er et heksadesimalt tall mellom 0 og 255 (og angir mengden av rødt), mens GG angir grønt og BB blått. (Det er flere måter å skrive det samme på, se referansene hvis du er interessert.)

Egenskapene

color
Denne egenskapen angir tekstfargen i et element.
background-color
Angir bakgrunnsfargen. Denne egenskapen har verdien "transparent" hvis den ikke angis, hvilket vil si at bakgrunnsfargen arves fra det omkringliggende elementet.
background-image
Angir et bakgrunnsbilde. F.eks. slik: BODY { background-image: url(bg.gif) }

Tekst-egenskaper

text-align
Angir hvordan teksten skal justeres og tar følgende verdier: left (mot venstre marg), høyre (mot høyre marg), center (sentreres) og justify (som betyr mot både venstre og høyre marg).
text-indent
Angir hvor mye teksten skal flyttes inn fra venstre marg. Verdien skal være en lengde-verdi eller oppgis i prosent av foreldre-elementets vidde.
line-height
Angir hvor store linjene skal være i forhold til teksten. (Kan altså brukes til å lage luft mellom linjene.) Kan angis med enten en prosent-verdi (i forhold til font-størrelsen) eller et tall. I det siste tilfellet blir høyden font-størrelsen ganget med tallet.

Boks-egenskaper

margin-left
Angir størrelsen på venstre marg, enten med en lengde-verdi eller en prosent av foreldre-elementets bredde.
margin-right
Angir størrelsen på høyre marg, på akkurat samme måte som margin-left.
margin-top
Angir størrelsen på margen over elementet, også på samme måte som margin-left, men nå relativt til elementets høyde.
margin-bottom
Angir størrelsen på margen over elementet, på samme måte som margin-top.
border-style
Angir utseendet på en ramme (kantlinje) rundt elementet. Kan være none (ingen ramme), dotted (prikker), dashed (små korte streker), solid (heltrukket linje), double (to doble linjer), groove (senket linje), ridge (hevet linje), inset (utstående relieff) eller outset (senket relieff). En rekke forskjellige stil-egenskaper lar deg angi farge, bredde osv på rammen (kantlinjen).
float
Angir at (og hvordan) teksten skal flyte rundt elementet. Gyldige verdier er left, right og none.

Mer avanserte stilsett

Avanserte selektorer

Pseudo-klasser

CSS har en del forhåndsdefinerte klasser som ikke egentlig er klasser i vanlig forstand, for å få til ting som ellers ville vært svært vanskelige. Hvordan ville du f.eks. velge farge på besøkte og ikke-besøkte linker med det du hittil har lært av CSS?

Til dette finnes det tre forhåndsdefinerte pseudo-klasser på A-elementet: link, visited og active. En selektor bruker pseudo-klasser slik:element:pseudo-klasse { stilregler }. Dermed skal altså disse pseudo-klassene brukes slik:

A:link
Setter stilegenskapene for ubesøkte linker.
A:visited
Setter stilegenskapene for besøkte linker.
A:active
Setter stilegenskapene for linker i det de klikkes på.

Det finnes to pseudoklasser til: first-line og first-letter, og disse kan brukes for å få til spesielle effekter på henholdvis første linje og første bokstav av teksten i et blokknivå-element. (Dvs: P, H1, BLOCKQUOTE etc, men ikke EM, STRONG osv.)

Kontekst-matching

Det er mulig å forskjellsbehandle elementer etter hvilken sammenheng de står i. For eksempel: dersom man har en liste av lister der LI i den ytterste listen brukes som overskrifter for de innerste listene ønsker man kanskje å fremheve overskriftene. Det kan gjøres slik:


/* LI'ene i den ytterste listen: */
UL LI    { font-size: large }

/* LI'ene i den innerste listen: */
UL UL LI { font-size: normal }

Den øverste regelen gjelder LI-elementer som står inne i en UL, mens den andre gjelder LI-elementer i en UL som igjen står inne i en annen UL. Du legger kanskje merke til at den øverste regelen gjelder i begge tilfeller? Det gjør ikke noe, for den nederste er mest spesifikk, så når den slår til vil den overstyre den øverste. (Mer om reglene for dette lenger ned.)

Generelle klasser

Du kan angi en stilregel som skal gjelde for alle elementer i samme klasse, uavhengig av hvilke de er. Regelen .klasse { deklarasjon } vil gjelde både <P CLASS=klasse>Dette avsnittet.</P> og <EM CLASS=klasse>denne frasen</EM>.

Lister av selektorer

Dersom du vil at alle overskrifter skal være i Helvetica, uansett hvilket nivå de er på kan du gjøre det slik: H1, H2, H3, H4, H5, H6 { font-family: Helvetica }

Luretriks

NOSTYLE

Av og til ønsker man å skrive noe som bare skal synes for de som har vevlesere som ikke forstår CSS. Dette kan gjøres svært enkelt med CSS: sett egenskapen display til none, og elementet vil ikke vises. Med andre ord kan man bruke en ID eller CLASS eller noe helt annet for å unngå at elementet vises.

SPAN og DIV

HTML inneholder to elementer som kan brukes som elementer uten noen form for betydning. Dvs: innholdet i CODE-elementet skal være programkode, HTML-markup, CSS-stilsett eller lignende. Det ligger ingen slike føringer på hva som kan være inne i SPAN og DIV, annet enn at DIV er et blokk-nivå element (på linje med P, PRE og TABLE), mens SPAN er på tekst-nivå (på linje med EM og A).

Disse to elementene er dermed svært greie å kombinere med CLASS for å lage egne pseudo-elementer for ting som ikke finnes i HTML, der det ikke passer å ta over noen av elementene i HTML. Dette kan være dersom man ikke ønsker linjeskift og lignende formateringsføringer.

To kolonner uten tabeller

I CSS er det fullt mulig å få til en layout som bruker to kolonner uten at man må ty til tabeller. Dette kan gjøres ved å legge ett "beholder"-element rundt hver kolonne (DIV med passende CLASS egner seg bra, siden det er snakk om ting på blokk-nivå) og så sette på de riktige CSS-egenskapene, f.eks. slik:


DIV.venstre { width: 30%; float: left  }
DIV.hoyre   { width: 70%; float: right }

Dette skulle være ekvivalent med:


<TABLE>
<TR><TD WIDTH="30%"> ...Innhold i venstre kolonne her...
    <TD WIDTH="70%"> ...Innhold i høyre kolonne her...
</TABLE>       

Brukere som ikke har stilsett vil ikke få de to kolonnene. I stedet vil den kolonnen som står først i teksten komme øverst, og den andre vil komme under. Siden bør være like leselig når den vises på denne måten.

Å inkludere andre stilsett

Ofte ønsker man å kunne dele stilregler mellom flere forskjellige stilsett. CSS har en enkel måte å håndtere dette på: @import lar deg inkludere et stilsett i et annet. @import-setninger kan settes inn blant stilreglene, og ser slik ut: @import url(http://www.server.dom/path/fil.css); De behøver selvsagt ikke være absolutte som her, men kan også være relative, akkurat som vanlige HTML-linker.

CSS-støtte i forskjellige vev-lesere

Hvilke vev-lesere støtter CSS?

Følgende vev-lesere har hel eller delvis støtte pr 02.10.97:

W3C har en mer oppdatert liste.

Flere mye brukte vev-lesere støtter ikke CSS, som f.eks. Lynx, Netscape Navigator 3.0. Dette betyr at du hvis du skriver sider som er avhengige av CSS for å være leselige vil svært mange av leserne dine ikke kunne lese dem. Dette vil normalt ikke være noe problem hvis man skriver noenlunde fornuftig HTML og kan lett testes ved at man skrur av stilsett i vevleseren sin og ser på sidene.

Mangler ved CSS-støtten i Netscape og MSIE

Dette er svært alvorlig fordi det betyr at enkelte helt korrekte sider vil være uleselige for svært mange lesere. Det bryter altså med prinsippet om at CSS skal "degrade gracefully". Feilen ligger selvsagt hos Microsoft/Netscape, men det hjelper ikke den stakkars leseren. Her må man antagelig teste sidene med de forskjellige vev-leserne for å være helt sikker på at de er leselige.

En alternativ holdning er at man ikke skal tilpasse seg programvare med alvorlige feil. Dette for å unngå at enkelte deler av CSS-standarden forblir umulige å bruke i all evighet fordi brukerne fortsetter å bruke dårlig programvare. (De vil jo ikke skifte til noe annet hvis de aldri opplever problemer med vev-leseren sin.) Du får selv velge hva du vil gjøre; jeg vil ikke gi noen anbefalinger her.

Se referansene for mer detaljert oversikt over feil og mangler. En ting som er verdt å merke seg er at Opera har veldig bra støtte for CSS.

Hvordan stilregler anvendes

Pass på å lese videre helt til avsnittet "En avsluttende moralpreken", ellers kan du risikere å misforstå reglene!

Når man skriver litt store og kompliserte stilsett (eller kombinerer bruker-stilsett med forfatter-stilsett) kommer man fort i den situasjon at flere forskjellige stilregler gjelder samme element. Dette kan virke forvirrende, men de som laget CSS har forutsett problemet og laget regler for hvilke regler som skal gjelde i disse tilfellene.

Reglene er slik: til enhver tid gjelder den mest spesifikke stilregelen som passer. For hvert element i dokumentet, gå gjennom alle stilreglene i stilsettet og beregn en poengsum for hver regel etter følgende formel og velg regelen med flest poeng:

   10000*c+100*b+a

Der bokstavene står for:

a
Antall elementer angitt i selektoren.
b
Antall klasse-navn angitt i selektoren.
c
Antall IDer angitt i selektoren. (I praksis vil det bare være en og som regel vil da a og b være 0.)

For å ta noen eksempler:

  LI            {...}  /* a=1 b=0 c=0 -> poeng =       1 */
  UL LI         {...}  /* a=2 b=0 c=0 -> poeng =       2 */
  UL OL LI      {...}  /* a=3 b=0 c=0 -> poeng =       3 */
  LI.red        {...}  /* a=1 b=1 c=0 -> poeng =     101 */
  UL OL LI.red  {...}  /* a=3 b=1 c=0 -> poeng =     103 */ 
  #x34y         {...}  /* a=0 b=0 c=1 -> poeng =   10000 */

Her vil altså regelen med ID #x34y bli valgt, hvilket er fornuftig når man tenker over det: regelen er skrevet spesielt for dette elementet, og da ville det vært litt dumt om den ikke gjaldt.

Dersom to regler skulle få samme poengsum vil den regelen som står sist i teksten gjelde.

Noen spesialtilfeller

Stilregler angitt med STYLE-attributtet

Så kan man lure på: hvordan passer stilegenskaper som er angitt med STYLE-attributtet inn i dette? De har jo ingen selektor, så hvordan skal man gi dem poeng? Svaret er ganske logisk: de teller som en stilregel med ID-verdi. (Og siden de står sist i teksten, og på det elementet de gjelder, vil de slå ut andre stilregler med ID-verdi.)

Presentasjon angitt i HTML-markupen

Det går også an å angi presentasjon i HTML-markupen, f.eks. av hensyn til vev-lesere som ikke støtter CSS. En vev-leser som støtter CSS skal oppfatte dette som stilregler med 1 poeng angitt av forfatteren aller først i stilsettet. De blir med andre ord en del av stilsettet.

Stilregler med flere selektorer

Som jeg allerede har nevnt kan man sette flere forskjellige selektorer etter hverandre på denne måten H1, H2 { deklarasjon }. Denne regelen vil ikke få to poeng, men vil i stedet betraktes som to forskjellige regler, slik:

  H1            {...}  /* a=1 b=0 c=0 -> poeng =       1 */
  H2            {...}  /* a=1 b=0 c=0 -> poeng =       1 */

Bruk av komma for å skille selektorer er altså bare en kortere måte å skrive stilregler på, slik at hvis man i flere tilfeller deler stilegenskaper kan man ramse opp alle tilfellene, og så slenge på stilegenskapene etterpå.

Selektorer og egenskaper

En måte å utnytte dette med flere selektorer per stilregel kunne være å skrive slik:


  H1, H2, H3, H4, H5, H6  { font-family: Helvetica, Sans-Serif }
  H1                      { font-size: 18pt                    }
  H2                      { font-size: 16pt                    }
  osv

Så er spørsmålet, vil en H1 da vises i Helvetica eller med 18 punkters skriftstørrelse? Svaret er kanskje ikke så overraskende: begge deler. Utvelgelsen av hvilke stilregler som gjelder gjøres på nytt for hver egenskap. Med andre ord så vil følgende element:


  <P CLASS=advarsel ID=14>Ikke trykk på knappen
  merket "Self-destruct"!</P>

kombinert med følgende stilsett:


  P.advarsel { color: red; font-weight: bold; text-align: center }
  #14        { text-align: left }

vises med rød fet skrift, men vil ikke sentreres, fordi ID-regelen overstyrer klasse-regelen. Det viktige her er at ID-regelen ikke overstyrer fargen eller skrift-vekten, fordi den ikke sier noe om disse egenskapene. Igjen ganske logisk, og omtrent slik man ville vente.

Forfatterens og leserens stilsett

Ett siste punkt gjenstår før vi er ferdige med behandlingen av kaskade-rekkefølgen: forholdet mellom forfatterens stilregler og brukerens stilregler.

For å få til dette må vi innføre to variable til i formelen jeg anga ovenfor:

d
2 hvis stilregelen kommer fra forfatteren, 1 hvis den kommer fra leserens oppsett og 0 hvis den kommer fra vev-leserens standard-oppsett.
e
1 hvis stilregelen er merket "!important", ellers 0.

slik at vi får formelen:

    100000000*e+1000000*d+10000*c+100*b+a

Dette er altså den endelige formelen for stilregel-sortering. Legg merke til at det er viktigere hva forfatteren av siden mener, enn hva du mener. I det opprinnelige CSS-forslaget var rekkefølgen omvendt, men etter press fra Microsoft og Netscape ble dette gjort om.

Dette er faktisk noe av et problem fordi jeg selv f.eks. forventer at linker er understreket i grafiske vev-lesere. Slik har det vært siden jeg begynte å bruke NCSA Mosaic i 1994, og slik vil jeg at det fortsatt skal være for meg, andre kan gjøre hva de vil.

Resultatet er at en forfatter kan si: A { text-decoration: none !important }, og vips får ikke linkene mine understreking, uansett hva jeg gjør, noe som vil både forvirre og irritere meg som leser. Med andre ord: rekkefølgen burde vært omvendt, men siden den ikke er det legger det mer ansvar på deg som forfatter av stilsett. Bruk !important med forsiktighet!

En avsluttende moralpreken

Skriv korrekt HTML

Det er viktig å skrive korrekt HTML når man bruker CSS, fordi vev-leserne ellers kan få problemer med å vise sidene riktig. Dette gjelder også når man ikke bruker CSS, men vev-leserne blir ekstra følsomme når man gjør det. Den enkleste måten å garantere at man skriver korrekt HTML på er å bruke en validator. Du finner mer informasjon om validatorer i referansene.

Ikke gjør deg avhengig av CSS

I og med at mange av leserne dine bruker programmer som ikke forstår CSS er det viktig at siden din er like leselig uten CSS. Å få til dette skulle ikke være så vanskelig, i og med at du kan skrive vanlig ren HTML og så bruke CSS til layouten.

Det er også en god ting å ikke gjøre seg avhengig av ID- og CLASS-attributtene, slik at dokumentet fortsatt er leselig dersom noen skulle finne på å ignorere ditt stilsett og heller bruke sitt eget. Om noen fargekodinger og slikt forsvinner er ikke det så farlig, poenget er at dokumentet fortsatt må være leselig.

Husk å alltid angi både forgrunn og bakgrunn

Alle vev-lesere har standardverdier for link-fargene i tillegg til dokumentenes forgrunns- og bakgrunnsfarger. Dette betyr at dersom du bare oppgir noen av disse fargene i ditt stilsett vil leserens vev-leser bruke sine standard-instillinger (enten fra et stilsett eller de som er satt opp i vevleseren). Problemet med dette er at du ikke kan vite hvilke farger dette er, slik at du risikerer at de kolliderer med de du selv har oppgitt. Resultatet kan f.eks. bli at leseren blir presentert for hvit tekst på hvit bakgrunn, som ikke er spesielt leselig.

Dersom du angir et bakgrunnsbilde til dokumentet ditt bør du også tenke på de som ikke laster bilder. Med andre ord: du bør angi en bakgrunnsfarge som erstatning for bakgrunnsbildet.

Vær forsiktig med å angi font

Arial er en populær font som brukes av mange "webdesignere". Man bør imidlertid være klar over at denne fonten kun finnes for Windows, slik at man bør oppgi alternativer for andre plattformer. Dette kan f.eks. gjøres slik: BODY { font-family: Arial, Helvetica, Sans-serif }.

Helvetica er det egentlige navnet på denne fonten, og Helvetica-fonter finnes på de aller fleste plattformer. Aller sist bør man angi en av de generiske font-familiene som er oppgitt i CSS-spesifikasjonen:

Merk også at font-navn som inneholder mellomrom bør settes i anførselstegn.

Alt som står inne i anførselstegn vil bli tolket som ett navn, slik at "Arial, Helvetica, Sans-Serif" vil tolkes som ett fontnavn, ikke tre.

Unngå absolutte størrelser

Størrelsesenheter som pt, px, in og cm bør unngås, fordi du ikke vet hva slags omgivelser dokumentet ditt vil bli vist under. Bruk i stedet prosent, em, ex og tilsvarende, som tilpasser seg dokumentet og skriftstørrelsene.

Til skriftstørrelser er kanskje disse verdiene de beste å bruke: xx-small, x-small, small, medium, large, x-large og xx-large.

Ikke angi mer enn nødvendig

Tenk på at stilsettet og dokumentet ditt skal tilpasse seg en mengde forskjellige omgivelser og bruker-stilsett. For å få til dette best mulig bør du unngi å oppgi flere stilegenskaper enn absolutt nødvendig. Alle deklarasjoner som ikke endrer hvordan dokumentet ser ut i forhold til standard-oppsettet bør unngås.

En vanlig feil er f.eks å sette tekststørrelse til 12pt i BODY-elementet (altså hele dokumentet), når standard-størrelse faktisk er 12pt i utgangspunktet. Dette er jo meningsløst, særlig hvis det overstyrer en bruker som forsøker å sette f.eks 14pt i sitt bruker-stilsett.

Tenk deg altså om to ganger før du slenger på en ny deklarasjon og gå gjerne over stilsettet etterpå for å luke ut de overflødige.





CSS Default Values Reference

Default CSS Values for HTML Elements

The table below shows the default CSS browser values for all HTML elements.

PB: Jeg har modifisert denne litt, fjernet siste kolonne med - Try it - linker.

ElementDefault CSS Value
a:linkcolor: (internal value);
text-decoration: underline;
cursor: auto;
a:visitedcolor: (internal value);
text-decoration: underline;
cursor: auto;
a:link:activecolor: (internal value);
a:visited:activecolor: (internal value);
abbrNone.
addressdisplay: block;
font-style: italic;
areadisplay: none;
articledisplay: block;
asidedisplay: block;
audioNone.
bfont-weight: bold;
baseNone.
bdiNone.
bdounicode-bidi: bidi-override;
blockquotedisplay: block;
margin-top: 1em;
margin-bottom: 1em;
margin-left: 40px;
margin-right: 40px;
bodydisplay: block;
margin: 8px;
body:focusoutline: none;
brNone.
buttonNone
canvasNone.
captiondisplay: table-caption;
text-align: center;
citefont-style: italic;
codefont-family: monospace;
coldisplay: table-column;
colgroupdisplay: table-column-group
datalistdisplay: none;
dddisplay: block;
margin-left: 40px;
deltext-decoration: line-through;
detailsdisplay: block;
dfnfont-style: italic;
dialogNone.
divdisplay: block;
dldisplay: block;
margin-top: 1em;
margin-bottom: 1em;
margin-left: 0;
margin-right: 0;
dtdisplay: block;
emfont-style: italic;
embed:focusoutline: none;
fieldsetdisplay: block;
margin-left: 2px;
margin-right: 2px;
padding-top: 0.35em;
padding-bottom: 0.625em;
padding-left: 0.75em;
padding-right: 0.75em;
border: 2px groove (internal value);
figcaptiondisplay: block;
figuredisplay: block;
margin-top: 1em;
margin-bottom: 1em;
margin-left: 40px;
margin-right: 40px;
footerdisplay: block;
formdisplay: block;
margin-top: 0em;
h1display: block;
font-size: 2em;
margin-top: 0.67em;
margin-bottom: 0.67em;
margin-left: 0;
margin-right: 0;
font-weight: bold;
h2display: block;
font-size: 1.5em;
margin-top: 0.83em;
margin-bottom: 0.83em;
margin-left: 0;
margin-right: 0;
font-weight: bold;
h3display: block;
font-size: 1.17em;
margin-top: 1em;
margin-bottom: 1em;
margin-left: 0;
margin-right: 0;
font-weight: bold;
h4display: block;
margin-top: 1.33em;
margin-bottom: 1.33em;
margin-left: 0;
margin-right: 0;
font-weight: bold;
h5display: block;
font-size: .83em;
margin-top: 1.67em;
margin-bottom: 1.67em;
margin-left: 0;
margin-right: 0;
font-weight: bold;
h6display: block;
font-size: .67em;
margin-top: 2.33em;
margin-bottom: 2.33em;
margin-left: 0;
margin-right: 0;
font-weight: bold;
headdisplay: none;
headerdisplay: block;
hrdisplay: block;
margin-top: 0.5em;
margin-bottom: 0.5em;
margin-left: auto;
margin-right: auto;
border-style: inset;
border-width: 1px;
htmldisplay: block;
html:focusoutline: none;
ifont-style: italic;
iframe:focusoutline: none;
iframe[seamless]display: block;
imgdisplay: inline-block;
inputNone.
instext-decoration: underline;
kbdfont-family: monospace;
labelcursor: default;
legenddisplay: block;
padding-left: 2px;
padding-right: 2px;
border: none;
lidisplay: list-item;
linkdisplay: none;
mainNone.
mapdisplay: inline;
markbackground-color: yellow;
color: black;
menudisplay: block;
list-style-type: disc;
margin-top: 1em;
margin-bottom: 1em;
margin-left: 0;
margin-right: 0;
padding-left: 40px;
menuitemNone.
metaNone.
meterNone.
navdisplay: block;
noscriptNone.
object:focusoutline: none;
oldisplay: block;
list-style-type: decimal;
margin-top: 1em;
margin-bottom: 1em;
margin-left: 0;
margin-right: 0;
padding-left: 40px;
optgroupNone.
optionNone.
outputdisplay: inline;
pdisplay: block;
margin-top: 1em;
margin-bottom: 1em;
margin-left: 0;
margin-right: 0;
paramdisplay: none;
pictureNone.
predisplay: block;
font-family: monospace;
white-space: pre;
margin: 1em 0;
progressNone.
qdisplay: inline;
q::beforecontent: open-quote;
q::aftercontent: close-quote;
rpNone.
rtline-height: normal;
rubyNone.
stext-decoration: line-through;
sampfont-family: monospace;
scriptdisplay: none;
sectiondisplay: block;
selectNone.
smallfont-size: smaller;
sourceNone.
spanNone.
striketext-decoration: line-through;
strongfont-weight: bold;
styledisplay: none;
subvertical-align: sub;
font-size: smaller;
summarydisplay: block;
supvertical-align: super;
font-size: smaller;
tabledisplay: table;
border-collapse: separate;
border-spacing: 2px;
border-color: gray;
tbodydisplay: table-row-group;
vertical-align: middle;
border-color: inherit;
tddisplay: table-cell;
vertical-align: inherit;
templateNone.
textareaNone.
tfootdisplay: table-footer-group;
vertical-align: middle;
border-color: inherit;
thdisplay: table-cell;
vertical-align: inherit;
font-weight: bold;
text-align: center;
theaddisplay: table-header-group;
vertical-align: middle;
border-color: inherit;
timeNone.
titledisplay: none;
trdisplay: table-row;
vertical-align: inherit;
border-color: inherit;
trackNone.
utext-decoration: underline;
uldisplay: block;
list-style-type: disc;
margin-top: 1em;
margin-bottom: 1 em;
margin-left: 0;
margin-right: 0;
padding-left: 40px;
varfont-style: italic;
videoNone.
wbrNone.

• • _ T _ H _ E _ - _ E _ N _ D _ • •