CSS Properties: How to set the style of the right border?
Solution:
HTML Code:
<!DOCTYPE html><!-- Declares the document type as HTML -->
<html><!-- Root element of the HTML document -->
<head><!-- Contains metadata about the HTML document -->
<title>How to set the style of the left border</title><!-- Sets the title of the HTML document -->
<style type="text/css"> /* Begins a CSS style block */
h1 {border-style: solid; /* Defines a CSS rule for all h1 elements, setting their border style to solid */
border-width: 3px; /* Sets the width of the border of h1 elements to 3 pixels */
}
h1.none {border-right-style: none;} /* Defines a CSS rule for h1 elements with the class 'none', setting their right border style to none */
h1.dotted {border-right-style: dotted;} /* Defines a CSS rule for h1 elements with the class 'dotted', setting their right border style to dotted */
h1.dashed {border-right-style: dashed;} /* Defines a CSS rule for h1 elements with the class 'dashed', setting their right border style to dashed */
h1.solid {border-right-style: solid;} /* Defines a CSS rule for h1 elements with the class 'solid', setting their right border style to solid */
h1.double {border-right-style: double;} /* Defines a CSS rule for h1 elements with the class 'double', setting their right border style to double */
h1.groove {border-right-style: groove;} /* Defines a CSS rule for h1 elements with the class 'groove', setting their right border style to groove */
h1.ridge {border-right-style: ridge;} /* Defines a CSS rule for h1 elements with the class 'ridge', setting their right border style to ridge */
h1.inset {border-right-style: inset;} /* Defines a CSS rule for h1 elements with the class 'inset', setting their right border style to inset */
h1.outset {border-right-style: outset;} /* Defines a CSS rule for h1 elements with the class 'outset', setting their right border style to outset */
</style><!-- Ends the CSS style block -->
</head><!-- Ends the head section of the HTML document -->
<body><!-- Contains the content of the HTML document -->
<h1 class="none">No right border</h1><!-- Displays the text 'No right border' within an h1 element with the class 'none' -->
<h1 class="dotted">A dotted right border</h1><!-- Displays the text 'A dotted right border' within an h1 element with the class 'dotted' -->
<h1 class="dashed">A dashed right border</h1><!-- Displays the text 'A dashed right border' within an h1 element with the class 'dashed' -->
<h1 class="solid">A solid right border</h1><!-- Displays the text 'A solid right border' within an h1 element with the class 'solid' -->
<h1 class="double">A double right border</h1><!-- Displays the text 'A double right border' within an h1 element with the class 'double' -->
<h1 class="groove">A groove right border</h1><!-- Displays the text 'A groove right border' within an h1 element with the class 'groove' -->
<h1 class="ridge">A ridge right border</h1><!-- Displays the text 'A ridge right border' within an h1 element with the class 'ridge' -->
<h1 class="inset">An inset right border</h1><!-- Displays the text 'An inset right border' within an h1 element with the class 'inset' -->
<h1 class="outset">An outset right border</h1><!-- Displays the text 'An outset right border' within an h1 element with the class 'outset' -->
</body><!-- Ends the body section of the HTML document -->
</html><!-- Ends the HTML document -->
Explanation:
- The HTML document is structured with essential elements such as html, head, title, style, and body.
- CSS is used to style all h1 elements, setting their border style to solid and border width to 3 pixels.
- Additional CSS rules are defined for specific classes of h1 elements to set the style of their right border:
- h1.none sets the right border style to none.
- h1.dotted sets the right border style to dotted.
- h1.dashed sets the right border style to dashed.
- h1.solid sets the right border style to solid.
- h1.double sets the right border style to double.
- h1.groove sets the right border style to groove.
- h1.ridge sets the right border style to ridge.
- h1.inset sets the right border style to inset.
- h1.outset sets the right border style to outset.
- Each h1 element is given a class corresponding to the desired right border style, and the text inside each h1 element reflects the border style it demonstrates.
Live Demo:
See the Pen border-right-style-answer by w3resource (@w3resource) on CodePen.
See the solution in the browser
Supported browser
Yes | Yes | Yes | Yes | Yes |
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/html-css-exercise/css-properties/border-right-style-answer.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics