1

Let's elaborate my problem. Think we have 3 template files 1.Master 2.Child(home) 3.navbar layout(included in home)

Mater->home->navbar

i have 2 external css files which have this css

p
{
color:red;
}

and

p
{
color:blue;
}

1st css file is linked in master.blade.php and 2nd css file is linked into navbar.blade.php

I want text color of navbar as blue and text color of home(other than navbar) as red.

Now the output is blue(overriding css which is declared in master).

I don't want to modify css(specificity), Is there anything in laravel like scopes for css.

3 Answers 3

3

Are you familiar with blade into laravel?

I think you should define a yield section in your master

@yield('css')

and then call it in your navbar or etc ... like this

 @section('css')
     p
     {
      color:red;
     }
    @endsection

and in other files

 @section('css')
 p
 {
  color:blue;
 }
@endsection
Sign up to request clarification or add additional context in comments.

1 Comment

i mentioned clearly that i don't want any css specificity.What you are doing is really simple and it is css specificity.And i don't require this.
1

Why don't you check the current route, then echo the color in style attribute in-line in your blade file:

@if(request()->is('/'))
    <!-- Homepage -->
    <p style="color:red">Hello</p>
@else
    <!-- All Other Pages -->
    <p style="color:blue">Hello</p>
@endif

or

<p style="color:{{ request()->is('/') ? 'red' : 'blue' }}">Hello</p>

1 Comment

sorry i can't do this as my url is same.As i am rendering into home layout only.
1

Why don't you just assign an ID to the different paragraph blocks and target them that way? Or even better, create a utility class for each colour.

.text-red {
   color: red;
}

And then...

<p class="text-red">Lorem ipsum[...]</p>

3 Comments

It really sounds like you're overcomplicating things - generally speaking, loading components as iframes is not a great idea and I'm not sure why you'd want to do so anyway.
actually i don't want specificity which u have mentioned like class,id, element.I want something like scopes in laravel which we have in AngularJS.But i don't think what i require is possible in laravel blade.
I just don't really see the point. It seems much easier to make use of utility classes or selectors to ensure that your elements are being styled correctly.

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.