combined multiple classes into one css rule

前端 未结 3 2013
后悔当初
后悔当初 2020-12-19 07:08

I\'m trying to do some buckets here and generally I would do 1 class element at a time. That seems silly since classes can share attributes.

HTML

&l         


        
相关标签:
3条回答
  • 2020-12-19 07:25

    It may even make sense to do something like

    <div id = "outerBuckets">
            <div class = "bucketStyleFirst">
                <div class ="bucketIcon">
                    <p></p>
                </div>
            </div>
            <div class = "bucketStyleFirst">
                <div class ="bucketIcon">
                    <p></p>
                </div>
            </div>
            <div class = "bucketStyleFirst">
                <div class ="bucketIcon">
                    <p></p>
                </div>
            </div>
            <div class = "bucketStyleSecond">
                <div class ="bucketIcon">
                    <p></p>
                </div>
            </div>
            <div class = "bucketStyleSecond">
                <div class ="bucketIcon">
                    <p></p>
                </div>
            </div>
            <div class = "bucketStyleSecond">
                <div class ="bucketIcon">
                    <p></p>
                </div>
            </div> 
    </div>
    

    That way you'll only need to say

    .bucketStyleFirst {
    
    }
    
    .bucketStyleSecond {
    
    }
    

    This is of course if you'll only be having the two different options.

    0 讨论(0)
  • 2020-12-19 07:35

    Use commas to separate the selectors in a list

    .bucket1, .bucket2, .bucket3 {
    }
    
    .bucket4, .bucket5, .bucket6 {
    }
    
    0 讨论(0)
  • 2020-12-19 07:37

    I will try again... (forget the part about posting code...):

    "E.g.: <div class = "someclass">... (notice the whitespace before and after =)

    ...should be: <div class="someclass"> to avoid confusing the browsers.

    0 讨论(0)
提交回复
热议问题