Designing Tables and Grids with HTML and CSS

Struggling to design the table below, I initially attempted using an HTML table. However, I encountered issues with applying box shadow properly as I needed to round the corners of the first and last td cells rather than the tr element (which doesn't support a border radius). Even when trying to apply a box shadow to the row, it did not round the curved edges as desired.

I also experimented with display:grid & flex, but couldn't find a solution to achieve both the box-shadow/border-radius effect and center aligning the text within columns simultaneously.

Any advice on how to tackle this would be greatly appreciated.

This is the design I was attempting to recreate using HTML and CSS:

https://i.sstatic.net/XpodM.png

The following is the react code snippet used to render the HTML for the table:

<div className="policy-container">
        <div className="policy-table">
            <div className="headings">
                <span className="heading">Name</span>
                <span className="heading">Last Updated</span>
                <span className="heading">Actions</span>
            </div>

            {data.map((row, ri) => (
                <div key={ri} className="policy">
                    <span>{row.name}</span>
                    <span>{row.lastUpdated.format("Do MMM YYYY")}</span>
                    <span>
                        <a href={row.link}>view</a>
                    </span>
                </div>
            ))}
        </div>
    </div>

Answer №1

To achieve a layout like this, I suggest using flexbox in your CSS:

body {
  background-color: #f5f5f5;
  font-family: Arial, sans-serif;
  font-size: 14px;
}

.container {
  color: #333;
  text-align: center;
}

.headers, .item {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-pack: justify;
  -ms-flex-pack: justify;
  justify-content: space-between;
  margin-bottom: 1em;
  padding: 1em;
}

.header {
  flex-basis: 33.333%;
  font-weight: bold;
}

.item {
  border-radius: 10px;
  background-color: #fff;
  margin-bottom: 15px;
  box-shadow: 1px 2px 4px rgba(0, 0, 0, 0.1);
}

span {
  flex-basis: 33.333%;
}

a {
  text-decoration: none;
  color: #666;
}
<div class="container">
  <div class="table">
    <div class="headers">
      <span class="header">Title</span>
      <span class="header">Date</span>
      <span class="header">Link</span>
    </div>

    <div class="item">
      <span>Title 1</span>
      <span>01/01/2022</span>
      <span>
        <a href="/link-1">View</a>
      </span>
    </div>

    <div class="item">
      <span>Title 2</span>
      <span>02/02/2022</span>
      <span>
        <a href="/link-2">View</a>
      </span>
    </div>
  </div>
</div>

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 challenge of utilizing Material UI Grid with Internet Explorer 11

I need help achieving a specific grid layout using the Grid component in Material UI. https://i.sstatic.net/HSsZ4.png Although I was successful in creating this layout in Chrome and Firefox with the provided sample code, in IE 11 all the grid items overl ...

Trouble arises when attempting to load a GLTF model in Next.js due to an error message stating, "Unable to load <url>. response.body.getReader is not

Seeking guidance on loading a GLTF model in next.js I have invested hours trying to figure this out with no success :( Here's what I've attempted so far: Experimented with different loaders (useLoader(GLTFLoader,url) / useGLTF(url)) Attempted ...

Please refrain from utilizing MUI - useGridRootProps outside of the DataGrid/DataGridPro component

When we click on "Filter" in the context menu of our DataGrid, we encounter this error. We are working on implementing a component hierarchy for the DataGrid as follows: MigrationJobTable.tsx: return ( <div data-testid='migrationJobTa ...

How come my image is not aligned to the right of the header in my HTML code?

My attempt to align an image to the right side of my heading using code was unsuccessful. Here is the HTML snippet I used: /* Aligning with CSS */ #colorlib-logo img { display: flex; align-items: center; width: 30px; height: 30px; } #colorli ...

Submenu fails to remain expanded

Having a minor issue with my dropdown menu. Whenever I hover over a link, the submenu pops out briefly but doesn't remain open. The issue seems to be related to the "content" div element, as removing it makes the menu functional. However, I can&apo ...

React functional component fails to update upon form submission

I am currently working on developing a functional component using Redux hooks that allows the user to edit a note. Everything appears to be functioning correctly, but when I submit the form with changes, it reloads itself without any updates being made. It ...

Guide to customizing the appearance of a component's host element on-the-fly

For instance: https://stackblitz.com/edit/angular-mkcfsd In my project, I have an icon component called app-icon which dynamically takes a path and inserts it into an SVG viewbox. I extract the height and width of the path, then set the SVG to match those ...

Unable to locate React npm package

I'm facing a seemingly simple issue that I just can't seem to solve. I am using React and webpack, and I've recently installed a new package (braintree-web-drop-in). However, whenever I import it into my React module and try to log it out, i ...

Is there a way to horizontally navigate a pallet using Next and Prev buttons?

As someone new to development, I am looking for a way to scroll my question pallet up and down based on the question number when I click next and previous buttons. In my pallet div, there are over 200 questions which are dynamically generated. However, th ...

The JSON file containing API data is stored within the _next folder, making it easily accessible to anyone without the need for security measures or a login in the Next

When accessing the protected user Listing page, we utilize SSR to call the api and retrieve all user records which are then rendered. However, if one were to check the Network tab in Chrome or Firefox, a JSON file containing all user data is generated and ...

PHP is failing to redirect the user to the correct index.php file

I encountered an issue in Jquery Mobile that has left me puzzled. Upon entering the site, users are prompted to either register or login. When selecting register, they are redirected to a page where they input their information. Once completed, the data is ...

Issue: ParserError encountered due to a Syntax Error found at line 1, column 32

As a beginner in programming, I am encountering an issue. When I run "npm run build" in the Terminal to compress my project in React.js, I encounter this error. Interestingly, I have previously created another project without facing this problem, and I can ...

What steps can be followed to create functionality for having three pop-up boxes appear from just one?

I have implemented code that triggers pop-up boxes at the bottom of the screen when a user clicks on a name from a list displayed on the top right corner of the screen. <!doctype html> <html> <head> <title>Facebook Style Popu ...

Tips on modifying webpage content based on page size (zoom) in responsive web design using CSS

I have a good understanding of responsive design and how to set elements with relative width. My specific question is regarding the transition of the page from thisto that. Any insight on this would be greatly appreciated. Thank you in advance. ...

Triggering a loop error may occur when attempting to update the state based on a

What I want to achieve is updating the state with the value received from a child component. However, whenever I try using the setstate method in my function, it results in a looping error. Here's a snippet of my code: class ParentTab extends Compone ...

Positioning of a paper-dialog in Polymer

I'm currently utilizing polymer's paper-dialog element in my application. While the dialog is always centered by default, I am looking to establish a minimum distance between the dialog and the right side of the window. This way, as the window re ...

After developing my React application, I made modifications to two files within it. However, upon attempting to load the app on the browser, an

This is the error message displayed on the browser I recently created my first app and made some changes to a couple of files to understand how it all works. However, now I keep encountering a common error "enoent" on the browser... I have tried troublesh ...

Encountered a lower number of hooks than anticipated while utilizing a react-redux translate function

Whenever I use the code below, a message saying Rendered fewer hooks than expected. This may be caused by an accidental early return statement. pops up: {headRows // Filter table columns based on user selected input .filter(item => displayedCol ...

Having some trouble with my React and MUI project - the button animation isn't functioning as expected when clicked

After implementing a Button from MUIv5, I noticed that the full animation only triggers when I hold down the button instead of with a simple click. Is there a way to fix this so that the animation fully plays with just a single click? Any help is apprecia ...

Learn how to customize the global style within a child component in Angular and restrict the changes to only affect that specific component

I have applied some custom css styling in my global style.css file (src/style.css) for my Angular project. However, I encountered a problem when trying to override this styling in a specific component without affecting the rest of the project. Currently, I ...