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元素。
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>
在这个例子中,我们将把字体颜色设置为“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.
以上就是How to apply styles to multiple classes at once?的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号