Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selected a div above using attribute

Tags:

css

I want to edit the "p" content which is inside the content div on my shopping cart page.

As the content div appears on every page, I don't wish to just go for "content + p"

Is there an attribute I can use that will "select all p tags in the div above cart-module"

 <div class="content">
   <p>The content I want to edit<./p>

<div class="cart-module">
<div class="cart-total">

Also, is there a problem with attribute rules slowing down the pages?

like image 632
Molder Avatar asked Nov 26 '25 05:11

Molder


1 Answers

If the structure is always as you describe in you question then you can go with the first child selector:

.content > p:first-child { 
    background-color: red;
}

wich will get the p inside the content only if it is in the first place inside of it.

Regarding your second question, it will always depend on how and how many attributes you use on each page. The attribute selectors are slower than the ids or classes, because the latter are indexed by the browsers, just for this reason. Anyway, if you don't use them massively surely you won't notice the difference.

Of course, if you have access to modify the html structure the easiest would be to add a class to the p tags you want to select...

like image 185
Vi100 Avatar answered Dec 08 '25 15:12

Vi100



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!