Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i apply css to the inner level of an element?

Tags:

html

css

Suppose there are number of div tags and if there are an element at the innermost level then how do I access that one or declare css for that element?

<div class="...">
     <div class="...">
          <div class="...">
               .....
                   <div class="...">
                           <p>element</p>
                   </div>
               .....
          </div>
     </div>
</div> 

How do I access the element <p> or set the background image for it in a separate css file?

like image 808
Rahul Verma Avatar asked Dec 22 '25 23:12

Rahul Verma


1 Answers

It depends on how specific you want the style to be, say if you have:

<div class="page">
  <div class="content">
    <div class="some-container">
      <p class="description">Lorem Ipsum</p>
    </div>
  </div>
</div>

You can style the <p> as generic/specific as you want:

p
{
   color:red; /* Affects all p */
}

p.description
{
   color:blue; /* Affects all p with class description */
}

.some-container p
{
   color:black; /* Affects all p that is a descendant of an element with some-container class */

}
.page .content .some-container p.description
{
    color:white; /* You get the idea */
}
like image 67
pixelfreak Avatar answered Dec 24 '25 16:12

pixelfreak



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!