Bakgrundsbilder

CSS

Bilder

Med <img> lägger man till bilder som innehåll i HTML. Kompletteras med alt-attribut för bildbeskrivning.

 

Backgrundsbilder är inte till för innehåll utan för dekoration. De läggs till i CSS. Inget alt-attribut.

Två sätt! ✌️

Bakgrundsbild

 .selector {

	 background-image: url("image_location/filename.jpg");
    
 }

Background 

CSS properties

background-color:

background-image:

background-position:

background-size:

background-repeat:

 

<color>

url() / gradient

left / center / right / top / bottom

auto / cover / contain

repeat /no-repeat / repeat-x / repeat-y

 

Även background-attachment, background-origin, background-clip ....

Background 

Interaktiv guide

Bakgrundsbilder med CSS

By Sandra Larsson

Bakgrundsbilder med CSS

  • 248