Ways to apply a border-bottom to tr elements without affecting td elements

Is there a way to add a bottom border to <tr> elements without affecting <td> cells that have no border?

I attempted the following approach, but setting border: 0 for <td> overrides the border for all <tr> elements as well, leaving only <thead> and <th> with borders!

table.admin_datagrid tbody tr {
     border:1px solid red;
}

table.admin_datagrid td{
    border: 0;
}

Answer №1

Were you asking about adding borders between the rows but not between the columns?

table.admin_datagrid tbody tr {

}

table.admin_datagrid td{
    border-left: 0;
    border-right: 0;
    border-top:1px solid red;
    border-bottom:1px solid red;
}

Answer №2

The problem here is not with the td border overriding the tr border, but rather with attempting to set a border on the tr element. Instead, consider applying a class to the td elements in the row that require a bottom border:

Here's an example using HTML:

<table class="data-table">
    <tbody>
        <tr>
            <td class="border-bottom">
                Text1
            </td>
        </tr>
        <tr>
            <td>
                Text2
            </td>
        </tr>
    </tbody>
</table>

And the corresponding CSS:

table.data-table td.border-bottom {
     border-bottom: 1px solid blue !important;
}

table.data-table td{
    border: 0;
}

Check out this JSFiddle for a working example: http://jsfiddle.net/8t7Lz/

Answer №3

Revise the sequence and include display:block :

table.admin_datagrid td{
    border: 0;
}

table.admin_datagrid tr {
     display: block;
     border:1px solid red;
}

Fiddle: http://jsfiddle.net/z5GZN/

Answer №4

To improve the structure of your table, include the CSS property border-collapse: collapse.

SEE DEMO

table{
      border-collapse: collapse; 
}
table.data_table tbody tr {
     border: 1px solid blue;
}

table.data_table td{
    border: none;
}

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

When scrolling, a new page loads seamlessly

Recently, I came across a website that has an interesting feature where new content is loaded automatically while scrolling, seamlessly appending to the existing page. What's more fascinating is that not only does the content change, but the URL also ...

Incorporating Sass into Django

As I delve into my Django Project, one question looms large: where exactly should all my Sass files be placed? Is it more practical to create a central 'Sass' folder within the main Project Folder or designate a 'Sass' directory for eac ...

"Problem with the Hide/Show Load feature: it's not functioning

After a user submits a form, my script shows 2 divs and hides 1 div. The form's target is an Iframe on the same page. I am looking to delay the Hide/Show events until the Iframe loads. I was successful in accomplishing this with a loading animation, ...

Creating a Star Rating System Using HTML and CSS

Looking for help with implementing a Star rating Feedback on articles in Visualforce page. Came across some code that seems to fit the bill but facing issues with getting it to work when placed in a file and executed, particularly in Firefox. Any assistanc ...

Locate the parent element that has the smallest amount of space taken up by its child elements

My goal is to determine which container, among several <divs>, each containing multiple child <divs> of varying sizes, has the smallest amount of space covered by the child elements. <div class="container" id="first"> ...

Tips for disabling default browser input validation in React

https://i.stack.imgur.com/834LB.png Is there a way to remove the message "Please fill out this field" while still keeping the "required" attribute intact? I have my own validation system in place, so I need to use the "required" attribute to determine whe ...

Images are failing to show up in the iPhone design

Encountering issues with displaying images on an iPhone? You can replicate the problem by minimizing your browser window horizontally. Here is a link showcasing the problem: here. To temporarily fix this, try zooming out the browser (Ctrl+-). You can see a ...

Updating the logo image on mobile devices using responsive CSS styling

My goal is to show a different image to users on mobile devices using only CSS, as I am unable to access the HTML code. On mobile, I used display:none for the header-logo-image img { and then added a background-url to the div to successfully display my alt ...

Implement a hover effect on a specific class targeting a nested element using JavaScript

Is there a method to apply a class that modifies rules for a child element using Javascript? I have successfully added it with CSS but am struggling to do the same with Javascript. Removing the class in JS is easy by referencing the classname before the ho ...

Display overlay objects specifically focused around the mouse cursor, regardless of its position on the screen

I am currently working on a project using SVG files and processing.js to develop a unique homepage that incorporates both animation and static elements. The concept is to maintain the overall structure of the original homepage but with varying colors, esse ...

What CSS property prevents a fixed header from overlapping a scrolled element?

After creating a fixed header for my HTML table, I noticed that as I scroll down the page, everything is being overlapped by the fixed header except for one slider (noUiSlider). I am curious to know which CSS property is preventing the header from overlayi ...

What could be the reason for this code not displaying buttons on separate lines rather than next to each other?

I am struggling to get the Logo to print followed by all buttons lined up side-by-side. I have experimented with different display properties within the first <div> tag such as block, inline-block, and even removing the display property altogether. ...

The text box is intersecting with the photo

Struggling to craft a clean layout with an upvote button, I encountered an issue where the textarea appears to overlap with the image. Below is my sample code snippet: .my-component-row { display: flex; justify-content: center; align-items: center ...

Styling images with text alignment in CSS

I'm trying to figure out how to align an image to the left, some text to the top right, and some text to the bottom right. The parent div contains a background image. <div id="parent" style="background: url(bg.jpg) repeat-x left top"> <i ...

Struggling to grasp the concept of using z-index in CSS

As a programmer versed in Python, C, Java, and Delphi, I am not a web developer or designer by trade. However, when required to fill those roles, I do my best; please be patient with me. :-) I have created a map (with a background image as a div), where I ...

What methods are available to generate dynamic shapes using HTML?

Looking to create an interactive triangle where users can move vertices or sides, updating angles in real-time. I'm struggling with how to accomplish this task. My initial attempt was to manually draw the triangle using the code below. <!DOCTYPE ht ...

Changing the order on mobile devices in Bootstrap 4: A quick guide

Currently, I am working on a responsive layout using Bootstrap 4 with two columns. Each column contains a total of 9 divs - four in the first column and five in the second column. My goal is to rearrange the order of the divs within the columns when the vi ...

Using "overflow-x: hidden" is ineffective on mobile devices

I'm facing an issue where the CSS property overflow-x: hidden is not working on mobile devices. Here is a snippet of my HTML code: <div class="topbar"> <div class="navbar-brand float-left"> <a href="#"><img src="asset ...

Determining the browser width's pixel value to enhance responsiveness in design

Lately, I've been delving into the world of responsive design and trying to grasp the most effective strategies. From what I've gathered, focusing on content-driven breakpoints rather than device-specific ones is key. One thing that would greatl ...

How can I use CSS to transform a "+" symbol to an "x"?

When I created an accordion using HTML, JS, and CSS, I encountered a problem. The "+" sign in the accordion does not rotate correctly as it should. Instead of rotating from the middle of the "+" sign, it rotates from the top. This is my HTML code: <di ...