CSS-reunuksen väri


Sisällysluettelo

    Näytä sisällysluettelo


CSS-reunuksen väri

Ominaisuutta border-color käytetään neljän reunuksen värin asettamiseen.

Värin voi asettaa seuraavasti:

  • nimi - määritä värin nimi, kuten "punainen"

  • HEX - määritä HEX-arvo, kuten "#ff0000"

  • RGB - määritä RGB-arvo, kuten "rgb(255,0,0)"

  • HSL - määritä HSL-arvo, kuten "hsl(0, 100%, 50%)"

  • läpinäkyvä

Huomaa: jos border-color-asetusta ei ole asetettu, se perii elementin värin.

Esimerkki

Erilaisten reunusten värien esittely:

p.one
{
   
border-style: solid;
   
border-color: red;
}

p.two
{
   
border-style: solid;
  border-color: green;
}
p.three {
  border-style: dotted;
  border-color: 
  blue;
}

Tulos:

Red border
Green border
Blue border

Kokeile itse →

<!DOCTYPE html>
<html>
<head>
<style>
p.one {
  border-style: solid;
  border-color: red;
}

p.two {
  border-style: solid;
  border-color: green;
} 

p.three {
  border-style: dotted;
  border-color: blue;
} 
</style>
</head>
<body>

<h2>The border-color Property</h2>
<p>This property specifies the color of the four borders:</p>

<p class="one">A solid red border</p>
<p class="two">A solid green border</p>
<p class="three">A dotted blue border</p>

<p><b>Note:</b> The "border-color" property does not work if it is used alone. Use the "border-style" property to set the borders first.</p>

</body>
</html>



Tietyt sivuvärit

border-color-ominaisuudella voi olla yhdestä neljään arvoa (esim. yläreuna, oikea reuna, alareuna ja vasen reuna).

Esimerkki

 p.one {
  border-style: solid;
  border-color: red green blue yellow; 
  /* red top, green right, blue bottom and yellow left */
}

Kokeile itse →

<!DOCTYPE html>
<html>
<head>
<style>
p.one {
  border-style: solid;
  border-color: red green blue yellow; /* red top, green right, blue bottom and yellow left */
}
</style>
</head>
<body>

<h2>The border-color Property</h2>
<p>The border-color property can have from one to four values (for the top border, right border, bottom border, and the left border):</p>

<p class="one">A solid multicolor border</p>

</body>
</html>




HEX-arvot

Reunuksen väri voidaan määrittää myös käyttämällä heksadesimaaliarvoa (HEX):

Esimerkki

 p.one {
  border-style: solid;
  border-color: #ff0000; /* red 
  */
}

Kokeile itse →

<!DOCTYPE html>
<html>
<head>
<style>
p.one {
  border-style: solid;
  border-color: #ff0000; /* red */
}

p.two {
  border-style: solid;
  border-color: #0000ff; /* blue */
}

p.three {
  border-style: solid;
  border-color: #bbbbbb; /* grey */
}
</style>
</head>
<body>

<h2>The border-color Property</h2>
<p>The color of the border can also be specified using a hexadecimal value (HEX):</p>

<p class="one">A solid red border</p>
<p class="two">A solid blue border</p>
<p class="three">A solid grey border</p>

</body>
</html>



RGB-arvot

Tai käyttämällä RGB-arvoja:

Esimerkki

 p.one {
  border-style: solid;
  border-color: rgb(255, 0, 0); 
  /* red */
}

Kokeile itse →

<!DOCTYPE html>
<html>
<head>
<style>
p.one {
  border-style: solid;
  border-color: rgb(255, 0, 0); /* red */
}

p.two {
  border-style: solid;
  border-color: rgb(0, 0, 255); /* blue */
}

p.three {
  border-style: solid;
  border-color: rgb(187, 187, 187); /* grey */
}
</style>
</head>
<body>

<h2>The border-color Property</h2>
<p>The color of the border can also be specified using RGB values:</p>

<p class="one">A solid red border</p>
<p class="two">A solid blue border</p>
<p class="three">A solid grey border</p>

</body>
</html>



HSL-arvot

Voit myös käyttää HSL-arvoja:

Esimerkki

 p.one {
  border-style: solid;
  border-color: hsl(0, 100%, 50%); 
  /* red */
}

Kokeile itse →

<!DOCTYPE html>
<html>
<head>
<style>
p.one {
  border-style: solid;
  border-color: hsl(0, 100%, 50%); /* red */
}

p.two {
  border-style: solid;
  border-color: hsl(240, 100%, 50%); /* blue */
}

p.three {
  border-style: solid;
  border-color: hsl(0, 0%, 73%); /* grey */
}
</style>
</head>
<body>

<h2>The border-color Property</h2>
<p>The color of the border can also be specified using HSL values:</p>

<p class="one">A solid red border</p>
<p class="two">A solid blue border</p>
<p class="three">A solid grey border</p>

</body>
</html>


Voit oppia lisää HEX-, RGB- ja HSL-arvoista CSS-värit-luvuissamme.