Maintain the original alignment of table cells <td> even when the <tbody> element is set to display:block

I've been working on creating a theme for SMF, but I'm encountering some challenges with the tables. Here's an example of my HTML code:

<div id="wrapper">
    <table class="table_list">
        <tbody class="header">
            <tr>
                <td colspan="4">
                    <h3>TESTING</h3>
                <td>
            </tr>
        </tbody>

        <tbody class="content">
            <tr class="window">
                <td class="as">
                    <a href="">12</a>
                <td>
                <td class="bs">
                    <a href="">23</a>
                <td>
                <td class="cs">
                    <a href="">34</a>
                <td>
                <td class="ds">
                    <a href="">45</a>
                <td>
            </tr>
        </tbody>
    </table>
</div>

Here is the CSS associated with it:

#wrapper {
width:500px;
margin:0 auto;
}
* 
{
    margin: 0;
    padding: 0;
    border-spacing: 0px;
    border-collapse: separate;
}
table.table_list {
    background:#16A085;
    width:100%;
}
tbody.header {background:#2980B9}
tbody.content {
    display:block;
}
td.as {background:#E74C3C}
td.bs {background:#8E44AD}
td.cs {background:#E74C3C}
td.ds {background:#8E44AD}

I noticed that changing the display property to block in the CSS causes the cells to behave like inline elements instead of remaining in their cell positions within the table. I must be missing something here.

p.s. I need the display property set to block in order to style it and add rounded borders.

JS Fiddle Link

Answer №1

To begin with, make sure to properly close your HTML tags.

Additionally, by altering the display type of the table body, you are impacting how the browser calculates cell widths. To address this issue, consider setting explicit widths:

tr {
    display:block;
    width:100%;
    clear:left;
}
td {
    float:left;
    width:25%;
    box-sizing:border-box;
}

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

Is it possible to hide a fixed header on scroll in a mobile device?

I am facing an issue with my Wordpress site where I want the header to hide when the user scrolls. Despite trying various codes, I have been unable to make it work. The reason for wanting to hide the header is that on mobile devices, it causes scroll prob ...

Updating the ghost image for HTML5 drag and drop functionality

I am facing an issue with a large div element that is too big for my liking. I have come up with a solution to change it by implementing the following code: <div draggable = "true" id = "ololo"> </div> var k = document.getElementById("ololo"); ...

Verify if there is a value in at least one of the multiple input fields

I have 4 input fields and I need to check if at least one of them has a value. If none of them are filled out, I want the function to stop. Below is the current code snippet I'm using but it's not working as expected because it doesn't ente ...

Design a grid-like layout using flexbox styling

I am looking to design a form using a table-like structure similar to what we typically do with HTML. The image below shows the basic layout I am aiming for: https://i.sstatic.net/H6b3f.png. Can anyone provide guidance on how to code this type of structu ...

Is there a way to showcase CSS styling for elements that are "siblings" when hovering over an item without affecting the item being hovered on?

When hovering over one of the 5 text bits, I want to apply CSS to all bits except the one being hovered over. Can you achieve this using jQuery and the .siblings() attribute? Here is the HTML: <table width="1138" height="38" border="0" class="Home111 ...

Customizing Material-UI styles using makeStyles

Currently, I am in the process of building a small portfolio website. Despite my attempts to style an avatar using the makeStyles class, it seems that the Mui avatar root is overriding my desired styling. I am wondering if there is a way to achieve this w ...

Enhance your webpage design with stylish CSS formatting using Bulma cards

My HTML output is as follows: https://i.stack.imgur.com/aBdEF.jpg It seems that the footer is not matching up with the cards... The CSS component I am using looks like this: .card-equal-height { display: flex; flex-direction: column; height: 100%; ...

What is the most efficient way to convert an entire HTML page into a different language using Django?

As I work on building a website with Django framework, I am faced with the task of translating my web page into French while keeping all other pages in English. <html lang="fr"> Despite setting the code as shown above, I am encountering issues wher ...

Enable vertical scrolling on the second row of a table while keeping the first row fixed as the table header (CSS)

While embedding the Ace Editor in a Chrome popup window, I encountered a challenge. My goal was to keep the first row of text always visible at the top while allowing the rest of the Editor to fill the screen. However, there is an issue with a vertical scr ...

I am experiencing some trouble with configuring the CoreUI Admin Template

I've encountered an issue where I've tried various methods to implement this theme but haven't had any success. 1. I followed the steps in the documentation by cloning the repo of the template and then using npm install (npm run serve) -> ...

Should we consider using extra url query parameters as a legitimate method to avoid caching or enforce the updating of css/js files?

Is it acceptable to include extra URL query parameters in order to avoid caching or enforce the updating of CSS/JS files? /style.css?v=1 Or would it be preferable to rename the file/directory instead? /style.1.css I've heard that this could potent ...

Is it possible to apply a consistent character width to all glyphs, even the most obscure Unicode symbols, using CSS?

Is it possible to style a single character within a span element to have a specific width and height of 1em? Ideally, I would like the character to be stretched if it is not already fixed-width. This styling must support any character, including rare Unic ...

Raphael JS Path Animation: Wiping Away

I have successfully created a line animation using RaphaelJS, which can be viewed on this jsfiddle link - http://jsfiddle.net/7n040zdu/. My next challenge is to create an erasing animation that follows the initial one. This erasing animation should mimic t ...

The function $.ajax may not be available, but rest assured that the jquery library is functioning properly

Upon checking the console, I noticed the following: Here is the AJAX code snippet in use: $("#accept").click(function(){ id = $("#idInput").val(); password = $("#passwordInput").val(); alert(id) alert(password) $.aja ...

The function cannot be applied to d[h] due to a TypeError

Having some trouble with my code here. I'm trying to set up routes to display a gif using CSS animation when the page is loading. The gif shows up initially, but then everything fades out and the gif remains on the page. Additionally, I'm getting ...

Obtain the radio button value along with the values of all other input fields

$('.cinput').each(function(){ console.log($(this).val()); }); <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input type='radio' name='radiox' class='cinput' v ...

Hover effect alters background color

I've successfully created a box around text, but now I want it to change color when hovered over. However, I'm facing difficulty in achieving this effect. An image has also been attached for reference. Please review the image and locate the socia ...

Changing the absolute layout to utilize floats

I am seeking guidance on a project I am currently working on and would greatly appreciate any help. Main Goal: The objective is to create a drag and drop CMS that allows users to draw elements on a grid and rearrange them as needed. The system will recor ...

Converting multi-dimensional array into a structured table format

Query about arrays: Here is the array structure I am working with: Array ( [0] => Array ( [0] => Project [1] => Time ) [1] => Array ( [0] => Google [1] => 2 ...

Animation in CSS/transform drifting out of view

I have a challenge with animating text to each corner of the screen, where the text is rotated in every corner. However, I am facing an issue where the text goes off-screen in the top right and bottom left corners. It seems like the rotation might be causi ...