Looking to style a <p> element with CSS?

In the div class index, there are two additional divs without any class or id names, along with two <p> tags. My goal is to style these two <p> tags.

<div class="doubt">
  <div>
    <p>Hello world</p>
    <div>
      <p>Hello</p>
    </div>
  </div>
</div>

I am looking for a way to apply different styles to the two p tags. How can this be achieved?

Your assistance with this matter would be greatly appreciated. Thank you in advance!

Answer №1

Just implement this simple CSS code:

If you need any further explanations, feel free to ask.

.doubt > div > div > p {
    color: green;
}
.doubt > div > p {
    color: red;
}
<div class="doubt">
    <div>
            <p>Hello world</p>  
        <div>
            <p>Hello</p>
        </div>
    </div>
</div>

Answer №2

You have the option to utilize inline styling.

<div class="doubt">
      <div>
        <p style="color: yellow">Greetings Earth</p>
        <div>
          <p style="color: red">Hi</p>
        </div>
      </div>
</div>

In addition, you can implement a hierarchical structure in the styles to add formatting to these paragraphs.

<head>
    <style>
        .doubt div p{
            color: red;
        }
        .doubt div div p{
            color: green;
        }
    </style>
</head>
<body>
    <div class="doubt">
      <div>
        <p>Greetings Earth</p>
        <div>
          <p>Hi</p>
        </div>
      </div>
    </div>
</body>

I trust that this information proves helpful to you.

Answer №3

You can give different styles to two p tags by following this example:

.doubt div:nth-child(1) p{ color:blue;}
.doubt div:nth-child(2) p{ color:purple;}
<div class="doubt">
    <div>
            <p>Greetings</p>  
        <div>
            <p>Bonjour</p>
        </div>
    </div>
</div>

Answer №4

You can add your own touch with inline styling.

<div class="question">
    <div>
        <p style="color: blue">Greetings from the world</p>  
        <div>
            <p style="color: purple">Hi there!</p>
        </div>
    </div>
</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Css shaky letters transformation

[SOLUTION] To resolve this issue, you can utilize the will-change CSS property that enforces GPU rendering: will-change: transform; [ORIGINAL QUESTION] After extensive searching on the internet, I have yet to find a solution to a seemingly simple prob ...

pop-up window that shows chosen choices using javascript or ajax

I have a specific HTML code that allows users to select multiple options. I would like these selected options to be displayed in a popup or a div in real-time as the user makes their selections. I have attempted using a selectbox with checkboxes, but extra ...

Challenges arise with CSS alignment when adding d3.js charts to a webpage

I'm puzzled by the empty space that appears between the left column (highlighted in the image) and the header. This peculiar gap only seems to occur when the middle column is filled with a chart. I've scrutinized the code using Chrome Developer t ...

Exploring the versatility of Angular 4 by implementing a switch feature with

My goal is to have the menu change based on the click of the "Cadastros" action, but it seems like the issue lies with the "workspaceSelected" property not being visible to all components. I believe the best approach in this situation would be to have the ...

Show information - press the button on the current PHP page

After successfully reading files via PHP from a directory and dynamically creating a drop-down menu to view the file content, I have a query. Is there a way to display the text files' content on the same page without calling another PHP page? I know t ...

Adding a Material Icon to an input type of 'submit' can be done by including the necessary HTML code and

Can Material Icon classes be used with button inputs? For example, using the <button> tag allows us to do this: <button class="btn btn-secondary btn-block btn-flat" id="submit"><i class="zmdi zmdi-long-arrow-right"></i> Login< ...

What could be the reason behind ejs not allowing if else statements when the variable is undefined?

I am attempting to replicate a rather simple example from this question here <div <% if (page_name === 'overview') { %> class="menu__menu-overviewPage menu" <% } %> class="menu"> However, when I try it on a ...

"Interacting with the ng-keypress event causes the page to smoothly scroll

As a newcomer to angularjs, I am trying to figure out why my component (which simulates a "checkbox" using fontawesome icons) causes the page to scroll down when the user presses the space key. Here is a snippet of my component : ugoFmk.component(' ...

Leverage variables in JavaScript to establish a unique style

function AdjustScale(){ scaleX = window.innerWidth / 1024; scaleY = window.innerHeight / 768; element = document.getElementById("IFM"); element.style.transform = "scale(" + scaleX + ", " + scaleY + ")"; } I'm facing an issue with thi ...

Swapping stylesheets using a hyperlink - a simple guide

Currently, I am creating a website that utilizes PHP, XHTML strict, and jQuery. The main goal is to ensure the site is adaptable for mobile and desktop devices by implementing the principles of Responsive Web Design. This involves serving different stylesh ...

Effective ways to transmit a variable array from an HTML document to a PHP server

Is there a better method for transferring a variable array from HTML to PHP? I attempted to use the serialize function, but it doesn't seem to be functioning correctly. Any suggestions would be greatly appreciated. //HTML var arrayTextAreasNames = [ ...

Toggle visibility of table row upon user click (HTML/JQuery)

Having an issue with showing or hiding table rows using jQuery. I would like it so that when a user clicks on a table row with id="jobtitle", the corresponding tr with class="texter" will either show up or hide if it is already displayed. This is my curre ...

Use jQuery to gather all the values from an HTML select element

I am using PHP to generate a HTML select option based on folders in a directory. Now, I am looking for a way to retrieve the value of the selected option in my jQuery script. I am familiar with $('#select :selected').text() and $(#select).val(), ...

The customer's status cannot be determined

I've encountered an issue with my TypeScript code that includes a simple if-else logic. endDate: String = ''; customerStatus: String; this.endDate = this.sampleData.customerStartDate; if (this.endDate == null) { this.customerStatus = ' ...

What is the best way to compress HTML code within a webpage's source?

I have noticed that my template is filled with empty spaces after previewing the page due to using many tags. Is there a way to make my code more compact, similar to the example below: https://i.sstatic.net/ZBlbg.jpg [...] startsWith",function(a){return ...

"Creating Search Engine Optimization friendly URLs: A Step-by-Step

Looking for ways to optimize my dynamic URL! http://www.example.com/hamlyn/page.php?id=14 Any suggestions on shortening or making it more search-engine-friendly? ...

Tips for organizing a div into a dock panel

I am seeking guidance on how to align and resize the following divs based on my specific requirements outlined below. Area A Area A should remain at the top with a set height that will not change. Area B The height of Area B should vary between 0 and a m ...

Internet Explorer's support for the `<summary>` tag in HTML

Is there a method to enable the summary tag in Internet Explorer 11, such as using an external library? <details> <summary>Here is the summary.</summary> <p>Lorem ipsum dolor sit amet</p> </details> App ...

Is there a way to position the tooltip above the sorter icon in Ant Design (antd) component?

I'm currently working on creating a table with sorter columns using the antd framework. Can anyone guide me on how to position the tooltip above the sorter icon? Below is a snippet of my UI. https://i.sstatic.net/fGoqA.png Specifically, I included t ...

Django causing issues with displaying Bootstrap modal on website

I am having issues with implementing a Bootstrap modal in my Django template. I followed an example from the Bootstrap website to create a button that triggers a modal, but when I click the button, nothing happens. There are no errors displayed in the co ...