How to apply styles to multiple classes at once?

ID:13078 / 打印

how to apply styles to multiple classes at once?

For Applying Styles to Muitliple classes at once we are going to use dot(.) selector and comma(,). In this article, we will use the dot (.) selector and select all the elements with their class names using the selector and separated by a comma (,).

“class” 是一个HTML属性,它接受由空格分隔的类列表。这些类可以在CSS中用于为特定元素设置样式,或者在javascript中用于操作这些HTML元素。

Example 1

In this example, we will apply the font color “red” to the HTML elements that have classes “header” and “para”. We will achieve this using the dot (.) selector and concatenating them with a comma (,).

<!DOCTYPE html> <html lang="en"> <head>    <title>How to apply styles to multiple classes at once?</title>    <style>       .header, .para {          color: red;       }    </style> </head> <body>    <h3 class="header">How to apply styles to multiple classes at once?</h3>    <p class="para">Lorem ipsum dolor sit amet consectetur adipisicing elit.</p> </body> </html> 

Example 2

在这个例子中,我们将把字体颜色设置为“green”并将字体样式设置为“italic”应用到具有类名“header”和“para”的HTML元素上。我们将使用点(.)选择器,并将它们与逗号(,)连接起来来实现这一目标。

<!DOCTYPE html> <html lang="en"> <head>    <title>How to apply styles to multiple classes at once??</title>    <style>       .header, .para {          color: green;          font-style: italic;       }    </style> </head> <body>    <h3class="header">How to apply styles to multiple classes at once?</h3>    <p class="para">Lorem ipsum dolor sit amet consectetur adipisicing elit.</p> </body> </html> 

结论

In this article, we learned how to apply multiple CSS classes at once. We did this by first, selecting multiple classes at once, using the dot (.) selector provided by the CSS, and then assigning them the required styles in the stylesheet.

上一篇: What is Graceful Degradation in CSS?
下一篇: css超出显示...

作者:admin @ 24资源网   2024-10-18

本站所有软件、源码、文章均有网友提供,如有侵权联系308410122@qq.com

与本文相关文章

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。