How to add lines besides a vertical text using SASS ?
Last Updated :
09 Mar, 2022
In this article, we will see how to add lines besides some vertical text using SASS.
Approach: The HTML code is used to depict the basic structure of the body. Here, we define a division element with a class of wrapper to contain subsequent division elements. Another division element with a class of vertical-text is defined and it is rotated by 90 degrees using the transform property in SASS. For the rest of the text, two other division elements are defined with classes item-top and item-bottom respectively to represent some other text apart from the vertical text and these division elements are wrapped within another division element with a class of items.
Coming to SASS, to add a line beside the vertical text, we use the border-bottom property since the rotated element's bottom section is actually displayed as a vertical border. The margins and the paddings of the other division elements are adjusted accordingly since the transform operation takes the vertical text outside of the normal flow of the document.
Example 1: Here, the vertical text is a random date (in this case 27 Feb 2022) and there is a line beside it defined using the border-bottom property (as explained earlier).
style.scss
body {
text-align: center;
}
h1 {
color: green;
font-size: 2.5rem;
}
p {
font-size: 1.25rem;
}
.wrapper {
display: flex;
align-items: flex-start;
justify-content: flex-start;
max-width: 600px;
min-width: 600px;
margin: 6rem auto 0 auto;
}
.vertical-text {
display: flex;
transform: rotate(-90deg);
border-bottom: 2px solid black;
padding-left: 5.5rem;
p {
padding-bottom: 0.1rem;
}
}
.items {
display: flex;
flex-direction: column;
justify-content: flex-start;
align-items: flex-start;
margin-left: -3.8rem;
margin-top: -3rem;
p {
padding-left: 1rem;
}
}
.item-top {
p {
padding-bottom: 1rem;
}
}
.item-bottom {
border-top: 2px solid black;
p {
padding-top: 1rem;
}
}
Output: The generated CSS output will be as shown below.
style.css
body {
text-align: center;
}
h1 {
color: green;
font-size: 2.5rem;
}
p {
font-size: 1.25rem;
}
.wrapper {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-align: start;
-ms-flex-align: start;
align-items: flex-start;
-webkit-box-pack: start;
-ms-flex-pack: start;
justify-content: flex-start;
max-width: 600px;
min-width: 600px;
margin: 6rem auto 0 auto;
}
.vertical-text {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-transform: rotate(-90deg);
transform: rotate(-90deg);
border-bottom: 2px solid black;
padding-left: 5.5rem;
}
.vertical-text p {
padding-bottom: 0.1rem;
}
.items {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-ms-flex-direction: column;
flex-direction: column;
-webkit-box-pack: start;
-ms-flex-pack: start;
justify-content: flex-start;
-webkit-box-align: start;
-ms-flex-align: start;
align-items: flex-start;
margin-left: -3.8rem;
margin-top: -3rem;
}
.items p {
padding-left: 1rem;
}
.item-top p {
padding-bottom: 1rem;
}
.item-bottom {
border-top: 2px solid black;
}
.item-bottom p {
padding-top: 1rem;
}
index.html
<!DOCTYPE html>
<html>
<head>
<!-- jQuery -->
<script src=
"https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js">
</script>
<!-- Compiled CSS from SASS file -->
<style>
body {
text-align: center;
}
h1 {
color: green;
font-size: 2.5rem;
}
p {
font-size: 1.25rem;
}
.wrapper {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-align: start;
-ms-flex-align: start;
align-items: flex-start;
-webkit-box-pack: start;
-ms-flex-pack: start;
justify-content: flex-start;
max-width: 600px;
min-width: 600px;
margin: 6rem auto 0 auto;
}
.vertical-text {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-transform: rotate(-90deg);
transform: rotate(-90deg);
border-bottom: 2px solid black;
padding-left: 5.5rem;
}
.vertical-text p {
padding-bottom: 0.1rem;
}
.items {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-ms-flex-direction: column;
flex-direction: column;
-webkit-box-pack: start;
-ms-flex-pack: start;
justify-content: flex-start;
-webkit-box-align: start;
-ms-flex-align: start;
align-items: flex-start;
margin-left: -3.8rem;
margin-top: -3rem;
}
.items p {
padding-left: 1rem;
}
.item-top p {
padding-bottom: 1rem;
}
.item-bottom {
border-top: 2px solid black;
}
.item-bottom p {
padding-top: 1rem;
}
</style>
</head>
<body>
<h1>GeeksforGeeks</h1>
<div class="wrapper">
<div class="vertical-text">
<p>27 Feb 2022</p>
</div>
<div class="items">
<div class="item item-top">
<p>GeeksforGeeks</p>
</div>
<div class="item item-bottom">
<p>GeeksforGeeks is a computer
science portal for geeks.</p>
</div>
</div>
</div>
</body>
</html>
Output:
Example 2: This example is quite similar to the previous example but the only difference is that there is only one item division element apart from the vertically rotated text. Moreover, the vertical text is rotated the other way around by 90 degrees instead of negative 90 degrees.
style.scss
body {
text-align: center;
}
h1 {
color: green;
font-size: 2.5rem;
}
p {
font-size: 1.25rem;
}
.wrapper {
display: flex;
align-items: flex-start;
justify-content: flex-start;
max-width: 600px;
min-width: 600px;
margin: 6rem auto 0 auto;
}
.vertical-text {
display: flex;
transform: rotate(90deg);
border-top: 2px solid black;
padding-right: 3rem;
color: green;
font-weight: bold;
}
.items {
display: flex;
flex-direction: column;
justify-content: flex-start;
align-items: flex-start;
margin-left: -5.8rem;
margin-top: -3rem;
p {
padding-left: 5rem;
}
}
Output: The generated CSS output will be:
style.css
body {
text-align: center;
}
h1 {
color: green;
font-size: 2.5rem;
}
p {
font-size: 1.25rem;
}
.wrapper {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-align: start;
-ms-flex-align: start;
align-items: flex-start;
-webkit-box-pack: start;
-ms-flex-pack: start;
justify-content: flex-start;
max-width: 600px;
min-width: 600px;
margin: 6rem auto 0 auto;
}
.vertical-text {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-transform: rotate(90deg);
transform: rotate(90deg);
border-top: 2px solid black;
padding-right: 3rem;
color: green;
font-weight: bold;
}
.items {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-ms-flex-direction: column;
flex-direction: column;
-webkit-box-pack: start;
-ms-flex-pack: start;
justify-content: flex-start;
-webkit-box-align: start;
-ms-flex-align: start;
align-items: flex-start;
margin-left: -5.8rem;
margin-top: -3rem;
}
.items p {
padding-left: 5rem;
}
index.html
<!DOCTYPE html>
<html>
<head>
<!-- jQuery -->
<script src=
"https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js">
</script>
<!-- Compiled CSS from SASS file -->
<style>
body {
text-align: center;
}
h1 {
color: green;
font-size: 2.5rem;
}
p {
font-size: 1.25rem;
}
.wrapper {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-align: start;
-ms-flex-align: start;
align-items: flex-start;
-webkit-box-pack: start;
-ms-flex-pack: start;
justify-content: flex-start;
max-width: 600px;
min-width: 600px;
margin: 6rem auto 0 auto;
}
.vertical-text {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-transform: rotate(90deg);
transform: rotate(90deg);
border-top: 2px solid black;
padding-right: 3rem;
color: green;
font-weight: bold;
}
.items {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-ms-flex-direction: column;
flex-direction: column;
-webkit-box-pack: start;
-ms-flex-pack: start;
justify-content: flex-start;
-webkit-box-align: start;
-ms-flex-align: start;
align-items: flex-start;
margin-left: -5.8rem;
margin-top: -3rem;
}
.items p {
padding-left: 5rem;
}
</style>
</head>
<body>
<h1>GeeksforGeeks</h1>
<div class="wrapper">
<div class="vertical-text">
<p>GeeksforGeeks</p>
</div>
<div class="items">
<div class="item">
<p>
GeeksforGeeks is a Computer Science
portal for geeks. It contains
well written, well thought
and well explained computer
science and programming articles.
</p>
</div>
</div>
</div>
</body>
</html>
Output:
Similar Reads
How to make a vertical wavy text line using HTML and CSS ?
In this article, a wavy animated text is implemented using HTML and CSS. It is one of the simplest CSS effects. For a beginner, it is one of the best examples to learn the concept of CSS pseudo-elements. Approach: The basic idea of getting wavy texts is performed by using the combination of some CSS
2 min read
How to Vertically Align Text Next to an Image using CSS ?
Adding images into our websites is a common practice, and there are situations where text must be vertically aligned alongside an image. For example, a userâs name should appear immediately next to their profile picture, vertically aligned for optimal readability . In this article, we will see how t
2 min read
How to Set Vertical Space Between the List of Items using CSS?
Vertical space refers to the distance between elements arranged vertically on a webpage. In CSS, it can be set between list items using properties like margin or padding etc. These properties help create a visually appealing layout, enhancing readability and organization of the content.Below are the
4 min read
How to Add Shadow to Text using CSS?
The text-shadow property is used to add shadow to the text. The text-shadow property creates text shadows, specifying horizontal/vertical offsets, blur radius, and color for depth and emphasis.Note: We can customize text shadow by changing position, blur, and color for improved appearance and visual
1 min read
How to Add Text Outline with CSS?
Since CSS does not provide a direct text-outline property, the CSS text-shadow property is used to create an outline effect around text by adding multiple shadows with offsets.1. Using text-shadow PropertyThe text-shadow property is commonly used to add shadows to text, by applying multiple shadows
1 min read
How to use a sass variable in nth child class ?
SASS is one of the most popular CSS extension languages which provides superpower to the normal CSS. The nth-child() class is a pseudo-class, when some HTML element has more than two elements of the same kind then we can use the nth-child class pseudo-class to provide styling to those elements witho
2 min read
How to Vertically Align Text Within a Div in CSS?
Aligning text vertically within a div can enhance the visual appeal of your web design. There are various approaches to achieving vertical alignment using CSS.1. Using line-height PropertyThe line-height property is the easiest and most commonly used approach to align text within a div vertically. T
2 min read
How to create linear gradient text by using HTML ?
Creating linear gradient text on a webpage can add a dynamic and visually interesting touch to the design. While it is typically created using CSS, it is also possible to create linear gradient text using only HTML. Approach: Using the `<svg>` Element: The `<svg>` element in HTML provide
2 min read
How to Add Border Around Text using CSS?
The CSS border property is used to add a border around text by wrapping the text in an HTML element like <span> or <p>. Syntaxborder: "borderWidth borderStyle colorName;"Example 1: Adding a border around the text content using CSS.HTML<p> The following text has a border <span st
1 min read
How to create linear gradient text using HTML and CSS ?
The linear-gradient is used to create eye-catching text effects, particularly suitable for dark-themed websites or applications. This method involves filling text with linear-gradient color codes, making it look attractive and bold. Linear-gradient text effects are ideal for dark themes and provide
2 min read