CSS ramar

CSS gör det enkelt att bestämma hur ramarna på ett element ska utformas.

HTML

<p>En paragraf med lite text</p>
<p class="foo">En paragraf till</p>

Ramens stil

CSS-egenskapen "border-style" används för att bestämma stil på en ram.

CSS

p {border-style:dashed}

Exempel

border-style: none

border-style: dotted

border-style: dashed

border-style: solid

border-style: double

border-style: groove

border-style: ridge

border-style: inset

border-style: outset


Rambredd

CSS-egenskapen "border-width" används för att bestämma hur bred ramen ska vara.

Värdet kan anges i px eller med orden: thin, medium, or thick.

CSS

p {border-style:solid; border-width:10px;}
.foo {border-style:dashed; border-width:thick;}

CSS-egenskapen "border-width" kan inte användas utan att också egenskapen "border-style" anges. Detta beror på att standardinställning för "border-style" är "none".

Ramfärg

CSS

p {border-style:solid; border-color:blue;}
.foo {border-style:solid; border-color:#000000;}

Läs mer om färger i HTML color

Olika egenskaper för ramens olika sidor

Det går att bestämma olika css-egenskaper för ramens olika sidor.

CSS

p {
border-top-color:blue;
border-top-style:solid;
border-top-width:3px;

border-right-color:green;
border-right-style:dashed;
border-right-width:5px;

border-bottom-color:red;
border-bottom-style:dotted;
border-bottom-width:thick;

border-left-color:yellow;
border-left-style:double;
border-left-width:2px;
}

Samlingsegenskap för ramar

Med egenskapen "border" är det möjligt att ange alla egenskaper för en ram på samma gång.

Egenskaperna måse anges i ordningen: border-width, border-style, border-color.

CSS

p {border:2px solid red}
.foo {border:3px dashed black}

Det är viktigt att egenskaperna anges precis samma ordning som i exemplet ovanför för att det ska fungera.

Notera att det går bra att utelämna en eller flera egenskaper. Då kommer den utelämnade egenskapen att anta få standardvärdet som är 1px none black.

CSS

p {border:solid red}
.foo {border:3px dashed}

Det går också att ange nya egenskaper för ramar så länge de anges nedanför samlingsegenskapen.

CSS

p {border:3px dashed}
p {border-color:red}
p.foo {border-color:blue}

Egenskaper som anges innan samlingsegenskapen "skrivs dock över". Se nedanstående exempel:

CSS

p {border:3px dashed}
p {border-color:red}

Samlingsegenskaper för individuella ramar

Samlingsegenskaper kan också gälla individuell ram.

CSS

p {border-top:1px solid blue}
p {border-right:1px dotted red}
p {border-bottom:2px double yellow}
p {border-left:1px dashed green}

Samlingsegenskaper för enskilda egenskaper

Samlingsegenskaper kan också gälla en enskild egenskap.

CSS

p {border-color:red green blue orange}
p {border-style:solid dotted dashed double}
p {border-width:1px 2px 3px 4p}

Värdena anges i tur och ordning för topp, höger, botten och vänster.

Det går även att ange färre egenskaper än fyra.

CSS

p {border-color:red}

p {border-style:solid dotted}
p {border-width:1px 4px 8px}

 

CSS Border Properties

The CSS border properties allow you to specify the style and color of an element's border. In HTML we use tables to create borders around a text, but with the CSS border properties we can create borders with nice effects, and it can be applied to any element.

Browser support: IE: Internet Explorer, F: Firefox, N: Netscape.

W3C: The number in the "W3C" column indicates in which CSS recommendation the property is defined (CSS1 or CSS2).

Property Description Values IE F N W3C
border A shorthand property for setting all of the properties for the four borders in one declaration border-width
border-style
border-color
4 1 4 1
border-bottom A shorthand property for setting all of the properties for the bottom border in one declaration border-bottom-width
border-style
border-color
4 1 6 1
border-bottom-color Sets the color of the bottom border border-color 4 1 6 2
border-bottom-style Sets the style of the bottom border border-style 4 1 6 2
border-bottom-width Sets the width of the bottom border thin
medium
thick
length
4 1 4 1
border-color Sets the color of the four borders, can have from one to four colors color 4 1 6 1
border-left A shorthand property for setting all of the properties for the left border in one declaration border-left-width
border-style
border-color
4 1 6 1
border-left-color Sets the color of the left border border-color 4 1 6 2
border-left-style Sets the style of the left border border-style 4 1 6 2
border-left-width Sets the width of the left border thin
medium
thick
length
4 1 4 1
border-right A shorthand property for setting all of the properties for the right border in one declaration border-right-width
border-style
border-color
4 1 6 1
border-right-color Sets the color of the right border border-color 4 1 6 2
border-right-style Sets the style of the right border border-style 4 1 6 2
border-right-width Sets the width of the right border thin
medium
thick
length
4 1 4 1
border-style Sets the style of the four borders, can have from one to four styles none
hidden
dotted
dashed
solid
double
groove
ridge
inset
outset
4 1 6 1
border-top A shorthand property for setting all of the properties for the top border in one declaration border-top-width
border-style
border-color
4 1 6 1
border-top-color Sets the color of the top border border-color 4 1 6 2
border-top-style Sets the style of the top border border-style 4 1 6 2
border-top-width Sets the width of the top border thin
medium
thick
length
4 1 4 1
border-width A shorthand property for setting the width of the four borders in one declaration, can have from one to four values thin
medium
thick
length
4 1 4 1