Menu

Log in

Sign up

From beginner to master of web design, coding, infrastructure operation, business development and marketing

  • COURSES
  • HTML & CSS Introduction
  • HTML & CSS Coding with AI
  • Linux Introduction
  • Docker Basics
  • Git & GitHub Introduction
  • JavaScript Coding with AI
  • Django Introduction
  • AWS Basics
  • Figma Introduction
  • SEO Tutorial for Beginners
  • SEO with AI
  • OTHERS
  • About
  • Terms of Service
  • Privacy Policy

© 2024 D-Libro. All Rights Reserved

HTML & CSS IntroductionChapter 13. CSS: Styling Borders and Drawing Lines

border-style

border-style

Choosing Border Styles in CSS

The border-style property is used for setting the style of borderlines. As the default value is none, you need to add this property to CSS in order to show borderlines. If you don't set the border-style property even though you specify the border-color or border-width, borderlines won't be displayed.

Property Values

There are several styles you can set. Here are the major ones:

  • none (default)
  • solid
  • double
  • dashed
  • dotted

Multiple Keywords

When you set only one keyword, the style is applied to all sides of the borderline. By setting multiple keywords, you can set different borderline styles for each side of the element.

Two keywords

  • The first keyword is applied to the top and bottom borders.
  • The second keyword is applied to the right and left borders.
border-style with two keywords (top&bottom  right&left)

Three keywords

  • The first keyword is applied to the top border.
  • The second keyword is applied to the right and left borders.
  • The third keyword is applied to the bottom border.
border-style with three keywords (top  right&left bottom)

Four keywords

Using four keywords, you can specify the styles for each side of the borders. The property values are set based on clockwise order starting from the top.

  • The first keyword is applied to the top border.
  • The second keyword is applied to the right border
  • The third keyword is applied to the bottom border.
  • The fourth keyword is applied to the left border.
border-style with four keywords (top  right bottom left)

Practice

Objective:
Practice to set different border styles with different numbers of keywords

1. Create a new HTML file for this chapter

  • Create a copy of the chapter12.html file and change the name to chapter13.html.
  • Change the <title> section to 13. CSS: Styling Borders and Drawing Lines.
  • Also, delete the existing content of the <body> element that was created in the previous chapter.
  • Add the <h1> tag to show the chapter title of this page at the top of the page.
  • The code should look like the one below.
chapter13.html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <!--Google Font-->
  <link rel="preconnect" href="https://fonts.googleapis.com">
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
  <link href="https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap" rel="stylesheet">
  <!--Custom CSS-->
  <link rel="stylesheet" href="css/practice.css">
  <title>13. CSS: Styling Borders and Drawing Lines</title>
</head>
<body>
  <h1>Chapter 13. CSS: Styling Borders and Drawing Lines</h1>
</body>
</html>

2. Update the body section

Add the code below in the body section of the HTML file. We are adding the bg-only class to set the size and shape of each box without any borderline as a base object style. The code for the styling will be explained in the next step.

We also add borderlines to the base object using the style attribute of each element so that we can customize the border style for each element. This part of the CSS code is written in the HTML file below.

In the code below, we are wrapping elements using the <div> element with the display and flex-wrap properties to structure the results. We'll explain these properties in detail later. For now, just copy and paste the code.

chapter13.html
<h2>Border Style</h2>
<h3> 1 Value </h3>
<div style="display: flex; flex-wrap: wrap;">
  <div class="bg-only">border-style: Original</div>
  <div class="bg-only" style="border-style: none;">border-style: None</div>
  <div class="bg-only" style="border-style: solid;">border-style: Solid</div>
  <div class="bg-only" style="border-style: dashed;">border-style: Dashed</div>
  <div class="bg-only" style="border-style: dotted;">border-style: Dotted</div>
  <div class="bg-only" style="border-style: double;">border-style: double</div>
</div>

<h3> 2 Values </h3>
<div style="display: flex;">
  <div class="bg-only" style="border-style: solid none;">border-style: Solid None</div>
  <div class="bg-only" style="border-style: solid dashed;">border-style: Solid Dashed</div>
</div>

<h3> 3 Values </h3>
<div class="bg-only" style="border-style: solid none dotted;">border-style: Solid None Dotted</div>

<h3> 4 Values </h3>
<div class="bg-only" style="border-style: solid dotted double none;">border-style: Solid Dotted Double None</div>
<hr>

3. Update the CSS file

Open the practice.css file and add new code for adding styles to the bg-only class. As this is the start of the chapter, add a comment upfront for code readability.

practice.css
/* Chapter 13. CSS: Styling Borders and Drawing Lines */
.bg-only{
  width: 300px;
  height: 100px;
  margin: 10px;
  padding: 10px;
  background-color: #B3EBEF;
  box-sizing: border-box;
}

4. Check the result with a browser

  • Open chapter13.html with a browser.
  • You can see how different border styles are set with multiple keywords.

You can also check the sample result here (Demo Site).

link


You can also learn this topic offline. Click AmazonKindle.

More Topics to Explore

Chapter 6. Dynamic Website Design Using CSS

Chapter 6. Dynamic Website Design Using CSS

Chapter 5. Building Responsive Website

Chapter 5. Building Responsive Website

Using margin: auto for Centering in CSS

margin: auto

Chapter 6. Dynamic Website Design Using CSS

Chapter 6. Dynamic Website Design Using CSS

Chapter 5. Building Responsive Website

Chapter 5. Building Responsive Website

Using margin: auto for Centering in CSS

margin: auto

Tags:

Borderline

Border Style

HTML & CSS Introduction
Course Content

Chapter 1. Overview of Website Development

How Websites Work?

Designing, Building and Publishing Websites

Designing Websites

Building Websites – Frontend and Backend Coding

Web App vs. Website

Frontend Coding

Web Framework and CMS

Publishing Websites (Hosting Services)

Chapter 2. Preparing for Website Coding

Two Key Tools to Start Coding Websites

How Browsers Display Web Pages

File Name Rules

Website Directory Structure

Absolute Path vs. Relative Path

Chapter 3. HTML Basics

What Is HTML?

HTML Element

Attribute

HTML Document Structure

Layout Semantics

Heading and Paragraph Tag

Text-Level Semantics

Space, Line-break and Tag in Content

Comments in HTML Document

Chapter 4. HTML: Add Links and Images

Overview of Adding Links and Images

Embed Images – <img>

Image File Format

Add Hyperlinks – <a>

Add Hyperlinks to Images

Add Hyperlinks to Specific Location on Web Page

Link Tag – <link>

Script Tag – <script>

Chapter 5. HTML: Create Lists and Tables

Create Lists

Create Tables

Combine Table Cells

Chapter 6. HTML: Create Forms

Create Forms

Create Text Input Forms and Submit Button

Radio Button and Checkbox

Select Box

Labels

Auto Complete and Disabled

Chapter 7. Bridging HTML and CSS

Block Element vs. Inline Element

Nesting Elements – Parent Elements and Child Elements

Div vs. Span

Global Attribute – Class, ID and Style

Accordion – <Details> and <Summary>

Chapter 8. CSS Basics

What Is CSS?

CSS Syntax

Where To Type CSS?

CSS Basic Selectors

Descendant Selector

Inheritance

Specificity

Reset CSS

Browser Developer Tools for CSS

Comments in CSS Document

Chapter 9. Web Design Basics

Design Element Representation in HTML and CSS

Key Design Points by CSS

Length

Color Code – HEX and RGB

Color Theme

Chapter 10. CSS: Sizing and Spacing

CSS Box Model

width and height

padding

margin

Margin and Padding for Specific Side

margin: auto

box-sizing

Chapter 11. CSS: Styling Text and Images

Text Styling Properties

font-size

color

font-family

Web Font and Google Font

font-weight and font-style

text-decoration

line-height and letter-spacing

text-align

vertical-align

Styling Images

float: left and right

Chapter 12. CSS: Styling Backgrounds

background-color

background-image

background-size

background-repeat

background-position

background-attachment

background (Multiple Properties)

Chapter 13. CSS: Styling Borders and Drawing Lines

border-style

border-color

border-width

border-radius

Border (Multiple Properties)

Borders on Specific Side

Border Radius on Specific Side

Chapter 14. CSS: Layout – Key Concepts and Display Property

Layout Before and After

Layout Key Design Points

Display Property

inline, block and inline-block

display: none

Chapter 15. CSS: Layout – Flex Box

Flex Box – display: flex

flex-direction

Main Axis and Cross Axis

flex-wrap

justify-content

align-items

align-content

align-self

flex-grow

flex-shrink

flex-basis

margin: auto with Flex Box

Inline Flex Box

Nested Flex Box

Chapter 16. CSS: Styling Lists

List Styling Properties

list-style-type

list-style-image

list-style-position

Chapter 17. Creating and Styling Components

Components and Layout

Buttons

Cards

Top Bar

Footer and Bottom Bar

Chapter 18. Completing Website Development

Website Structure Design

Live Server

Home (Landing) Page Development

Main (List) Page Development

Content (Detail) Page Development

Chapter 19. Publishing Websites

Key Steps to Publish Websites

Domain and DNS Server

Favicon

GitHub Pages

Chapter 20. Supplemental Topics

Horizontal Rule – <hr>

Line Break – <br>

Reserved Characters and HTML Entities

Non-breaking Space – &nbsp;

Chapter 1. Overview of Website Development

How Websites Work?

Designing, Building and Publishing Websites

Designing Websites

Building Websites – Frontend and Backend Coding

Web App vs. Website

Frontend Coding

Web Framework and CMS

Publishing Websites (Hosting Services)

Chapter 2. Preparing for Website Coding

Two Key Tools to Start Coding Websites

How Browsers Display Web Pages

File Name Rules

Website Directory Structure

Absolute Path vs. Relative Path

Chapter 3. HTML Basics

What Is HTML?

HTML Element

Attribute

HTML Document Structure

Layout Semantics

Heading and Paragraph Tag

Text-Level Semantics

Space, Line-break and Tag in Content

Comments in HTML Document

Chapter 4. HTML: Add Links and Images

Overview of Adding Links and Images

Embed Images – <img>

Image File Format

Add Hyperlinks – <a>

Add Hyperlinks to Images

Add Hyperlinks to Specific Location on Web Page

Link Tag – <link>

Script Tag – <script>

Chapter 5. HTML: Create Lists and Tables

Create Lists

Create Tables

Combine Table Cells

Chapter 6. HTML: Create Forms

Create Forms

Create Text Input Forms and Submit Button

Radio Button and Checkbox

Select Box

Labels

Auto Complete and Disabled

Chapter 7. Bridging HTML and CSS

Block Element vs. Inline Element

Nesting Elements – Parent Elements and Child Elements

Div vs. Span

Global Attribute – Class, ID and Style

Accordion – <Details> and <Summary>

Chapter 8. CSS Basics

What Is CSS?

CSS Syntax

Where To Type CSS?

CSS Basic Selectors

Descendant Selector

Inheritance

Specificity

Reset CSS

Browser Developer Tools for CSS

Comments in CSS Document

Chapter 9. Web Design Basics

Design Element Representation in HTML and CSS

Key Design Points by CSS

Length

Color Code – HEX and RGB

Color Theme

Chapter 10. CSS: Sizing and Spacing

CSS Box Model

width and height

padding

margin

Margin and Padding for Specific Side

margin: auto

box-sizing

Chapter 11. CSS: Styling Text and Images

Text Styling Properties

font-size

color

font-family

Web Font and Google Font

font-weight and font-style

text-decoration

line-height and letter-spacing

text-align

vertical-align

Styling Images

float: left and right

Chapter 12. CSS: Styling Backgrounds

background-color

background-image

background-size

background-repeat

background-position

background-attachment

background (Multiple Properties)

Chapter 13. CSS: Styling Borders and Drawing Lines

border-style

border-color

border-width

border-radius

Border (Multiple Properties)

Borders on Specific Side

Border Radius on Specific Side

Chapter 14. CSS: Layout – Key Concepts and Display Property

Layout Before and After

Layout Key Design Points

Display Property

inline, block and inline-block

display: none

Chapter 15. CSS: Layout – Flex Box

Flex Box – display: flex

flex-direction

Main Axis and Cross Axis

flex-wrap

justify-content

align-items

align-content

align-self

flex-grow

flex-shrink

flex-basis

margin: auto with Flex Box

Inline Flex Box

Nested Flex Box

Chapter 16. CSS: Styling Lists

List Styling Properties

list-style-type

list-style-image

list-style-position

Chapter 17. Creating and Styling Components

Components and Layout

Buttons

Cards

Top Bar

Footer and Bottom Bar

Chapter 18. Completing Website Development

Website Structure Design

Live Server

Home (Landing) Page Development

Main (List) Page Development

Content (Detail) Page Development

Chapter 19. Publishing Websites

Key Steps to Publish Websites

Domain and DNS Server

Favicon

GitHub Pages

Chapter 20. Supplemental Topics

Horizontal Rule – <hr>

Line Break – <br>

Reserved Characters and HTML Entities

Non-breaking Space – &nbsp;