Is there a way to remove extra elements following the application of the after pseudo-class selector?

I have been working on making a table mobile responsive, and I am striving to replicate a specific design. The image linked here shows the goal I am aiming for: https://i.sstatic.net/1xFLf.png

So far, this is what I have managed to achieve: https://i.sstatic.net/6mZIs.png

My current implementation involves using the after pseudo-selector to add horizontal lines to the table. However, only the first five tables from the mockup are showing up. I have set the display property of the other elements to none, but the horizontal line appears for everything.

To see what I mean, take a look at this image: https://i.sstatic.net/QZUc3.png

I am wondering if there is a way to disable the horizontal line for the last element so that only the first five elements appear without it.

@media (max-width: 500px) {
  body {
    overflow-x: hidden;
    margin: 0;
  }
  .date-container {
    width: 260px;
    height: 40px;
    ...
<div class="email-table">
  <table>
    <tr>
      <th>From <span><img src="./assets/icon_arrow01.svg" alt=""></span></th>
      <th>To</th>
      <th>Subject</th>
      <th class="date">Date <span><img src="./assets/icon_arrow01.svg" alt=""></span></th>
...

Answer №1

To select all the tr elements starting from the 6th one onward, you can use this CSS rule:

tr:nth-of-type(6) ~ tr {
  display: none;
}

If your previous CSS rules are nested, you'll need to nest as well to override the previous display: grid property like this:

.email-table table tr:nth-of-type(6) ~ tr {
  display: none;
}

You can also achieve the same effect using !important:

tr:nth-of-type(6) ~ tr {
  display: none !important;
}

It's generally recommended to avoid nesting and use class names for better element identification, thus preventing similar issues in the future.

CSS code snippet
...
HTML Code
<div class="email-table">
  <table>
    ...
  </table>
</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

Unable to retrieve file paths for assets using Node.js Server and Three.js

I am facing challenges when it comes to loading 3D models from a folder on my computer using a localhost node.js test server with the three.js library. Below is my app.js file that I execute via command line in the project directory using the 'node a ...

How can I inject an isolated scope object into an Angular custom directive template?

Having trouble using an object in an angular template within a custom directive. Take a look at this plunker to see the issue I'm facing. After some experimentation, I realized that I need to utilize scope: {address: '='} to pass an object ...

A guide on creating a clickable div with a dynamic URL in a Django template

I want to create a post display similar to a tweet on Twitter, where the entire div is clickable. The current code I have seems to achieve this functionality: <div onclick='location.href="{% url 'post' post.id %}";' style=& ...

Customize Bootstrap 4 borders within a row

I am currently facing an issue with my code, where there is a border at the bottom of every row. Click here to view the code Unfortunately, I have noticed that the border at the bottom of each row does not extend across the full width. This occurs even wh ...

Sticky navigation bar anchored to the top of the webpage using CSS and HTML

Currently, I am in the process of learning CSS3 and HTML5 but I'm facing some confusion. My goal right now is to create a webpage with a fixed navigation bar at the top that scrolls along with the page. Although the navbar is fixed at the top and doe ...

Can the appearance of the Chrome browser be altered to resemble a printed page?

Simply put, I'm tackling a massive project right now. While my print.css is functioning perfectly, the task of constantly previewing the print page has become incredibly frustrating. What's more, it's impossible to inspect the page effectiv ...

Adjust the dropdown width on a bootstrap form to match the size of the textbox

In order to maintain a combined width of 450px, I have two textboxes. One textbox includes a dropdown menu while the other does not. Both textboxes are part of an input group. The dropdown can switch between either textbox at any time. I need the width ...

"What is the significance of the .default property in scss modules when used with typescript

When dealing with scss modules in a TypeScript environment, my modules are saved within a property named default. Button-styles.scss .button { background-color: black; } index.tsx import * as React from 'react'; import * as styles from ' ...

In an HTML template, what is the significance of the $ symbol?

Currently, I am exploring the web.py framework with the help of a tutorial that I found online. This tutorial focuses on Python and AJAX functionalities. One thing that is confusing me in the tutorial is the use of variables with a $ sign in the tutorial ...

"Disappearing act: Navigating through pages causes the navigation

Struggling with navigation in my asp.net core web app development. My directory structure includes the use of Areas. https://i.sstatic.net/DL6qe.png https://i.sstatic.net/GeEg9.png When navigating through pages in the main folder like Index, Index1, and ...

Unable to display <iframe> containing a YouTube video on Mozilla Firefox page

I have included an <iframe> in my webpage to display videos from YouTube, but I am facing an issue with Mozilla Firefox. In Chrome, IE, and Edge, the videos display correctly using the following code: <iframe src="http://www.youtube.com/v/DNLh8p ...

Grow the Bootstrap column when hovered over (Similar to Netflix)

My grid view is structured as follows: jQuery(window).resize(function(evt) { jQuery(".grid-content > div > div > .channelImage").height(jQuery(".grid-content > div > ...

Inheriting CSS Styles in a JavaScript Toolbar Plugin

Recently, I created a javascript plugin that can be activated by clicking a button on my browser's toolbar. While it functions perfectly on certain websites, it appears unappealing on others due to inheriting CSS styles from the site itself. Are the ...

Words are elusive as I furiously tap away at the keys

While working inside the div, I noticed that when I type rapidly on the keyboard, the text suddenly disappears onto a second line. This issue does not seem to be caused by overflow:hidden. What could be causing this text hiding behavior, and is there an a ...

Is the z-index functioning properly for the header call-to-action text on mobile devices, but not on desktop?

The desktop header cta is functioning properly, but when I switch to mobile nothing happens. I attempted to increase the z-index number within the html instead of in the style sheet. This is where my CTA is located in the html: CALL TO ACTION surrounded ...

What could be causing disparities in the padding of certain table cells compared to others?

If you're interested, I created a photo gallery over at Take a look around and feel free to download any wallpapers that catch your eye! The issue I'm encountering is with the padding of the columns - specifically, the first and last columns ha ...

Is utilizing a personalized hook the most optimal resolution?

Currently, I am in the process of developing a chess application and encountered a scenario where I needed the board size to dynamically adjust to the window size while maintaining a square aspect ratio (width equals height). To address this, I created my ...

Customizing Bootstrap by incorporating my own external stylesheet

I've been working on learning Bootstrap and decided to challenge myself by trying to recreate this website: However, I'm encountering difficulties when it comes to overriding Bootstrap and incorporating my own custom font. I attempted to add a G ...

Chrome DevTools automatically translates all HEX color codes into their corresponding RGB values

Chrome DevTools now automatically converts all HEX colors to RGB values, even if the color is set in CSS or using DevTools. Is there a way to prevent this conversion? I know about the method of holding down Shift + clicking the color icon to convert color ...

Using JQuery to parse an XML file and automatically redirecting the page if a specific attribute equals "Update"

Updated I've made some edits to clarify my request. My website is built using HTML5, CSS3, and JQuery, resulting in all content being on one page. During updates, I want the ability to set an option in a configuration file so that when users visit m ...