Add two cells below a header with a colspan of one

I've been having trouble grouping the cells with the values { Lazy, Dog, Then, It } under a single header (with a colspan of 1)

So far, I've attempted using div tags within the cells, creating multiple cells, and trying various combinations of widths and colspans.

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

Although I managed to stack Lazy and Dog under the header using div tags and CSS, they aren't treated as individual cells.

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

    <html>
<head>
<style>

        table,td,tr,th{
            border: 1px solid black;
            }


            .lazy {
            float: left;
            width: 50%;
            }

            .dog {
            float: right;
            width: 50%;
            }
</style>
</head>
<body>
<table>
            <tr>
                <th>Quick</th>
                <th>brown fox</th>
                <th>jumps</th>

            </tr>

            <tr>
                <td rowspan=3>over the</td>
                <td><div class="lazy">lazy</div> <div class="dog">dog</div></td>
                <td>and</td>
            </tr>

            <tr>
                <td>then</td>
                <td>it</td>
                <td>fall</td>
            </tr>

            <tr>
                <td colspan=2> prey to a lion </td>
            </tr>

</table>
</body>
</html>

I appreciate any insights or suggestions. Thank you!

Answer №1

Add the attribute colspan="2" to the <th>brown fox</th> element.

There is no need to nest a <div> inside a <td> to separate data.

Next, modify your

<td colspan=2> prey to a lion </td>
to
<td colspan="3"> prey to a lion </td>
.

Check out the following live example, I hope it makes it easier for you to understand:

https://jsfiddle.net/ABcd1234/2/

Answer №2

Simple like a slice of pie, here is the code snippet:

        table, td, tr, th {
            border: 1px solid black;
        }


        .lazy {
            float: left;
            width: 50%;
        }

        .dog {
            float: right;
            width: 50%;
        }
    
<table>
        <tr>
            <th>Quick</th>
            <th colspan="2">brown fox</th>
            <th>jumps</th>

        </tr>

        <tr>
            <td rowspan=3>over the</td>
            <td>lazy</td> 
            <td>dog</td>
            <td>and</td>
        </tr>

        <tr>
            <td>then</td>
            <td>it</td>
            <td>fall</td>
        </tr>

        <tr>
            <td colspan=3> prey to a lion </td>
        </tr>

    </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

The start screen fails to display when clicking the restart button

I am struggling to get the restart button to display the start screen again. Even though I have called the restart function within the clearColors function, which should show the start screen, it hasn't been effective so far. Initially, in the fadeOut ...

Is there a way to bring to life the addClass() and removeClass() jQuery functions through animation?

I am currently developing a website and I want to be able to toggle the visibility of sections by using the ".hidden" bootstrap class within click events. Here is the basic code snippet: $('selector').click(function(){ $('*part-to-hi ...

How can PHP be utilized to dynamically add classes to <li> elements and alternate them after every third item

I'm trying to find a way to add a class to an unordered list and alternate that class after every third item. Here's the code I have so far: <?php $i=1; foreach($this->items as $item) : ?> <li class="<?php if ($i % 3 == 0) : ...

Optimizing HTML/CSS performance: Comparing flexbox and tables for handling extensive datasets

Creating a React table component with hundreds of lines and variable cell widths can be complex. Would it be better to implement this using flexbox or a traditional table structure in HTML/CSS? ...

The addition of input fields on keyup creates problems in the initial field of each row

I am currently working with a table and attempting to calculate the sums as follows: td(1) + td(2) + td(3) = td(4), td(5) + td(6) + td(7) = td(8), td(9) + td(10) + td(11) = td(12). This is the code I have implemented: $(document).ready(function () { ...

When multiple input fields with an iterative design are using the same onChange() function, the specific event.target.values for each input

I'm in the process of developing a dynamic select button that adjusts based on the information entered into the iterative input fields I've set up. These input fields all utilize the same onChange() function. for (let i = 0; i < selectCount; i ...

There appears to be a gap on the right side of the <span> element, resembling an additional space at the end

While testing a button on my website, I noticed that all the spans have an extra space at the end. Adding a background box made this gap very noticeable. Upon further inspection of my other pages, I realized that the issue exists there too. I have not made ...

Vanished were the empty voids within our

It seems that the spaces between words have mysteriously vanished in a font I am currently using. Take a look at this website: I am utilizing a slightly modified Twitter Bootstrap with Google Web fonts, and the font causing the issue is Oswald from Googl ...

Refresh in AJAX, automated loading for seamless transition to a different page

Having an issue with the page not auto-refreshing, although it loads when I manually refresh. P.S Loading the page onto another page. Below is my HTML and AJAX code along with its database: The Trigger Button <?php $data = mysqli_query ...

Disappearing CSS Box Shadows

I'm attempting to replicate effect number 2 from a website I found, but I'm running into an issue. Whenever I add more HTML content to the page, the effect disappears. Here is a sample of what I have so far: http://jsfiddle.net/aHrB7/ Here is a ...

How to style a sublevel menu to appear next to its parent using CSS

I have a menu that is currently functioning well, but I would like to add a new sublevel onto it. However, if I directly add the new options, they end up hiding the existing ones on the menu. Here's an image for reference: I want the new options to ...

Angular application featuring scrolling buttons

[Apologies for any language errors] I need to create a scrollable view with scroll buttons, similar to the image below: Specifications: If the list overflows, display right/left buttons. Hide the scroll buttons if there is no overflow. Disable the le ...

Multiple columns contained within a span

I'm trying to create a panel that displays a list of values with corresponding labels. The requirement is for each label to be positioned above its respective value and aligned to the left. The layout should resemble the following: Label 1 Lab ...

Swift: NSAttributeString generates unexpected HTML output

I attempted to use NSAttributeString to parse HTML, but encountered a problem when trying to display a table within a list item. <ol> <li>first <table> <tbody> <tr> ...

Are there alternative methods to retrieve the CSS properties of web elements more effectively than relying on selenium?

I have a situation in my code where I need to retrieve the CSS properties of a large number of web elements. Currently, I am using Selenium and the code looks like this: ... node = browser.find_element_by_xpath(xpath_to_node) return {k: node.v ...

jQuery: Remove the class if it exists, and then assign it to a different element. The power of jQuery

Currently, I am working on a video section that is designed in an accordion style. My main goal right now is to check if a class exists when a user clicks on a specific element. The requirement for this project is to allow only one section to be open at a ...

Issue with content overlapping when hamburger icon is tapped on mobile device

When the hamburger menu is pressed on smaller screens, I want my navbar to cover the entire screen. To achieve this, I included the .push class in my code (see the jQuery and CSS) to trigger when the .navbar-toggle-icon is pushed. However, after implemen ...

Switching images with jQuery on a click event

Can anyone provide suggestions on how to swap images with the header image when icons in the footer are clicked? Here is a demonstration on Jsfiddle <ul> <li> <a href="#"> <img src="img/q.jpg&quo ...

What is the mechanism behind the functioning of "3D Meninas" (CSS/Animation)?

Recently stumbled upon a fascinating website called "3D Meninas", showcasing an impressive 3D animation effect. Upon examining the HTML code, I noticed there was no mention of any <script> tags or events, leading me to believe that it operates solely ...

Ensuring uniform height of columns in Bootstrap

I want all columns following the first row with col-md-6 to have equal height, regardless of dynamic content (go to full page). <html> <head> <title>Page Title</title> <meta charset="utf-8"> <meta name="viewport" ...