Rotating text using CSS
In this article, we will use CSS to rotate HTML text. Rotated text is commonly used in many languages, such as Chinese, Japanese, or Korean.
Moreover, when designing a web page, developers may need to rotate the text to a certain degree to make the user interface more attractive. Here, we have used two different methods to rotate the text.
Rotating text using the CSS transform property
In the following example, we have created a div element and assigned it the element text class name for identification. Inside the div element, we have created an element and added text inside it.
Sample code:
<div class="example-text">
<span>Rotated texts.</span>
</div>
Now, to rotate <div>
all the text of the <div> element, we access the div using the class name in CSS.
Next, we transform: rotate(-90deg)
applied the CSS properties to the div element to rotate the entire content. However, we used -webkit-transform: rotate(-90deg);
To rotate the text in Chrome browser, -moz-transform: rotate(-90deg);
in Firefox browser, -o-transform: rotate(-90deg);
the same as in Opera.
Additionally, we've applied some additional CSS to position the div element at the top. Here, this Position: absolute
means that the position of the div element will change relative to its parent element, which is the document body itself.
.example-text {
-webkit-transform: rotate(-80deg);
-moz-transform: rotate(-80deg);
-o-transform: rotate(-80deg);
position: absolute;
top: 40px;
}
In the output below, the user can see that the text is rotated 90 degrees counterclockwise.
If we pass positive degrees as a parameter to rotate()
the method, it rotates the content or text in clockwise direction as you can see from the following example.
.example-text {
-webkit-transform: rotate(80deg);
-moz-transform: rotate(80deg);
-o-transform: rotate(80deg);
position: absolute;
top: 40px;
}
<div class="example-text">
<span>Rotated texts.</span>
</div>
Rotating text using the CSS writing-mode property
The writing-mode CSS property helps us change the direction of the text. Using it, we can rotate the text by 90 or -90 degrees.
We can use verticle-rl as the value of the writing-mode property to rotate the text so that users can read it from right to left and from top to bottom.
In the following example, we create <p>
HTML markup that contains some writing-mode:vertical-rl
text that we rotate using CSS properties.
Sample code:
<p class="text">These text rotated by writing-mode: vertical-rl; CSS property. Read it from top to bottom and left to right.</p>
.text{
writing-mode: vertical-rl;
height: 200px;
}
If we use verticle-lr as the value of the writing-mode property, it rotates the text so that it can be read from left to right and top to bottom.
.text{
writing-mode: vertical-lr;
height: 200px;
}
<p class="text">These text rotated by writing-mode: vertical-rl; CSS property. Read it from top to bottom and left to right.</p>
The above output allows the user to read the text from left to right and top to bottom.
We have learned different methods to rotate text. The first method allows the programmer to rotate the text by any degree.
Using the second method, the programmer can rotate the text 90 degrees so that it can be read from left to right or right to left. Therefore, the first method is recommended.
For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.
Related Articles
覆盖 Bootstrap CSS
Publish Date:2023/04/28 Views:136 Category:CSS
-
本文介绍的是著名的 CSS UI 框架 Bootstrap。 我们将讨论使用自定义样式覆盖 Bootstrap CSS 的过程。
使用 CSS 制作带圆角的 HTML 表格
Publish Date:2023/04/28 Views:247 Category:CSS
-
这个简短的文章是关于在 HTML 页面上制作圆角表格的 CSS 样式。使用 CSS 制作带圆角的 HTML 表格 使图像、表格或 div 段的角变圆的属性是 border-radius。
CSS 设置轮廓 outline 的半径
Publish Date:2023/04/28 Views:141 Category:CSS
-
在本文中,用户将学习如何为 outline 属性设置圆角,与 border-radius 属性相同。 在这里,我们已经解释了将圆角应用于轮廓属性的不同方法。
使用 CSS 居中视频
Publish Date:2023/04/28 Views:272 Category:CSS
-
在本文中,用户将学习仅使用 CSS 将 <video> 元素居中。 我们已经在下面解释了使用 CSS 使视频居中的多种方法。
使用 CSS 居中内联块
Publish Date:2023/04/28 Views:123 Category:CSS
-
在本文中,我们将创建多个 HTML 元素并将其显示设置为 inline-block。 之后,我们将学习使用 display: inline-block 将所有元素居中。
使用 CSS 添加透明边框
Publish Date:2023/04/28 Views:537 Category:CSS
-
在本文中,我们将讨论在 HTML 中的图像、按钮或任何其他对象周围创建透明边框。 透明边框是图像或对象周围的边框,可改善用户体验。
使用 CSS 向上移动文本
Publish Date:2023/04/28 Views:715 Category:CSS
-
有时,在开发网页时,我们将文本放在底部或页脚中,因此我们可能需要在文本下方留一个空格并将文本上移。 我们将学习如何使用 css 从网页底部向上移动文本。
使用 CSS 和 JavaScript 制作文本闪烁
Publish Date:2023/04/28 Views:244 Category:CSS
-
本文提供了使用 CSS、JavaScript 和 jQuery 使文本闪烁的详细说明。
CSS 防止文本选择
Publish Date:2023/04/28 Views:82 Category:CSS
-
在本文中,我们讨论了防止文本选择和使用具有 none 值的 user-select 属性。 此外,您还将了解如何为不同的 Web 浏览器使用该属性。