Design a layer that rests on top of a specific table column

I am currently working with a table that consists of 5 columns (

city, 1st quarter, 2nd quarter, 3rd quarter, 4th quarter
).

My goal is to create an overlay on each column if we have already passed a specific quarter. However, I am encountering difficulties in making the overlay cover the entire column, including its padding. Does anyone have suggestions on how to achieve this? Below is the code I have been working on:

http://jsfiddle.net/7kp3atp7/1/

Answer №1

This issue is occurring due to the presence of spaces between table td elements. You have two options to resolve this - either use border-collapse: collapse or make modifications to your current implementation. One way to handle this is by creating an overlay using a pseudo-element :after and applying it to all td elements with the class disable:


.year-calendar {
    width: 918px;
    margin: 0 auto;
    min-height: 260px;
    height: auto;
    background-color: #ffffff;
    border: 8px solid transparent;
    padding: 0px;
    box-shadow: 1px 1px 30px 1px #adb2b7;
    display: block;
    border-radius: 8px 8px;
    -o-border-radius: 8px 8px;
    -ms-border-radius: 8px 8px;
    -moz-border-radius: 8px 8px;
    -webkit-border-radius: 8px 8px;
}

/* Other styling properties for .year-calendar */

td, th {
    position:relative;
}

td.disable:after {
    content:"";
    position:absolute;
    background-color:black;
    display:block;
    width:100%;
    height:100%;
    top:0px;
    left: -5px;
    padding-left: 4px;
    padding-right: 5px;
}
<table class="table year-calendar">
    <thead>
        <tr>
            <th>City</th>
            <th><span class="q1"></span>Q1</th>
            <th>Q2</th>
            <th>Q3</th>
            <th>Q4</th>
        </tr>
    </thead>

    <!-- Table body content -->

You can also address this issue by using border-collapse: collapse in your CSS:


/* CSS code for .year-calendar */
.year-calendar {
    width: 918px;
    margin: 0 auto;
    min-height: 260px;
    height: auto;
    background-color: #ffffff;
    border: 8px solid transparent;
    padding: 0px;
    box-shadow: 1px 1px 30px 1px #adb2b7;
    display: block;
    border-radius: 8px 8px;
    -o-border-radius: 8px 8px;
    -ms-border-radius: 8px 8px;
    -moz-border-radius: 8px 8px;
    -webkit-border-radius: 8px 8px;
    border-collapse: collapse;
}

/* Other styling properties for .year-calendar */

td, th {
    position: relative;
}
.q1 {
    position: absolute;
    background-color: black;
    display: block;
    width: 100%;
    height: 100%;
    top: 0px;
    left: 0px;
}

<!-- HTML table structure with classes applied -->
<table class="table year-calendar">
    <thead>
        <tr>
            <th>City</th>
            <th><span class="q1"></span>Q1</th>
            <th>Q2</th>
            <th>Q3</th>
            <th>Q4</th>
        </tr>
    </thead>

    <!-- Table body content -->

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

Having difficulty targeting the span element in my CSS code

I've got an HTML document that includes multiple span elements. <span>Skip to content</span> There are several of these span elements throughout the document. I've attempted to hide them using the following CSS: span {display: non ...

Enhance your viewing experience by clicking on photos to enlarge them with

Is there a way for me to click on a photo and have it zoom in? Similar to how it works on this website --> I only need one specific photo to zoom in, not a whole gallery. Can anyone assist with this? <img src="images/uploads/phs.jpg"></img&g ...

Are you looking to add some flair to your Flexbox layout using Media

I am in the process of developing a website using flexbox, and one key aspect of the design is to hide the navigation bar, specifically the left panel in this JSFiddle, when the viewport width is between 480px and 1023px. The current implementation achieve ...

Bootstrap4: Is it possible to wrap text on mobile screens when "col-12" is too wide?

I am currently utilizing Bootstrap4 for creating grid systems. Specifically, I am using col-12 for mobile screens and col-md-6 for laptops. However, I have encountered an issue where the first image appears too large on mobile phones and the text extends b ...

Can TypeScript React apps be styled using a style.ts file?

Exploring the world of TypeScript and encountering a new challenge - I've been tasked with styling my app using a style.ts file. Are you wondering if this is possible or how to go about it? Seeking a comprehensive answer on the feasibility of this app ...

Displaying data from a PHP form

I'm working on a table that is populated with data from my controller. The issue I am facing is that only the first record, in this case Sephen C. Cox, does not redirect me when I click the "add employee" button. For all other records, the button work ...

Activate an event on a separate webpage using jQuery or JavaScript

Currently, I am in the process of working on a project with 2 distinct pages: Index Settings On the Settings page, I have implemented a button to close an element and hide it. However, I am encountering an issue where I want the elements on the Index pa ...

What is the best method for fetching the values of a select element in React.js?

I'm struggling to retrieve the value of a selected element in a dropdown list. I've tried debugging it, but haven't been able to get the value. I attempted to console log e.target.value, but unfortunately, it didn't work. Any thoughts o ...

Images that dynamically adjust to different screen sizes with captions that are perfectly

For a while now, I have been utilizing <picture> to display images with more design control. I typically use CSS to show or hide specific images within the <div> block. However, I am now considering using <figure> with <figcaption> ...

Is it possible to manually trigger a version change transaction in IndexedDB?

I have been working on a Chrome extension that uses the IndexedDB to store data client-side in an IDBObjectStore within an IDBDatabase. The data structure requires users to be able to modify the object store freely, such as adding new objects or modifying ...

CSS:Tips for removing borders with border-radius in CSS

I have a div that has been styled with a left-hand border, and it's causing me some trouble. You can view the styling here on Jsfiddle. Is there a way to remove just the left hand side border without affecting the rest of the design or creating an un ...

What is the best way to format specific text as bold within an input text field?

I am attempting to make certain text bold within an input text field. However, I'm uncertain about how to achieve this because HTML code is not recognized inside a text field. Therefore, using <b> will not be effective. Is there a way to bold sp ...

I have come across this building error, what do you think is the cause of it?

My attempt to launch my company's React.js project, downloaded from Tortoise SVN, is encountering an issue. PS C:\Projects\Old EHR> yarn start yarn run v1.22.19 $ next start ready - started server on 0.0.0.0:3000, url: http://localhost:30 ...

Steps to customize a CSS file within node_modules

Is there a way to make changes to a CSS file in the "node_modules" dependency without them being overwritten when I run npm install? I want to keep the modifications I've made to the node module files. ...

Text that disappears upon clicking on show/hide按钮

Could someone please help me figure out how to prevent the "See more" text from disappearing when clicked in the example below? I want it to stay visible. Thank you! ...

Issue with CSS not loading correctly when switching routes in AngularJS using Gulp and Router

I currently have a router set up in my application: var mainmodule.config(function($routeProvider){ $routeProvider.when('/home',{ templateUrl:'src/home/home.html' }; $routeProvider.when('/home/sports',{ ...

An undefined PHP index error was encountered by Ajax, while the other one did not face the same issue

I encountered an issue with ajax where I am receiving an undefined index error on my variables when making a call. Strangely, I have other ajax calls functioning perfectly fine across my website except for this particular one which is giving me troubles. I ...

Disregard the stylesheet that has been provided

I'm currently working on a website using a template that includes a stylesheet. Unfortunately, the stylesheet is causing issues with elements I add such as Google Maps or other custom features on my site. Is there a way to prevent the following tag fr ...

The concept of AJAX send function and toggling button visibility

I am facing a challenge with a textarea and send button on a panel that is displayed after entering the first character. The visibility of the button is controlled by the isButtonVisible() method. Once clicked, it sends the text from the textarea using the ...

What is the best way for a client to showcase a constantly fluctuating server-side variable's value?

On my website's homepage (index.html), I want to show a dynamic server-side global variable called serverVariable. This variable is always changing based on the node.js server-side code. However, since the client doesn't know what serverVariable ...