• We just launched and are currently in beta. Join us as we build and grow the community.

Borders

Zaluke

Platform Insights Analyst
Z Rep
0
0
0
Rep
0
Z Vouches
0
0
0
Vouches
0
Posts
164
Likes
89
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 300 XP
Introduction:
This is the fourth part in my CSS Styling tutorials, in which I will be covering Borders.

Order:
Borders around elements come between the elements margin and padding. So, if the element has padding, the border will be away from the element whereas if the element only has margin, the border will be next the element but away from other elements.

Basic Structure:
The basic border attribute takes three arguments; Width, Type, Colour. The below code would give a solid white border that is 5 pixels width...

  1. border

    :

    5px

    solid

    #ffffff

    ;

Or this code would give a dashed black border of 3 pixels width...

  1. border

    :

    3px

    dashed

    #000000

    ;

There is also;
dotted
double
groove
ridge
inset
outset

Setting Sides:
Just like margin and padding, you can set individual sides of borders...

  1. border-right

    :

    3px

    dashed

    #000000

    ;
  2. border-left

    :

    1px

    dotted

    #ffffff

    ;
  3. border-top

    :

    3px

    solid

    #000000

    ;
  4. border-bottom

    :

    13px

    inset

    #ffffff

    ;
  5. </cs>

  6. <strong>

    Individual Settings:

    </strong>
  7. You can also set the properties individually...

  8. <css>
  9. border-style

    :

    solid

    ;
  10. border-width

    :

    5px

    ;

    //or medium

    etc.
  11. border-color

    :

    #000000

    ;

Linking CSS To a HTML Element:
To link your CSS to an HTML element (text, div, etc.) you will need to decide whether you want to use a class or id, you will also need a unique name. Once you have those, go to your element in HTML and add...

  1. class=

    'myClass'

... to the attributes of that element if you chose a class, or...

  1. id=

    'myID'

if you chose an id.

Make sure you replace 'myClass' and/or 'myID' with your unique name. Then, in the CSS you will want to encase your properties with...

  1. .myClass

    {
  2. //Properties go here
  3. }

if you chose a class, or...

  1. #myID

    {
  2. //Properties go here
  3. }

(You can remove the line beginning with // if you wish).

Here's an example...

  1. <html>
  2. <head>
  3. <style>
  4. .strong

    {
  5. background-color

    :

    #000

    ;
  6. color

    :

    #fff

    ;
  7. width

    :

    300px

    ;
  8. height

    :

    100px

    ;
  9. border

    :

    10px

    solid

    #000

    ;
  10. // Thick black

    border

    of 10

    pixels
  11. }

  12. .thin

    {
  13. background-color

    :

    #000

    ;
  14. color

    :

    #fff

    ;
  15. width

    :

    300px

    ;
  16. height

    :

    100px

    ;
  17. border

    :

    2px

    solid

    green

    ;
  18. // Thin green

    border

    of 2

    pixels
  19. }
  20. </style>
  21. </head>
  22. <body>
  23. <div class=

    'strong'

    >

    Strong/Thick Border</div>
  24. <div class=

    'thin'

    >

    Weak/Thin Border</div>
  25. </body>
  26. </html>

Book traversal links for Borders

  • ‹ Border Radius
  • Up
  • CSS @keyframes Rule ›

 

449,193

322,229

322,238

Top