Having trouble understanding why the border-radius attribute is not being applied to tables?

I've been trying to give the outer corners of tables a rounded appearance in HTML/CSS, but I can't seem to get the border-radius property to work properly.

After inspecting the elements in Chrome's computed section, I noticed that the elements have a default border of 3, which is encroaching into the rounded corners. When I try adding "border: 0"; it doesn't make any difference. I suspect that the browser may be applying a default border.

I would really appreciate any suggestions or tips on how to solve this issue.

Thank you.

* {
  box-sizing: border-box;

}

h1 {
  color: rgb(11, 8, 165);
  text-align: center;
  margin-bottom: 80px;
}

h2 {
  color: rgb(5, 59, 41);
  text-align: center;
}

body {
  background-color: rgb(226, 220, 176);
}

.firstPara p {
  text-align: center;
}

table {
  border-collapse: collapse;
  margin-left: auto;
  margin-right: auto;
  border-radius: 15px;
  overflow:hidden;
  perspective: 1px;
  border: 0px;
}

.univeralSelector {
  color: rgb(211, 21, 21);
}

table thead tr th {
  background-color: rgb(11, 134, 93);
  color: white;
  padding: 12px 15px;
  border: 3px black solid;
}

table tbody tr td {
  border: black solid;
  padding: 12px 15px;
  font-size: 0,9rem;
}
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8>
  <meta http-equiv="X-UA-Compatible" content="IE=edge"></head&
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="/styles.css">
  <title>Common CSS Properties</title>
</head>
<body>
  <header><h1>Common CSS Properties</h1></header>
  
  <h2>Different Types of Selectors</h2>
  <div class="firstPara">
    <p>Selectors are used to style HTML elements according to their type and/or attributes.
      <br>
       All markups can be selected with the universal selector: "
       <span class="univeralSelector">*</span>  "{
        /* declarations here */
      }
    </p>
  </div>
  
  <table>
    <thead>
      <tr>
        <th>Select by</th>
        <th>Syntax</th>
        <th>Example</th>
      </tr>
    </thead>

    <tbody>
      <tr>
        <td>Type</td>
        <td>element-name {
        /* declarations here */}</td>
        <td>
        p {
          text-align: center;
          color: red;}</td>
      </tr>

      <tr>
        <td>Attribute</td>
        <td>'id' (in the HTML file) '#' (in CSS file) 
          <br>'class' (in HTML file) '.' (in CSS file)</td>
        <td>#para1 {
          text-align: center;
          color: red;
        }
        <br>
        .center {
          text-align: center;
          color: red;}</td>
      </tr>
    </tbody>
  </table>

  <h2>CSS Units</h2>
  
  <table>
    <thead>
      <tr>
        <th>Absolute Units</th>
        <th>Relative Units</th>
      </tr>
    </thead>
    <tb>
      <td>
        <ul>
          <li>
            em: Property size relative to property size of direct parent element (most common)
          </li>
          <li>
            rem: Property size relative to property size of direct root element
          </li>
          <li>
            vw: Percentage based on width of screen
          </li>
          <li>
            vh: Percentage based on height of screen
          </li>
        </ul>
      </td>
      <td>
        <ul>
          <li>px: Pixels (most common)</li>
          <li>pt: Points</li>
          <li>mm: Millimeters</li>
        </ul>
      </td>
    </tb>
  </table>
</body>
</html>

Answer №1

There are a couple of issues to address here - firstly, the border is being applied to the table cell instead of the table itself where the border-radius is set.

If you're experiencing problems with border-collapse: collapse;, consider using

border-collapse: separate;border-spacing: 0px;
as an alternative solution.

You can achieve rounded corners on your table borders by combining table and cell borders for a more visually appealing grid.

Below is a functional implementation:

* {
  box-sizing: border-box;
}
h1 {
  color: rgb(11, 8, 165);
  text-align: center;
  margin-bottom: 80px;
}
h2 {
  color: rgb(5, 59, 41);
  text-align: center;
}
body {
  background-color: rgb(226, 220, 176);
}
.firstPara p {
  text-align: center;
}
table {
  margin-left: auto;
  margin-right: auto;
  perspective: 1px;
}
.univeralSelector {
  color: rgb(211, 21, 21);
}
table thead tr th {
  background-color: rgb(11, 134, 93);
  color: white;
  padding: 12px 15px;
}
table tbody tr td {
  padding: 12px 15px;
  font-size: 0.9rem;
}
table {
  border-collapse: separate;
  border-spacing: 0px;
}
th {
  border: 3px solid black;
  border-right: 1px solid black;
  border-left: 2px solid black;
}
th:first-child {
  border-left: 3px solid black;
}
th:last-child {
  border-right: 3px solid black;
}
td {
  border-left: solid black;
  border-bottom: solid black;
}
td:last-child {
  border-right: solid black;
}
th:first-child {
  border-top-left-radius: 15px;
}
th:last-child {
  border-top-right-radius: 15px;
}
tr:last-child > td:first-child {
  border-bottom-left-radius: 15px;
}
tr:last-child > td:last-child {
  border-bottom-right-radius: 15px;
}
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8>
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="/styles.css">
  <title>Common CSS Properties</title>
</head>
<body>
  <header><h1>Common CSS Properties</h1></header>

  <h2>Different Types of Selectors</h2>
  <div class="firstPara">
    <p>Selectors are used to style HTML elements based on their type and/or attributes.
      <br>
       All tags can be styled with the universal selector: "
       <span class="univeralSelector">*</span>  "{
        /* declarations go here */
      }
    </p>
  </div>

  <table>
    <thead>
      <tr>
        <th>Select by</th>
        <th>Syntax</th>
        <th>Example</th>
      </tr>
    </thead>

    <tbody>
      <tr>
        <td>Type</td>
        <td>element-name {
        /* styling goes here */}</td>
        <td>
        p {
          text-align: center;
          color: red;}</td>
      </tr>

      <tr>
        <td>Attribute</td>
        <td>'id' (in the HTML file) '#' (in CSS file) 
          <br>'class' (in HTML file) '.' (in CSS file)</td>
        <td>#para1 {
          text-align: center;
          color: red;
        }
        <br>
        .center {
          text-align: center;
          color: red;}</td>
      </tr>
    </tbody>
  </table>

  <h2>CSS Units</h2>

  <table>
    <thead>
      <tr>
        <th>Absolute Units</th>
        <th>Relative Units</th>
      </tr>
    </thead>
    <tb>
      <td>
        <ul>
          <li>
            em: Property size relative to property size of direct parent element (most common)
          </li>
          <li>
            rem: Property size relative to property size of direct root element
          </li>
          <li>
            vw: Percentage based on width of screen
          </li>
          <li>
            vh: Percentage based on height of screen
          </li>
        </ul>
      </td>
      <td>
        <ul>
          <li>px: Pixels (most common)</li>
          <li>pt: Points</li>
          <li>mm: Millimeters</li>
        </ul>
      </td>
    </tb>
  </table>
</body>
</html>

Answer №2

When using the table tag, border-radius does not function properly if you have set the CSS property "border-collapse: collapse;". To resolve this issue, try changing it to "border-collapse: separate;"

Answer №3

When trying to use both border-collapse and border-radius, there is a conflict that prevents border-radius from working properly. One solution is to wrap the table within a div element, then apply the desired border and border-radius styles to the div element instead of the table.

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

Incorporate Arabic typography into the React Material Theme

My goal is to utilize the Noto Sans Arabic font within my React material UI theme. Everything seems to be functioning correctly, including overrides. Despite consulting the React Material UI documentation and attempting to follow similar steps as outlined ...

What is the Best Way to Create a Smooth Border-Bottom Transition?

I'm currently diving into the world of HTML5 and CSS. I want to replicate the layout from . Specifically, I am interested in adding a transition effect to the border bottom of certain elements such as "View Our Listings", "The Agency Daily", "Meet our ...

Disabling the ripple effect on the primary action in React Material lists: A Step-by-Step

I was attempting to include two action buttons at the opposite ends of a list component. https://i.stack.imgur.com/juv8F.gif When clicking on the secondary action (delete icon on the right), the ripple effect is confined to just the icon. On the othe ...

Troubles with Conditional Application of CSS Styles to a Twitter-Bootstrap Table

I am facing an issue with highlighting a row in a table when a barcode is entered. Despite following similar scenarios and checking my code, the CSS doesn't seem to be applied. Can anyone help me figure out what I'm missing or how I can fix this? ...

Adjust padding of elements based on scrolling movements

Currently, I am attempting to adjust the padding of a specific element based on how far down the page the user scrolls. Ideally, as the user scrolls further down the page, the padding will increase, and as they scroll back up, the padding will decrease. H ...

The jsPdf library performs well on medium-sized screens like laptops, but when downloaded from larger monitor screens, the PDF files do not appear properly aligned

In the code snippet below, I am using html2canvas to convert HTML to PDF. The PDF download works fine on medium screens, but when viewed on larger screens, some pages appear blank and the content order gets shuffled. How can I resolve this issue so that th ...

Styling text on a HTML webpage

Is there a way to center text in the caption and add a link on the far-right of the caption? Let me know if this is possible. The format for the caption should be: Centered Text Right-justified link ...

Guide to adding a tag in front of a text in HTML with Python

Searching for all the text within the html document and wishing to incorporate a span tag that contains additional information about each text as shown below def recursiveChildren(x): if "childGenerator" in dir(x): for child in x.childGenerator( ...

Perfect CSS Menu Hover Effect

I created my own navigation menu, and I'm struggling with one thing... How do I change the A tag color to white when hovering over the ul id "navitemul"? I've tried #lovedating#navitemul:hover #lovedating a {color:white} and other methods, but no ...

Troubleshooting a Navigation Styling Issue in HTML and CSS

I'm struggling to position my drop-down menus correctly in my WordPress theme navigation. They are appearing far away from the nav bar and end up near the top left corner of the screen when I hover over a ul li >. Here is the CSS code I am using: # ...

Shift the content downwards within an 'a' snippet located in the sidebar when it reaches the edge of the right border

I'm having an issue with my style.css file. As a beginner in programming, I am trying to position text next to an image attached in the sidebar. However, the text is overflowing past the border. Here's the HTML code: Please see this first to ide ...

Struggling with applying mixins

Is it possible to select only the top border using this mixin? Currently, I only need a top border but would like to have the option to use others in the future. Using separate mixins for each side of the border seems inefficient. .bordered(@top-width: 1 ...

implement a Django for loop within the template by utilizing JavaScript

Is it possible to incorporate a {% for in %} loop and {{ variables }} in a Django template using JavaScript DOM (insertAdjacentText, or textContent) and dynamically load data from the views without refreshing the entire page? If so, can you please guide me ...

Chat box custom scrollbar always positioned at the bottom

I have a personalized chat box where I included overflow-y for scrolling functionality. However, every time I input a message in the text box, it displays at the top of the scrollbar window. Is there a way to automatically show the most recent message I ...

How to fetch an image from a web API using JavaScript

I have recently entered the world of web development and I am facing an issue where I am trying to retrieve a Bitmap Value from a web api in order to display it on an HTML page using JavaScript. However, despite my efforts, the image is not getting display ...

Moving the element from the right side

Is there a way to change the direction of this element's transition from left to right, so that it transitions from right to left smoothly without any gaps between the element and the edge of the page? @keyframes slideInFromRight { 0% { trans ...

What could be preventing the background image from displaying properly?

I had the idea to create a game where players have to flip cards to reveal what's on the back, but I'm struggling to get the background image to display properly. As a newcomer to Vue, I'm not sure if I made a mistake somewhere. My intuition ...

Should I implement this practice when developing an AJAX website? Is it recommended to enable PHP code within .html files, or should I switch to using .php files instead?

Query: I am interested in executing PHP within HTML documents to include HTML using PHP include();. Question: Would it be more beneficial to change .php to .txt for my AJAX-loaded pages and switch my .html files to .php? This approach might resolve the ...

Don't forget to preserve the hover state of divs even after refreshing

I recently added a navigation bar that expands in width upon hovering over it. For an illustration, check out this example: http://jsfiddle.net/Gsj27/822/ However, I encountered an issue when clicking on a button within the hover effect area. After load ...

The challenge of aligning widgets in bootstrap panels across different browsers

Incorporating angularjs and bootstrap3, I'm in search of the best way to center widgets within a panel and achieve responsive behavior. Interestingly, the results vary across browsers, particularly in Firefox. Within my code, I have 4 column divs str ...