0

So, I have been using my own CSS class named myclass and Bootstrap built-in class container. My question is while declaring a with both classes.

Should I use

<div class="myclass container">some code</div>

this format, or:

<div class="myclass">
    <div class="container">
      some code
    </div>
</div>

Does both work in the same way? Or these two are different?

1
  • They are different, but depending on the CSS may work the same way. Read about CSS selectors Commented Mar 7, 2018 at 14:53

2 Answers 2

1

They are different, first one you have 2 classes for the same element, and you can select the element by using the following rules:

  • .container {}
  • .myclass{}

  • .myclass.container{} or .container.myclass{}

The second example you have a parent and a child elemtns

which you can use the following rule:

.myclass .container {}
Sign up to request clarification or add additional context in comments.

1 Comment

thank you !! thats why I was confused,although the result was pretty much the same.I just had to clear my confusion
0

Both are totally different.

<!-- Here you're declaring ONE div element with two values on class atribute -->
<div class="myclass container">some code</div> this format
<!-- Here you're declaring TWO elements with a different class each one -->
<div class="myclass">
       <div class="container">

    </div>
</div>

Why this is so different? HTML tags/eelements have default properties with default values, plus the properties and values that you put in addition.

For example: if you set globally:

div{padding:5px;}

On the first example, the content inside the div will be padded 5px.

On the second example, the content inside container will be padded 10px.

That can happen with default properties rendered by the browser or globally applied by frameworks as bootstrap.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.