What is the best way to create an adaptive <pre> tag for ASCII art without using media queries?

Currently, my username is displayed as an ASCII art banner/header and I am looking to enhance its responsiveness. Instead of relying solely on media queries, I am exploring the possibility of making it scale within a CSS grid container. This approach would not only reduce code bloat but also make maintenance easier.

Here are the methods I have experimented with:
  • width using min(), max(), clamp(), and calc() functions incorporating various values of vw and vh.
  • width with just a value in vw, based on suggestions from other sources.
  • font-size with percentages in min(), max(), clamp(), and calc() functions.
  • white-space: pre-wrap;
  • white-space: pre-line;
  • word-wrap: break-word;

white-space: pre-wrap; and white-space: pre-line; somewhat work but they disrupt the appearance of the ASCII art.

Despite trying these approaches, I have been unable to achieve proper scaling for my username.

Below is my current code snippet:

body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 7.25rem auto 5rem;
  grid-template-areas: "header header" "main sidebar" "footer footer";
  min-height: 100vh;
}

header {
  grid-area: header;
}

header pre {
  display: grid;
  justify-content: center;
  align-content: center;
  text-align: center;
  font-size: 70%;
}

@media only screen and (max-device-width: 700px) {
  body {
    grid-template-rows: 6rem auto 5rem;
  }
  header {
    font-size: 55%;
  }
}
<header>
  <pre>
 ___       __    ________   ___    _________   ________   _____ ______    ________   _______    ________      
|\  \     |\  \ |\   __  \ |\  \  |\___   ___\|\   __  \ |\   _ \  _   \ |\   ____\ |\  ___ \  |\   ___  \    
\ \  \    \ \  \\ \  \|\  \\ \  \ \|___ \  \_|\ \  \|\  \\ \  \\\__\ \  \\ \  \___|_\ \   __/| \ \  \\ \  \   
 \ \  \  __\ \  \\ \   __  \\ \  \     \ \  \  \ \  \\\  \\ \  \\|__| \  \\ \_____  \\ \  \_|/__\ \  \\ \  \  
  \ \  \|\__\_\  \\ \  \ \  \\ \  \____ \ \  \  \ \  \\\  \\ \  \    \ \  \\|____|\  \\ \  \_|\ \\ \  \\ \  \ 
   \ \____________\\ \__\ \__\\ \_______\\ \__\  \ \_______\\ \__\    \ \__\ ____\_\  \\ \_______\\ \__\\ \__\
    \|____________| \|__|\|__ \|_______| \|__|   \|_______ \|__|     \|__||\_________\\|_______| \|__| \|__|
                                                                            \|_________                              
  </pre>
</header>

I have implemented two additional media queries to improve mobile-friendliness and adjusted the font size of the header to scale accordingly. However, I am interested in exploring whether the header grid container/box can enforce scaling constraints on the ASCII art tag as the screen size decreases.

Thank you for taking the time to review my query!

Answer №1

Here are the revisions I implemented! All remaining code remains unchanged.

Initial solution: Functioning well but application of scaling is overly aggressive.
header pre {
 font-size: 0.5vw;
}
Second solution addresses the scaling concern, although not meeting desired outcome completely.
header pre {
 font-size: max(0.5vw, 0.25rem);
}
The third and most efficient solution offers a smooth and consistent scaling that works effectively on both small and large screens! Utilization of minmax and max functions to prevent excessive shrinking has been added.
body {
 grid-template-rows: minmax(2.5rem, 12vmin) 1fr 5rem;
}
header pre {
 font-size: max(0.2rem, 1vmin);
}

Special thanks to Adam and somethinghere, for their input!

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

I am having trouble accessing the database. Jacky @ localhost Password: NO

What is preventing me from accessing the database? Username: jacky @ local host Password: NO ...

Tips on utilizing innerHTML or innerText to add content to the Evernote editor, a rich text editor

A method authored by Jayant was employed in this particular post how-to-insert-text-into-the-textarea-at-the-current-cursor-position to perform an insertion into the Evernote editor. The Evernote editor being a rich text editor, altering from el.value to ...

The Wonders of Flex Box and Media Queries

Can a website still be made responsive without relying on media queries when flexbox is already implemented? Are there specific scenarios where the utilization of media queries offers enhanced control? ...

What is the best way to ensure that the text input in a text area is linked to a particular radio

I have created a form that contains radio buttons. My next goal is to include a text area next to each group of radio buttons. This will allow the user to select an option either by clicking on the radio button or by typing in the corresponding value in t ...

Ways to stop a background image from repeating?

<div style="background-image: url('https://i.ibb.co/v1B855w/bg15.png'); color: #000000; background-color: #000000; background-attachment: fixed; text-align: center;"><img src="https://i.ibb.co/L6zQY0S/name6.png" /> ...

Push the accordion tab upwards towards the top of the browser

I am working on an accordion menu that contains lengthy content. To improve user experience, I want to implement a slide effect when the accordion content is opened. Currently, when the first two menu items are opened, the content of the last item is disp ...

As you scroll, this smooth marquee effect gently shimmers with each movement

I've been trying out this code to create a scrolling marquee text, but the issue is that after 7000 milliseconds it starts to jitter, which doesn't make the text look good. Any suggestions on how I can fix this problem? Let me know! <script ...

Preventing AngularJS from Ignoring HTML Elements

Is there a way to calculate HTML content within an AngularJS object (such as {{names}}) that includes an '<a>' element? When I try to display it, the result looks like this: <a href="http://www.example.com">link text</a> I&ap ...

What advantages do constant variables offer when selecting DOM elements?

What is the significance of declaring variables as constant when selecting elements from the DOM? Many developers and tutorials often use const form = document.querySelector('form'); ...

Extract the content from the span element on Whatsapp Web

Currently, I am in the process of learning Python along with Selenium and have encountered a challenge. I am attempting to extract the username from the most recent message in a WhatsApp group conversation. Despite several attempts, I have been unsuccessfu ...

Exploring the Terrain: Troubleshooting Meteor CSS with Twitter Bootstrap

Recently, I have encountered an issue that perplexes me - I am unable to debug less code in my meteor app when the twbs:boostrap package is present. Interestingly, everything works fine when I remove it, but as soon as I add it back, the CSS seems to be co ...

I am looking to switch the content between two divs. Specifically, I want to take the content from div 1 and move it to div 2, while moving the

I am facing a challenge involving three divs. One of them is the main div, while the other two are positioned below it and contain different content. I am trying to find a way to swap the content between div one and div two in such a way that the original ...

Struggling to implement a Datepicker in the date column of a table created using HTML and JavaScript

I am encountering an issue while creating a table in html and javascript. I am unable to use a Datepicker in the date column when inserting a new row, even though it works fine when using in normal html code. Below is the javascript function: //Script fo ...

Ways to verify if an element includes a specific class in JavaScript

When the mouse hovers over each paragraph within the DIVs with the "change" class, the font color should turn red, and revert back to black when the mouse is not on them. Here's my current code: var paragraphs = document.getElementsByTagName('p& ...

Incorporate content from HTML into various sections

Is there a way to dynamically extract the h4 headers and the first sentence from each section of this HTML, and then add them to a new div? function summarize() { let headings = document.getElementsByTagName("h4"); // Get all H4 elements let newsText = do ...

centered logo in a flexbox header

Having trouble with Flex for the first time. Despite reading and experimenting, I still can't figure it out. Any suggestions on how to accomplish this? Check out an example ...

Tips for making the background image fit perfectly within a div element

I have a calendar div that I want to customize with a background image and text. How can I achieve this? Here is my code: .calenderArrivalDiv{ margin-top: 15%; margin-bottom: 1%; background-image: url("im ...

Navigate the Xpath to target the text enclosed by tags, pausing the extraction process upon encountering an internal tag within the

I am seeking to extract specific text from various forms of HTML code. Only the text within certain tags should be considered, and everything after those tags should be ignored. The structure of the HTML varies. <span class="classA">Text 1 ...

Design elements using CSS within the <th> tags

When working with HTML tables, the use of a <th> element allows for the implementation of a scope attribute. This attribute serves to indicate whether the header cell is associated with its subsequent column, row, or group. Is it feasible to leverage ...

Why is the "text-overflow: ellipsis" property of a parent div not functioning properly for its child div?

Why is the CSS property text-overflow: ellipsis not working on a child div with the class name cluster-name? .ft-column { flex-basis: 0; flex-grow: 1; padding: 4px; text-overflow: ellipsis; overflow: hidden; } .ft-column > .cluster-name { ...