The CSS table has a rounded background, but its borders have a squared design

I am attempting to design a table with rounded top borders on both sides, while the remaining borders of the table remain squared.

Despite applying CSS, the borders continue to appear squared, although the background-color is indeed rounded, resulting in an odd appearance:

table {border-collapse:collapse}
th {border-top:1px solid red; width:70px}
th, td {text-align:left; background-color:#cccccc}
th.header1 {border-top:1px solid red; border-left:1px solid red; border-top-left-radius:20px}
th.header2 {border-top:1px solid red; border-right:1px solid red; border-top-right-radius:20px}

The outcome looks like this:

Is there a way to achieve a 'rounded' effect on the borders in the top left/right header cells so that the red border aligns with the background color?

For a demonstration, please refer to the JSFiddle.

Answer №1

The reason for this is that the border collapsed using:

CSS

table {
    border-collapse: collapse;
}

Check out this quick solution.

Answer №2

modify:

   table {
    border-collapse: collapse;
}

to:

 table {
    border-collapse: separate;
    border-spacing: 0px 0px;
}

DEMO

Answer №3

To address this issue, consider simplifying the solution by specifying the border properties exclusively for the table element, rather than applying them to both the th element and td element.

table {
    background: #ccc;
    border-top-left-radius: 20px;
    border-top-right-radius: 20px;
    border-top: 1px solid red;
}
th {
    width: 70px;
}
th, td {
    text-align: left;
}

http://jsfiddle.net/Tomer123/z5832/9/

Answer №4

Below is an example of how to use the following code:

table {border:collapse;}
th {border-top:1px solid red; width:70px}
th, td {text-align:left; background-color:#cccccc}
th.header1 {border-top:1px solid red; border-left:1px solid red; border-top-left-radius:20px}

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

The autoplay feature of the HTML5 audio player is not working on iOS Safari

<audio controls autoplay> <source src="horse.ogg" type="audio/ogg"> </audio> The audio element is programmed to autoplay, but it does not work on iOS browsers. I even attempted to trigger a simulated click, but the autoplay feature sti ...

The hover effect on MUI TableRows is being overshadowed by the background color of the TableCell

I'm currently using @mui/material version ^5.10.1. My challenge is applying the TableRow hover behavior as outlined in the documentation. However, I have also set a background color for the first TableCell in each row, which ends up overriding the ho ...

What is the best way to center my menu/logo instead of having it all the way to the right?

I am facing an issue with centering my menu and logo on my website. You can view the page here: Currently, the logo and menu appear to be aligned to the right instead of being centered. I have tried adjusting margins and other settings, but it does not se ...

Make sure that the two rows in my Bootstrap table are consistently positioned next to each other, regardless of the length of the text

When working with a Bootstrap panel containing text inside a table, I've encountered a challenge. One side features links while the other displays descriptions. At times, I find myself having to artificially lengthen the text to ensure it aligns corre ...

Building a local storage feature using HTML5 WebControl in a Winform application

Welcome, fellow software developers! I am currently working on a WinForm application that utilizes the WebBrowser control to host an HTML5 web app. This web app relies on two key HTML5 features: 1. Application Cache 2. Local Storage While the Application ...

Top ways to avoid default on anchor tags: best practices for preventing this issue

Previously, excluding the criticism for not using unobtrusive JS, I typically employed anchors with inline onclick attributes for AJAX loading in the following format: <a href="http://example.com/some/specific/link.php?hello=mum" class="menu" id="m ...

Utilizing the "row" and "column" attributes in Angular (Flexbox) results in significant spacing between input fields within the HTML code

I'm working on aligning 2 input fields side by side within the same line. To achieve this, I've been utilizing Flexbox. However, I've observed that when using Flex with both 'row' and 'column', it introduces extra spacing ...

A guide on converting an HTML tag ID to a PHP string

I am currently working on a project that is giving me some trouble with errors. I have created an HTML file called name.html and a PHP file named result.php. In the HTML file, I included some JavaScript to take us to result.php when we click on the Submit ...

Display the contents of an array retrieved using the getElementById method

My goal is to utilize the document.getElemntById as a unique identifier for listing arrays function aircraft(operator) { var model = document.getElementById('model').value; var B738 = ['39.5', '35.8', '12.5', &a ...

Query in MySQL to select distinct rows and non-distinct rows

Looking to run a query on a table where the names are distinct and the emails are not Here is how my database is structured: Name Email john <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bfdad2ded68effd2c6c8daddccd6cbd ...

jQuery counter no longer updates when scrolling

I'm having trouble with my jQuery counting function when using the scroll feature on a specific div ID. The numbers freeze if I keep scrolling before they finish updating on the screen. Whenever I scroll to the defined div ID, the counting function k ...

Pause the YouTube video and swap it out with an image

I am currently working on incorporating an embedded YouTube video into my project. I want to replace the video with an image, and when the image is clicked, the video should start playing. I have successfully implemented this functionality: <script typ ...

Having trouble with displaying the modal dialog in Twitter Bootstrap 3?

There seems to be an issue with my Twitter Bootstrap modal as it is not rendering the dialog box correctly, and I'm puzzled about the reason behind this. HTML <p class="text-center btn-p"><button class="btn btn-warning" data-toggle="modal" ...

Querying Using Multiple Filter Selectors

Currently, I am in the process of developing a jQuery multiple filter module and have encountered a logic gap in my framework. Within this module, there are numerous div elements each containing data-x and data-y attributes. For instance: <div class= ...

What is the best way to ensure the box div is centered responsively?

Here is the code for my HTML file: body { background-color: rgb(231, 59, 59); font-family: "Alata"; font-size: 20px; margin: 30px; } h1 { margin-top: 100px; color: #202124; text-align: center; } .box { width: 1000px; } input { positi ...

AngularJS, Gridster, and n3-charts are causing a $digest error in Chrome and Firefox, but not in Safari

My project involves developing an Angular app to generate a dashboard featuring various charts within gridster items. The dashboard layout is structured using Angular-gridster, while the charts utilize n3-charts. When attempting to display a chart within a ...

Inconsistency with div heights in Chrome, unlike Firefox and IE where it works smoothly

I am in the process of creating a simple website using MVC3, with plans to make it easily expandable in the future. Despite my limited skills in javascript, I have attempted various online solutions to address a persistent issue with Chrome. Some have sugg ...

Accordion checkbox with dynamic features

Currently, I am dynamically populating data into a jQuery accordion. My goal is to include a checkbox just before the <h2> text. <div id="checkbox"> <h2> <span> <input type="checkbox" class="mycheck" value="apple" / ...

Troubleshooting material design CSS problem in AngularJS routing module

Attempting to incorporate material design with routing in angular js, but encountering issues with CSS design not working. Interestingly, when using bootstrap CSS, it functions properly. Check out the Plnker Demo here However, upon trying this approach, ...

Retrieve the blob value from outside the canvas by using the ToBlob() function asynchronously

I have encountered an issue with the HTMLCanvas element where it returns a blob object outside of the async toBlob() function. Since this function does not return an output value, I have attempted to declare a variable outside and then access it through th ...