Steps for constructing a customized table

I'm not entirely sure if I explained that clearly, so here's another attempt:

My goal is to create a table where each alternating row has border radius applied to the top sides, filling the space created by the border radius with the color of the previous row. Here is the CSS code I am using:

table {
  background-color: grey;
  border-radius: 10px 10px 0px 0px; 
  border-spacing: 0;
}

td, th{
  height: 28px;
}

table th{
  background-color: blue;    
}

table tr th:first-child {
  border-radius: 10px 0px 0px 0px;
}

table tr th:last-child {
  border-radius: 0px 10px 0px 0px;
}

table tr td:first-child {
  width: 200px;
}

table tr:nth-child(odd) {
  background-image: url("http://i.imgur.com/WOF6Nqu.png");
  background-repeat: no-repeat;
  padding-top: 10px;
  margin-top: -10px;
}

table tr:nth-child(even) {
  background-image: url("http://i.imgur.com/BLcmMtw.png");
  background-repeat: no-repeat;
}

table td:nth-child(1),
table td:nth-child(2),
table th:nth-child(1),
table th:nth-child(2) {
  border-right: 2px solid white;
}

Answer №1

(Optimized for Firefox browser)

To achieve a table layout with alternating row colors, set the background-color for each table cell and then apply the same color to cells in every other row. View an example implementation here:

https://jsfiddle.net/svArtist/20rhemuf/

(Some adjustments may be required for your header section)

td:first-child, th:first-child {
    border-radius: 10px 0 0 0;
}
td:last-child, th:last-child {
    border-radius: 0 10px 0 0;
}

/* Set the colors below */
table tr:nth-child(odd) {
    background-color: #bbb;
}
table tr:nth-child(even) {
    background-color: #ABDBEA;
}
table tr:nth-child(even) td {
    background-color: #bbb;
}
table tr:nth-child(odd) td {
    background-color: #ABDBEA;
}

/* Header fixes */
table tr:first-child {
    background-color: transparent;
}
table tr:nth-child(2) {
    background-color: blue;
}

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

Unlocking the Interactive Potential of CSS Across All Screen Formats

I am currently working on transforming my website into an engaging and interactive platform. My first challenge: The alignment of the logo image does not meet my desired specifications. Whenever the screen width exceeds 1200 pixels, there seems to be exc ...

Utilize jQuery to display or toggle each element individually, ensuring that only one is visible on the screen at any given time

Here are some clickable links: About Portfolio Resume Upon clicking 'About', I want the About section to appear while hiding the Portfolio and Resume sections (and vice versa)... This is how my code is structured (relevant parts only): HTML: ...

Issue with Safari browser: Circular div not displaying shadow as intended

I am facing an issue with a div element that has the following CSS styling close: { position: 'fixed', boxShadow: '1px 1px 6px 0px rgba(0,0,0,0.5)', borderRadius: '50%' } This styling behaves as ex ...

Is it possible for IE7/8 to show position:relative elements in front of position:absolute ones?

The layout I have created utilizes absolute positioning and includes a CSS-based menu in the header section. It functions perfectly in Firefox, however, when viewed in Internet Explorer 7 and 8, the menu dropdowns are hidden by the content area. Unfortunat ...

How to style font display in PHP Select Menu with two different font sizes

Here is the code for my dropdown menu. I'm trying to figure out how to make the text inside the option value have a smaller font size. I attempted using a span tag to adjust the font size, but it didn't work as expected. <select name="met ...

What is the best way to showcase specific information from a JSON file with the help of

Our corporation is looking to showcase job listings that we promote on a prominent job platform. They provide us with JSON data so we can exhibit our company's job openings on our website. I aim to present essential information in a summary format, w ...

Produced inputs and preset values

I have a question regarding the use of generated input elements in my App's form. I want to keep it as simple as possible, which is why I am using native form reset for these elements. It appears that the 'default value' becomes bound to th ...

Stop the browser from automatically loading a file that is dragged and dropped into it

I've implemented an HTML5 drag and drop uploader on my webpage. It functions perfectly when a file is dropped into the designated upload area. Unfortunately, if I mistakenly drop the file outside of that area, the browser treats it as a new page loa ...

Limiting the use of CSS selectors to a single class without the need to include the class name multiple

I am trying to find a solution to avoid repeating the same class name multiple times in CSS. For instance, if I have: .class1 div { color: red } .class1 h2 { color: blue } .class1 p { color: yellow } Is there a way to consolidate these three rules under ...

Delay the page briefly before redirecting

I want to implement a feature on my WordPress website where after successfully submitting a form, the visitor is shown a message like 'form submitted successfully' for a few seconds before being redirected back to the page they were on. The redir ...

Animations in Angular fail to operate within mat-tabs after switching back when custom components are being utilized

I am facing a similar issue as Olafvv with my angular 16 project. The problem occurs in a mat-tab-group where the :enter animations do not work when navigating away from a tab and then returning to it. However, in my case, the issue lies within a custom su ...

Tips for hiding a div only on mobile devices while always displaying it on large screens using AngularJS or CSS

How can I use Angularjs or css to hide a div on mobile devices only, ensuring that it is always displayed on large screens? ...

Transform HTML table data into XML format

My challenge is to transform an HTML table into XML format using pure JavaScript without the use of jQuery or any other libraries. I have found plenty of tutorials on converting XML to HTML, but none on how to go in the opposite direction without resorting ...

Tips for sending text back to a <span> element in a .cshtml file from a C# ASP.NET controller

I have a question that I've been pondering on and haven't found an answer to yet. Is it possible for my Login Controller to display text in a span on the Login view if one of its if statements fail? For example, if this condition fails during t ...

Browsing using the "touchmove" feature feels extremely laggy

I implemented a workaround to achieve "position:fixed" on mobile devices, specifically my Android device. This involved creating two divs with heights that combined to match the screen height through JavaScript, and adding touch listeners to the bottom div ...

Variations in CSS display across various browsers

I'm currently facing an issue while learning web development. The expected result only appears when I preview my website on an old version of Internet Explorer, but it doesn't show up correctly when opened on Firefox or Chrome. The code I have i ...

What is the best way to incorporate a rectangle or arrow into my canvas design?

Looking for a way to enhance my html canvas wind direction code, here is how it currently looks: var x, y, r, ctx, radians; ctx = window.compass.getContext("2d"); radians = 0.0174533 * (10 - 90); x = ctx.canvas.width / 2; y = ctx.canvas.height / ...

How can I prevent Bootstrap from conflicting with my custom styles?

My HTML menu was functioning perfectly with specific CSS styles, until I decided to add a Bootstrap reference in the header: New Link Added <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" /> Afte ...

Choosing dropdown options without the <Select> tag in Selenium with Python

Looking to choose a date from the URL highlighted in yellow below: https://i.sstatic.net/UIBLJ.jpg Upon inspecting the HTML code, I couldn't locate any "select" tag as shown: https://i.sstatic.net/fhaaU.jpg Snippet of my code: chrome_options ...

I am having trouble placing the button within the image

Essentially, my goal is to place the button within the image and ensure it remains in its position when transitioning to mobile mode or adjusting window size. This is the desired outcome: https://example.com/image https://example.com/button-image .img ...