Ways to create diagonal or vertical table breaks using CSS

If you have a <table> that is very tall or wide and you want it to wrap for screen display, how can this be achieved using CSS?

For example, a table that is 300% page height and 30% page width would be divided into three parts.

#
#
# 
# 
# 
# 

becoming

# # #
# # #

I am seeking a purely CSS-based solution, is this feasible?

Edit: HTML Sample

<table>
    <thead>
        <tr>
            <th>Foo</th>
            <th>Bar</th>
            <th>Baz</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>6</td>
            <td>1</td>
            <td>5</td>
        </tr>
        <tr>
            <td>42</td>
            <td>5</td>
            <td>34</td>
        </tr>
        [snip 100 lines]
        <tr>
            <td>4</td>
            <td>0</td>
            <td>3</td>
        </tr>
    </tbody>
</table>

Answer №1

Here is an example of how you can achieve a similar effect:

td {
    border: 1px dashed #f0f;
    float: left
}

This code will be compatible with IE8 and newer versions, as well as all modern browsers. However, it may not work properly in IE7.

Check out: http://jsfiddle.net/abc123/
or with a specified width: http://jsfiddle.net/abc123/1/

Answer №2

It's not possible to achieve this layout using a table. The best approach would be to divide the content into three separate tables and then redesign the page accordingly.

CSS does offer a feature called columns, which enables block elements to be displayed in multiple columns resembling newspaper columns. However, this feature is not compatible with table content and has limited browser support at the moment (not supported in IE9; vendor prefixes required for other browsers). Therefore, it may not be suitable for widespread use yet.

If you're interested in learning more about this feature, Quirksmode provides a comprehensive guide on its implementation:

You can also check the current browser support status for this feature on CanIUse: http://caniuse.com/#search=columns

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

Achieve consistent heights for divs within table cells without the use of JavaScript

Is it possible to make two divs contained in table cells in a shared row both have the height of the taller div without using JavaScript? Take a look at this simplified example here: http://jsfiddle.net/Lem53dn7/1/ Check out the code snippet from the fidd ...

What is the best way to animate an element when it comes into the user's view

In order to activate the animation of the skill-bars when the element is displayed on the website, I am seeking a solution where scrolling down through the section triggers the animation. Although I have managed to conceptualize and implement the idea with ...

CSS3 alternative to width:calc(100% - 10px)

Currently, I am in need of an alternative solution for migrating my CSS file since some CSS3 features are not being rendered properly on QtWebKit yet. The CSS code that I am working with is as follows: .fit { width: -moz-calc(100% - 10px); width: ...

Floating action button within a collapsible panel

I am having trouble placing a fixed-action-btn inside a collapsible body. It keeps appearing in the bottom right corner of the page instead of within the collapsible itself. How can I ensure that the button stays inside the body? Check out this link for r ...

What is the best way to define file paths in a webpage to ensure that the same file works seamlessly on both server and

Currently, I am working on developing a website locally with the intention of later transferring it via FTP to my server. In my index.php file, there is a line that reads: <?php include($_SERVER['DOCUMENT_ROOT'] . "/includes/header.php");?&g ...

Center and justify image inside flexbox using MUI

Can someone explain why my image appears centered but not justified? I'm feeling confused about this. <Box sx={{ display: 'flex', minHeight: '100vh', alignItems: 'center', flexGrow ...

When using jQuery to select elements of a specific class, make sure to exclude the element that triggered the

A dynamic number of divs are generated from a data source. Each div contains an image button and another div with text. While the actual scenario is more complex, we can present a simplified version: <div id="main"> <div id="content_block_1" ...

Attempting to establish a discussion board using MVC 5 on the ASP.NET platform

I'm currently facing a challenge while attempting to build a simple forum using ASP.NET MVC 5. Specifically, I am encountering an error message stating "The INSERT statement conflicted with the FOREIGN KEY constraint." Below, you can find the code sni ...

What is the reason behind causing the overflow to become visible on the parent anchor when a child anchor is added?

I've been facing a puzzling issue for the past day. I am working on creating a website that resembles Windows 8, where each box represents a list item. The code is more complex than what I have shared here, but the problem seems to be isolated... &l ...

Pass a JavaScript variable to a PHP script using AJAX when a button is clicked, with a dynamically set href attribute

This is the current situation: There is a checkbox on each row of a table that represents some information An initially disabled button becomes enabled when any checkbox is checked The button is enclosed by an <a></a> tag as shown: <a>&l ...

Pass a data variable to an HTML file using express's sendfile function (quick inquiry)

Currently utilizing Node.JS, path, and express for running an HTML webpage. I need to pass a variable to the HTML file for its utilization: var client_cred_access_token = 'fakeToken'; ... app.get('/', function (req, res) { res.se ...

Incorporating photos within the layout of a Twitter Bootstrap grid

Looking to showcase images like the ones found here: https://i.stack.imgur.com/eD4GD.jpg These images are original and come in various sizes. I want a hover effect that includes blur, fogging effects, and text placed in the middle of the picture. Check ou ...

What is the best way to apply styling exclusively to a child component?

I am currently working on a coding project that involves a parent component and multiple child components. My main goal is to adjust the position of a filter icon by moving it down 5 pixels on one specific child component. The issue I am facing is that no ...

I believe I am attempting to add some space to a row using CSS, or at least that's what I think I'm trying to achieve

Hey there, I need some help with adding an icon "services" section to my website. CSS is not my strongest suit, so I'm reaching out for assistance. My goal is to create blocks for the icons that don't touch the edge of the page and have a margin ...

Tips for evaluating style modifications on mouseover using cypress

Trying to test hover styles on table rows but encountering issues: Here is the code snippet I am testing: it("Table rows should display correct hover styles", () => { cy.get("table>tbody>tr").each(($el, index, $list) =&g ...

Tips for maintaining video height consistency while adjusting its attributes

When you click on a button, the video's poster and src attributes change. However, after clicking, the video height briefly becomes 0, causing an unsightly effect on the entire page. How can this be avoided? Please note - lorem.mp4 and ipsum.mp4 hav ...

"Utilizing a hidden overflow combined with border-radius and translate3d for a

Is there a way to keep the corners of a block hidden when it has both overflow set to hidden and border radius applied while being translated? HTML <div class="scroller"> <div class="scroller-content"></div> </div> CSS .s ...

Hover over to disable inline styling and restore default appearance

There are some unique elements (.worker) with inline styles that are dynamically generated through Perl. I want to change the background when hovering over them and then revert back to the original Perl-generated style. The only way to override the inline ...

What impact does the order of the element I'm specifying in my .css file have on its appearance after being rendered?

(An update has been added below) In my project, I am working with a .css file and an index.html document. The goal is to create a panel of buttons on the screen [to prototype the usability of a touchscreen interface], with each button assigned a specific ...

What is the best way to prevent the content within a div from being obscured by a sticky element affixed to the bottom of the div?

I am struggling with ensuring that the content in my wrapper does not get cut off by the "view more" div attached to the bottom. The default wrapper cuts off the children, and even when expanded, the issue persists due to CSS problems. In React, the gener ...