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 8571179
In Process

The Archive Base Latest Questions

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

I have several <p> elements in my HTML body. I only want to show

  • 0

I have several <p> elements in my HTML body. I only want to show the first two paragraphs, and set display:none to all paragraphs after. Why does the following code not work?

<html>

<head>
    <style type="text/css">
        p:gt(2) { display:none; }
    </style>
</head>
<body>
    <p>1</p>
    <p>2</p>
    <p>3</p>
    <p>4</p>
</body> 

</html> 

My code still shows all 4 paragraph elements in Chrome web browser.

How do I correct my code to achieve the objective I originally stated?

  • 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:43:35+00:00Added an answer on June 11, 2026 at 6:43 pm

    If they’re siblings the easiest approach with some backwards compatibility would be:

    p + p ~ p {
        display: none;
    }
    

    JS Fiddle demo.

    You could also use:

    p:nth-of-type(2) ~ p {
        display: none;
    }
    

    JS Fiddle demo.

    References:

    • CSS Selectors.
    • CSS :nth-of-type() pseudo-class.
    • Adjacent sibling (+) combinators.
    • General sibling (~) combinators.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have several html input elements which all look something like this: <input id=1
I have several elements in HTML that I want to keep grouped when they
I have several HTML elements (buttons) that fire the same JQuery AJAX request. When
I have created several UI elements in the viewDidLoad method. I want to change
I've got several elements on a HTML page which have the same class -
I have several <div> elements inside another <div> . I want to do an
i have several common elements (components), that will generate some html. it seems my
I have several same HTML elements going one after another: <span>1</span> <span>2</span> <span>3</span> I'm
I have several elements on the html page, I call them through javascript like
I have several HTML blocks on a page set up like: <p class=something> <a

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.