Preventing overflow of monospace text on small viewports in Bootstrap 5: A complete guide

For a web app I am developing, I need to showcase certain text using a monospace font. This is necessary because the text may include elements like ASCII art, requiring a consistent monospace alignment. Moreover, it's crucial that the text does not wrap around as it could disrupt the intended display.

Here is a snippet of my HTML code:

<body>
    <div id="outer" class="container-sm pt-2 bg-light rounded-bottom">
        <div id="inner" class="text-warning bg-dark rounded p-3 font-monospace">
            Text that is very long and exceeds the width of a mobile display
        </div>
    </div>
</body>

While this works effectively on larger screens, issues arise on mobile devices where the text overflows beyond both outer and inner divs, causing horizontal scrolling for the entire page.

I aim to confine the text within the inner div, especially on smaller viewports like mobile phones. Ideally, I want the horizontal scroll bar to appear solely within the inner div, preserving the overall page layout. This way, mobile users can easily swipe left or right within the inner div to access the complete text.

What modifications should I make to achieve this desired behavior?

Answer №1

Preventing wrapping with nowrap and enabling auto scroll with overflow-x

#inner {
  font-family: monospace;
  overflow-x: auto;
  white-space: nowrap;
}
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b6d4d9d9c2c5c2c4d7c6f68398849887">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-iYQeCzEYFbKjA/T2uDLTpkwGzCiq6soy8tYaI1GyVh/UjpbCx/TYkiZhlZB6+fzT" crossorigin="anonymous">


<body>
  <div id="outer" class="container-sm pt-2 bg-light rounded-bottom">
    <div id="inner" class="text-warning bg-dark rounded p-3 font-monospace">
      Text that is very long and exceeds the width of the mobile display
    </div>
  </div>
</body>

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

Editing input within a Bootstrap 4 popover causes it to lose focus

I am using Bootstrap 4 along with the Bootstrap colorpicker to implement a colorpicker within a popup that includes an input field for setting the color code. However, I am facing an issue where the input field (#color-value) seems uneditable when the popo ...

Is there a way to achieve a straightforward three-column stacked layout in Bootstrap 5 that spans 100% of the viewport height?

Today I decided to try out Bootstrap 5 for the first time. However, I am facing a challenge in creating a 3 stacked column layout with box-1, box-2, and box-3 on top of each other, taking up 100vh. I have shared a redacted version of the code below, wher ...

How can I eliminate or override the CSS property from a content delivery network (CDN)?

Currently, I am utilizing swiper.js through a CDN. However, there seems to be an issue in the swiper-bundle.min.css CDN file where the .swiper-button-next and .swiper-button-prev classes are set to top:50%; like so: .swiper-button-next, .swiper-button-prev ...

Tips for effectively closing div elements

How can I modify this accordion to close when a user clicks on another link, and also change the image of the open "p" tag? Currently, clicking on a link toggles the content and changes the image. However, what I am struggling with is closing the previousl ...

Highlight the navigation transition in the menu

Is there a more updated tutorial available for creating an underline effect that slides from one link to another when hovered over and remains at the clicked link? I have come across a tutorial on Underline transition in menu which seems to be based on th ...

Tips for shutting down an HTML webpage with the help of JavaScript

Recently, I've been working on a project to implement a feature that automatically closes the website when an incorrect password is entered. However, I am fairly new to JavaScript and still in the early stages of learning. Below is the code snippet I ...

What are some strategies I can use to prevent issues with my web design while updating bootstrap?

I recently updated Bootstrap CDN from version 4.0.0 alpha to beta this morning. Here is a snapshot of how the web page looked before (still under construction): Website with Bootstrap 4.0.0 alpha And here is how it appears now: With Bootstrap 4.0.0 bet ...

What is the trick to utilizing CSS transitions to enlarge the font size of a Bootstrap card when it is hovered over

I'm having trouble increasing the font size and changing the color on hover for text inside a Bootstrap card. My current code only changes the color without adjusting the font size or implementing any transitions. I don't have much experience wit ...

Tips for adjusting div content to fit a fixed height on all devices

Looking to adjust the size of the #left-content div based on the height of the window, while ensuring that all content is visible within the fixed #left-bg. However, when viewing on mobile or tablet devices, the content appears hidden. .left-bg{ backgro ...

Designing Your WordPress Website's Header Structure

When working on my non-WP sites, I usually handle columns using Bootstrap. However, this is my first time delving into CSS positioning without it. I am trying to align my site header elements similar to the image shown, where the text elements are flush ri ...

What is the best way to include an image in a bootstrap carousel?

Can anyone help me troubleshoot my issue with fitting an image into the bootstrap carousel? I've tried adjusting the CSS, but it's not working. Any advice or suggestions would be greatly appreciated! Here is a screenshot for reference: https://i ...

Exploring the Vertical Metrics of Various Typeface Styles

I'm encountering a problem and struggling to find a solution. I'm in the process of creating a website and incorporating various fonts. My goal is to ensure that every font appears visually similar to the others and align perfectly at the base. ...

Encountered an issue when attempting to insert data into MySQL using jQuery

Having some difficulties with jQuery and MySQL, specifically when trying to insert data into the database. Here is the code from my HTML file: <!DOCTYPE html> <html> <head> <title> Staff Registration </title> <body> < ...

Trouble with Safari browser windows and Mac Safari compatibility

Hello everyone, I have a CSS code that I need help with. See below: .left { margin-bottom: 20px; } It works fine on Windows OS with Safari and Chrome browsers, but it's all messed up on Mac OS Safari. After debugging in Mac, I found that it need ...

Tips for consistently positioning a div beneath another div in HTML/CSS

Would appreciate it if you could review this. <.div id="main"> Main Div <./div> <br/> <.div id="sub">Sub-Division<./div> ...

What might be causing the status problem to not display correctly?

My toggle feature to switch between no issue and issue is not displaying the status correctly. Despite trying to troubleshoot, I can't figure out why the issue section is not showing up. <!DOCTYPE html> <html> <script src="https://aj ...

When sending a post request in MongoDB, only the object's _id is displayed

Can someone help me with an issue I am facing with a contact form in my HTML file? The form code is as follows: <form action="/contact" method="post"> <input type="text" name="name" id="" placeholder="Name"> <input type="email" name ...

jQuery: Issue Encountered with POST Request when Offline (iOS & Chrome)

After developing an HTML5 web application with offline capabilities using AppCache, the process flow is as follows: Online: While connected to the network, the app loads base information in advance. Offline: Users can take the app offline on their tablet ...

Break down the text of a paragraph into separate words, placing each word within its own span element, and then add animations

I am facing an issue with my paragraph element that has the display property set to hidden. I have split each word of the paragraph and placed them inside individual span elements. My goal is to create an effect where each word comes from different locatio ...

In Java, use an HttpRequest to retrieve the webpage content and ensure that the process waits until the JavaScript has finished

Is there a way in Java to wait for partial content of a webpage to be loaded by JavaScript before initiating the rest of the process? The webpage contains script that loads additional content once the page is fully loaded, and I need to ensure that the p ...