在一个元素中有多个类是一个好的(或最好的)练习? [英] Is having multiple classes in an element a good (or best) practice?

查看:97
本文介绍了在一个元素中有多个类是一个好的(或最好的)练习?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在单个元素中有多个类是一个好习惯吗?像这样:

 < div class =panel panel-primary panel-hide text-center> 

或者最好这样做:

 < div class =panel> 
< div class =panel-primary>
< div class =panel-hide>
< div class =text-center>
<! - 此处的内容 - >

或者最好将课程限制为每个div 2或3个?



或者它甚至有影响吗?

解决方案

您是否获得了一些这些类和代码段从Bootstrap网站?

有时类需要位于单独的嵌套div上,因为它们使用:before和:after或margin,为该div填充或定位。当您将所有类粘贴到一个div中时,这可能不起作用,并且类可能会相互覆盖。


Is having multiple classes in a single element a good practice? Like so:

<div class ="panel panel-primary panel-hide text-center">

Or is it better to do this:

<div class ="panel">
    <div class="panel-primary">
        <div class="panel-hide">
            <div class="text-center">
             <!-- content here -->

Or is it better to limit classes to 2 or 3 per div?

Or does it even matter?

解决方案

Did you got some of these classes and pieces of code from the Bootstrap website?

Sometimes classes need to be on separate nested divs, because they use :before and :after or margin, padding or positioning for that div. When you paste all classes inside one div, this may not work, and classes may overwrite eachother.

这篇关于在一个元素中有多个类是一个好的(或最好的)练习?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆