0

How do I nest codes in css?

Working Code (Example):

.component--search{
  background: #3D3F43;
  border-radius: 15px;
  padding: 40px 45px;
  box-shadow: 0 15px 25px -20px #202125;

  .form {
    position: relative;
    margin-bottom: 30px;

    .search-icon {
      position: absolute;
      top: 0;
      left: 0;
      width: 53px;
      height: 50px;
      display: flex;
      align-items: center;
      justify-content: center;
    }
 }
}

Code Not Working:

.front{
            width: 600px;
            height: 600px;
            border: 1px solid #000;
            .box1{
                background: red;
                border: 1px solid #000;
            }

        }

What's the difference? Why doesn't the part I wrote 2 work? my english is very little. Sorry if I didn't explain the question in detail.

1
  • This is not pure css, are you trying to use LESS or something similar? Commented Sep 19, 2022 at 6:09

1 Answer 1

2

The second code block works in sass or less but not in css.

So in css you must do this:

.front {
    width: 600px;
    height: 600px;
    border: 1px solid #000;
}

.front .box1 {
    background: red;
    border: 1px solid #000;
}
Sign up to request clarification or add additional context in comments.

1 Comment

Native CSS nesting is coming. w3.org/TR/css-nesting-1

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.