Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8572335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:59:10+00:00 2026-06-11T18:59:10+00:00

Below is a simple piece of HTML/CSS code, where I put in two URLs:

  • 0

Below is a simple piece of HTML/CSS code, where I put in two URLs:

  • The 1st URL (Google) is a child of the div.
  • The 2nd URL (Bing) is only a descendant of the div.

Child-selector use implies that only the Google URL should be colored Red.

But in implementation, somehow both Google and Bing URLs are Red. (Also, interestingly, when I remove the <h1>Text</h1> element, then only the Google URL is colored Red.)

What is the reason?

Here is the HTML extract:

<div class="mydiv">
    <a href="http://www.google.com">Google</a>
    <p>
        <h1>Text</h1>
        <a href="http://www.bing.com">Bing</a>
    </p>
</div>

And the CSS extract:

.mydiv > a {
    color:red;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T18:59:11+00:00Added an answer on June 11, 2026 at 6:59 pm

    This is kind of tricky.

    First of all <h1> is a block-element. Next to note is, that <p> can only contain inline elements. As soon as a block element is encountered as a child of a <p> element, the opened <p> is implicitly closed.

    So (internally) your HTML snippet is transformed to this (for all I know the closing </p> is ignored then):

    <div class="mydiv">
            <a href="http://www.google.com">Google</a>
            <p></p>
            <h1>Text</h1>
            <a href="http://www.bing.com">Bing</a>
    </div>
    

    Now, as you can see, both <a> tags are direct descendants of your <div> and so your CSS rule applies to both of them.

    The behavior, when removing the <h1> tag follows accordingly: Your <p> is not implicitly closed. As such the second <a> remains a child of <p> and the CSS does not apply to it.

    I think, what you want to have is best achieved using another <div> instead of the <p> tag (maybe even <article>, <section> or similar).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two OptionMenu widgets in the simple pieces of code shown below: variable
The simple code block below can be served up in a static HTML page
I have a piece of ada code shown below which is a simple switch
Below have a simple piece of code: using System; using System.Collections.Generic; using System.Linq; using
I have a very simple piece of code below which I think gives the
Simple stuff but somehow not able to crack it, below piece of code gives
I have a simple code below: import java.util.ArrayList; public class BoidList extends ArrayList {
The code pasted below is a simple JSF program, with an idea of having
I am testing this simple code below and it works... $(document).ready( function() { $('.show-modal').click(
I am having trouble with some javascript. The code snippet below creates a simple

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.