Transform your table into an ASCII-art masterpiece using CSS styling techniques

My vision is to style a table "ASCII art" using CSS, like the example below:

+------+---------+----+
| Jill | Smith   | 50 |
+------+---------+----+
| Eve  | Jackson | 94 |
+------+---------+----+
| John | Doe     | 80 |
+------+---------+----+

<table>
 <tr>
    <td>Jill</td>
    <td>Smith</td> 
    <td>50</td>
  </tr>
  <tr>
    <td>Eve</td>
    <td>Jackson</td> 
    <td>94</td>
  </tr>
</table>

If you're interested in creating tables like this, you can visit this table generator: Format Text As Table

If possible, I want to achieve this style using pure CSS without hardcoding any border characters.


My Experimentation

I attempted to use border-image but the outcome wasn't quite what I expected:

This is my CSS code:

* {
    font-family: "Ubuntu Mono";
    size: 10px;
    padding: 0;
    margin: 0;
}
table {
    border-spacing: 0;
    border-width: 8px;
    border-image: url("border.png") 16 8 round;
}

border.png:

The Result:

As clearly seen, the top and bottom borders are not visible. Moreover, there are no lines between the cells displayed.

When using border-width: 16px:

Now, the top and bottom borders are shown, however, the left and right borders are stretched.

Another downside of my approach is that the image does not adapt properly to changes in font size.

Answer №1

Looking for a creative CSS solution that utilizes pseudo elements? Here's how it works:

  • You'll need an extra element to ensure we have enough pseudo elements for single-row tables.
  • An image is necessary for the cell corners.
  • The image will be positioned at the top-left corner of all cells.
  • For cells in the bottom row and right column, the image will be positioned at the bottom-right corner.
  • The table itself will have the image at both the top-right and bottom-left corners.

Note: Please keep in mind that there might be a 1px discrepancy in Firefox.

.ascii-table {
    font: medium/1 monospace;
    margin: 1em;
    display: inline-block;
    position: relative;
}
.ascii-table table {
    border-collapse: collapse;
}
.ascii-table td {
    border: 1px dashed #000;
    padding: .5em;
    position: relative;
}
.ascii-table tr td:before {
    position: absolute;
    width: 15px;
    height: 15px;
    content: "";
    background-image: url(https://i.stack.imgur.com/2OGdZ.png);
    background-color: rgba(255, 127, 0, .4);
    top: -8px;
    left: -8px;
}
.ascii-table tr td:last-child:after, .ascii-table tr:last-child td:after {
    position: absolute;
    width: 15px;
    height: 15px;
    content: "";
    background-image: url(https://i.stack.imgur.com/2OGdZ.png);
    background-color: rgba(255, 63, 63, .4);
    bottom: -8px;
    right: -8px;
}
.ascii-table:before {
    position: absolute;
    width: 15px;
    height: 15px;
    content: "";
    background-image: url(https://i.stack.imgur.com/2OGdZ.png);
    background-color: rgba(255, 127, 0, .8);
    top: -7px;
    right: -7px;
}
.ascii-table:after {
    position: absolute;
    width: 15px;
    height: 15px;
    content: "";
    background-image: url(https://i.stack.imgur.com/2OGdZ.png);
    background-color: rgba(255, 63, 63, .8);
    bottom: -7px;
    left: -7px;
}
<div class="ascii-table">
    <table>
        <tr>
            <td>Jill</td><td>Smith</td><td>50</td>
        </tr>
    </table>
</div>
<div class="ascii-table">
    <table>
        <tr>
            <td>Jill</td><td>Smith</td><td>50</td>
        </tr>
        <tr>
            <td>Eve</td><td>Jackson</td><td>94</td>
        </tr>
    </table>
</div>
<div class="ascii-table">
    <table>
        <tr>
            <td>Jill</td><td>Smith</td><td>50</td>
        </tr>
        <tr>
            <td>Eve</td><td>Jackson</td><td>94</td>
        </tr>
        <tr>
            <td>John</td><td>Doe</td><td>75</td>
        </tr>
    </table>
</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

Implementing Material-UI’s FlatButton and Dialog in ReactJS for dynamic TableRow functionality

I am working with Material-UI and have implemented a <Table> component. Each dynamically rendered <TableRow> in the <TableBody> needs to include a button (<FlatButton>) within one of the columns. When this button is clicked, a <D ...

Utilize jQuery to serialize the HTML input elements that are dynamically generated outside of the form

A proof of concept is in progress for an application that involves the generation of HTML elements based on user-configured fields. Here is a sample configuration: // Customer SAM $response = array( array ( NAME => CUSTOMER, TYPE = ...

changing tooltip color in bootstrap based on the parent element

Is there a way to adjust the bootstrap tooltip background-color based on the container? For example, my header has a white background and my footer is black. #header .tooltip-inner{ background-color:fade(@grayWhite,80); } #footer .tooltip-inner{ backgro ...

Combine and blur multiple background images using CSS blending techniques

I am currently working on a website, which is just a demo built in ReactJS: The issue I'm facing is related to the background. The idea behind the app is simple - it consists of 4 parts, with the top part displaying weather information without a bac ...

What is the best way to distinguish a particular item in a <select> element and include a delete button for each row using jQuery?

1.) I've set up a nested table and now I want to ensure that when the 'Delete' button within the child table is clicked, its corresponding row gets deleted. 2.) I have a <select> tag. The issue is how can I implement validation to che ...

Which slider was featured in the unity3d.com/5 website?

While browsing the internet, I came across the website and was intrigued by the slider effect featured in the "graphics" section. I am eager to figure out how to replicate that stunning visual effect. ...

I am encountering difficulties with generating images on canvas within an Angular environment

I am trying to crop a part of a video that is being played after the user clicks on it. However, I am encountering the following error: ERROR DOMException: Failed to execute 'toDataURL' on 'HTMLCanvasElement': Tainted canvases may no ...

Switching the endpoint renders the middleware ineffective

I've encountered a puzzling issue with my NodeJs - Express server, which serves as the backend for my mobile application. The problem arises when I send post requests to certain endpoints like checkmail and checkusername using axios from the frontend ...

Adaptable HTML design with alignment features

Here is the structure I am working with: <style> #main { max-width: 500px; margin: 0 auto; overflow: hidden; border: 1px solid red; } #container{ margin-right: -50px; } .block{ display: inline-block; width: 100px; height: 100px; border: 1px solid gr ...

Stop header background image from loading on mobile browsers by utilizing the <picture> tag

Is there a method to utilize the <picture> element in order to prevent a page from downloading an image when viewed on a mobile phone? I have a website that features a header image. Unfortunately, due to the site's functionality, using CSS (bac ...

The process of updating a session using jQuery

Whenever a checkbox is selected, the session gets populated with an id. However, if another checkbox is selected afterwards, the session remains unchanged. This is my current code structure: <input type='checkbox' class='imei' id=&a ...

Problematic response design

On my responsive website, I am utilizing the hr tag in various places. However, I have noticed that some lines appear with different thicknesses, as shown in the example below. For a demonstration, you can view a sample on this fiddle: http://fiddle.jshel ...

Exploring the Differences in Site Navigation: PHP/HTML, Ajax, and CSS/Javascript

Lately, I've been weighing the pros and cons of using AJAX for my website navigation to transfer only necessary updated HTML elements. Alternatively, if there isn't a significant difference between new elements and current ones, just loading the ...

One approach to animating elements on a web page is by utilizing Node.js

Imagine you want to programmatically define animated movement for elements on a web page. In JavaScript, this can be achieved using techniques outlined in this helpful guide: How TO - JavaScript HTML Animations. But how would you do this in Node.js? UPDAT ...

Choose a dynamically generated html element without having to click on it

I've been looking for a way to target a dynamically-generated element (specifically a div with the class "date") using jQuery. While I keep finding references to the .on('click') method, it appears that this only selects the div once the pag ...

Tips for choosing an attribute within a list with a CSS selector and Selenium

Is it possible to use a css selector to target an element within a <li> using Selenium? Below is the code snippet in question: <div id= "popup"> <ul> <li> <div id="item" option= "1" ....> </div> < ...

I am experiencing difficulty with the Click() operation in Selenium web driver as it is not successfully redirecting me to another page

Hello everyone, I could really use your assistance with a problem I'm facing. WebElement wb=driver.findElement(By.name("NavHeader1$tabs$ctl00$btnNavHeaderTab")); Actions act=new Actions(driver); act.moveToElement(wb).perform(); ...

Adjustment of Facebook button positioning in floating bar on Firefox

My floating bar currently has 5 social buttons, but I've noticed that the Facebook button is shifting about 20 pixels to the left. Could this be an issue with the CSS elements? After inspecting the elements, I found that when I remove position: absol ...

Direct jQuery to redirect to a new page and reveal a hidden div

I am facing a situation where I have two web pages named index and results. The results.html page contains some hidden divs with the CSS property set to display: none. My goal is to navigate from the index page using a navigation menu and open the results ...

Tips for matching the width of tooltips with the length of the title

I am trying to adjust the width of the antd tooltip to match that of the title. Here is the code snippet: <Tooltip placement="top" align={{ offset: [0, 10] }} title='this is the title'> <span>tooltip</span> </T ...