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

Certain iFrame instances are unable to display specific cross-domain pages

I'm currently working on a project to create a website that can embed external cross-domain sites, essentially like building a browser within a browser. I've been experimenting with using iFrames for this purpose: While it works for some pages, ...

"Utilizing the power of Twitter Bootstrap and Snap.js for

I am currently working on integrating Snap.js by jakiestfu with Twitter Bootstrap. I have managed to make it work to some extent (I can slide the content and open a drawer through a click event). However, I am facing a challenge where the drawer content re ...

What could be the underlying reason for the unusual behavior observed in this range polyfill implementation?

I am attempting to transform an HTML5 range input into a set of radio buttons. Each radio button corresponds to a value within the original range, with text displaying its value. However, I am encountering an issue where the last piece of text, meant to sh ...

Sending the complete data from an HTML table to a web method

Is there a way to pass the data from a dynamically generated HTML table grid to a web method using jQuery AJAX? The table grid creates multiple rows on button click at runtime, and I need to send the entire table data. Please refer to the following snaps ...

Adjusting the height of a div inside a Material-UI Grid using Styled Components

When the mouse hovers over the two cells highlighted in pink, they turn pink. Is there a way to make the entire grid fill with pink when hovered over, both width and height at 100%? Check out the sandbox here ...

Load media upon the click of an image

I'm currently in the process of designing a team page for our website. Each team member's photo is displayed in a grid layout, with two boxes positioned below containing various content. Box 1: This box consists of basic text information. Box 2: ...

The functionality of Vue.js Stylus and scoped CSS appears to be malfunctioning

I am currently utilizing stylus and scoped CSS styles with Vuetify. Despite trying to use deep nested selectors such as ::v-deep or >>&, I have not been successful in getting them to work (even after rebuilding the project due to issues with hot relo ...

align all items centrally and customize Excel columns based on the length of the data

Is there a way to dynamically adjust the column width based on the length of data in an Excel report using PHPexcel? Additionally, how can I center all the data in the Excel sheet? Here is the current code snippet: <?php if (!isset($_POST['send&a ...

_my_custom_styles.scss are being overridden by reboot.scss

Hey there, I'm currently facing an issue where my custom CSS is getting overwritten. Even though I have placed my custom CSS beneath the CDN bootstrap reference, it doesn't seem to resolve the problem. For instance, when attempting to change the ...

Leveraging the power of Ajax in JavaScript

For my assignment, I successfully made two separate paragraphs hide and show using jQuery. Moving forward, the next step involves integrating JavaScript Ajax code to allow the paragraphs to toggle visibility. To achieve this, I created two distinct HTML fi ...

Tooltips experience issues when interacting with elements that do not utilize the :active state

$(function () { $('[data-toggle="tooltip"]').tooltip() }) <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" ...

The timer is malfunctioning

I am new to JavaScript and looking to create a simple countdown. I came across this script: http://codepen.io/scottobrien/pen/Fvawk However, when I try to customize it with my own settings, nothing seems to happen. Thank you for any assistance! Below is ...

What is the best way to decrease the font size of every element in the DOM?

Is there a way to decrease the size of all DOM elements by a specific amount? Currently, I am using Bootstrap styles where h5 is set at 14px and I need it to be 12px, and h1 is at 36px when I want it to be 34px, and so forth. I have considered two option ...

Add CSS styles to the outermost container element when the slideshow is currently in use

On my homepage, I have a carousel featuring multiple slides. However, when the third slide appears in the carousel, the positioning of the carousel buttons within the div class="rotator-controls" shifts downward due to the space taken up by the image. My o ...

Steps for removing all inline styles within an element:1. Access the element's

I have a group of span elements containing texts generated by tinymce. <span class="ArticleSummary"> This content is produced using a text editor and may include various inline styles. </span> Typically, this text includes numerous inline s ...

What is the best way to achieve a transparent background for an element?

Having trouble making elements transparent in the background for mobile view with React. I've attempted adding background-color and background with a value of transparent to various classes, but it's not working as intended. Any suggestions on h ...

Retrieve input value from a jQuery template

I've created a template <div id="template" style="display: none;"> <strong>Name</strong>: <span class="name"></span><br/> <input type="number" id="amount"> <button type="button" onclick="App.submit ...

Echo command fails to work with location.href

I am facing a small issue with my PHP echo. I have a JavaScript link function that is not working because the HTML code shows this type of link onclick="location.href="http://www.link.com/";". It's clear that this syntax won't work. However, if w ...

Pictures Unavailable to Show in Table

I've been working on a project where I need to insert some images into a table. Usually, this isn't an issue for me. However, today when I added the images to the table, all I see is a square border with the alt text inside it. I'm confident ...

centered logo in a flexbox header

Having trouble with Flex for the first time. Despite reading and experimenting, I still can't figure it out. Any suggestions on how to accomplish this? Check out an example ...