Using line breaks and horizontal scrolling in HTML and CSS

I am struggling with a div that contains multiple small spans. My goal is to implement a horizontal scrollbar that extends up until the line break tags (a-z on each line) in order to view the full content on narrow screens.

Although I have applied the 'overflow' style to the div and set it to 'auto', the content always seems compressed within the div and the horizontal scrollbars do not appear as intended.

Is there a way to use a series of spans (or any other tag) followed by line breaks to define where the lines end and specify where the horizontal scrolling should initiate and stop?

<div style="overflow: auto">
    <span>a</span> <span>b</span> <span>c</span> <span>d</span> <span>e</span>
    <span>f</span> <span>g</span> <span>h</span> <span>i</span> <span>j</span>
    <span>k</span> <span>l</span> <span>m</span> <span>n</span> <span>o</span>
    <span>p</span> <span>q</span> <span>r</span> <span>s</span> <span>t</span>
    <span>u</span> <span>v</span> <span>w</span> <span>x</span> <span>y</span>
    <span>z</span>

    <br>

    <span>a</span> <span>b</span> <span>c</span> <span>d</span> <span>e</span>
    <span>f</span> <span>g</span> <span>h</span> <span>i</span> <span>j</span>
    <span>k</span> <span>l</span> <span>m</span> <span>n</span> <span>o</span>
    <span>p</span> <span>q</span> <span>r</span> <span>s</span> <span>t</span>
    <span>u</span> <span>v</span> <span>w</span> <span>x</span> <span>y</span>
    <span>z</span>

    <br>

    <span>a</span> <span>b</span> <span>c</span> <span>d</span> <span>e</span>
    <span>f</span> <span>g</span> <span>h</span> <span>i</span> <span>j</span>
    <span>k</span> <span>l</span> <span>m</span> <span>n</span> <span>o</span>
    <span>p</span> <span>q</span> <span>r</span> <span>s</span> <span>t</span>
    <span>u</span> <span>v</span> <span>w</span> <span>x</span> <span>y</span>
    <span>z</span>

    <br>

</div>

What could be the issue with the absence of the scroll bar?https://i.sstatic.net/e49oq.png

Answer №1

If the text inside this div exceeds the width of the container, it will automatically wrap to fit. To prevent wrapping, you can set white-space:nowrap;. For more information on white space in CSS, check out white-space.

For an example, visit https://jsfiddle.net/nmagq349/

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

How can you switch the default menu in bootstrap 5 to an off-canvas menu?

I'm currently designing a landing page using Bootstrap 5, and I want to replace the default menu with an off-canvas menu that includes a close icon. <!DOCTYPE html> <html lang="en"> <head> … </body> </html> Whi ...

Exploring the possibilities of integrating CSS and JavaScript in Node.js with Express

Here is the folder structure I am working with: lifecoding |login2 |index.html |css style.css |js index.js I have all the necessary modules installed for express to work properly. However, when I try to set the static path as shown below, it keeps ...

Python Automation: Saving Excel Files with Selenium

I'm on a mission to download an XLS file for each day of a specific month. However, when I use Chrome's developer tools to inspect the download button for the XLS file, it turns out that it's not actually a button at all. So how can I go abo ...

CSS Interactive Design Breakpoints

Do my Break points at 768, 480, and 225 provide enough support for a responsive design, or should I consider adding more? 768 + | Computer 480 - 768 | Tablet 225 - 480 | Smartphone 225 < | Phone / Mini Browser ...

Having trouble clicking the button due to the overlay blocking it?

This code contains the HTML portion <li id="nav1" class="navs"><a unselectable="on" draggable="false" class="Navigation" href="http://youtube.com">YouTube</a></li> Below is the CSS code .navs:after { content: ""; position: ab ...

What is the best way to stop div animations when clicking with jQuery?

Upon loading the page, a div animates automatically. There is also a button present. When the button is clicked, I would like to create a new div and animate it the same way as the first one. However, when this happens, the position of the first div also ...

jQuery loops through form fields and sets them as disabled

Trying to solve a question... In a form with multiple inputs, I only need to loop through the ones inside the div tagged player. <div class="player"> <input type="text" value="0" class="unit" /> <input type="text" value="0" class="unit" ...

Combining two kebab-case CSS classes within a React component

import React from 'react'; import styles from './stylesheet.moudle.css' <div className={styles['first-style']} {styles['second-style']}> some content </div> What is the correct way to include styles[&ap ...

CSS margin dispute

I'm facing an issue with two CSS classes - container and top_menu. The top_menu should not have a margin on top when used within the container class, but it somehow does. Removing the container div resolves this. How can I resolve this problem? Below ...

CSS can be used to eliminate specific background images from a webpage

In the CSS code, I have specified two background images within a 'body' tag. #body { background: url("image1.jpeg"), url("image2.png"); background-repeat: no-repeat, no-repeat; } But now, I need to remove only "image1" from a specific p ...

I'm receiving the error message "Fatal error: Call to a member function query() on a non-object," what could be causing this issue?

Need help with fixing an error on my private server realmeye. The error message I'm receiving is: Fatal error: Call to a member function query() on a non-object in /home/noxus/public_html/realmeye/index.php on line 112 =========================== ...

Developing an editor

Currently, I am delving into the concept of object inheritance in JavaScript through a practical exercise where I am creating an online editor similar to the one I am currently using. However, I find myself slightly confused as I aim to utilize data-* att ...

Dynamic resizing navigation with JQUERY

I have successfully created a navigation menu that dynamically resizes each list item to fit the entire width of the menu using JavaScript. $(function() { changeWidth(500); function changeWidth(menuWidth){ var menuItems = $('#menu l ...

How can I ensure my game or website fits perfectly on the screen without any need

I have recently developed a fun Erase-A-Man game that is optimized for mobile devices. However, I am facing an issue where users need to scroll to view all the letters on their screens. My goal is to make the game fit perfectly on all phone screen sizes so ...

Is the hover effect malfunctioning, even though the correct style has been applied?

I'm currently working on a simple design, but I've encountered an issue. When I hover over the number blocks (1, 2, etc.), my hover effect doesn't seem to work. My intention is to hover over the list item and change the entire digit text fro ...

Is it necessary for CSS Media query to load all the referenced CSS files?

When utilizing a CSS Media Query to assign two different stylesheets, such as desktop.css and mobile.css based on the max-width, how does this process function? Is it necessary for both stylesheets to be loaded by the browser every time, and then the appr ...

Preventing scrollbar-induced content shifting in Material-UI components: A guide

My browser app displays content dynamically, which can vary in length compared to the screen size. This causes a vertical scrollbar to appear and disappear on desktop browsers, leading to the content shifting left and right. To prevent this, I apply style ...

Hiding a div after three clicks using HTML

What is the best way to hide a div tag containing an input tag after clicking on the input tag three times using HTML and angular? ...

Display an HTML code snippet on the webpage

I'm facing a situation that has been discussed before on this platform. However, I want to present my problem in a different light. I am working with PHP and need to display an HTML string from the database on my webpage. The issue is that the CSS app ...

vertically centering a div specifically on laptops

What is the best way to vertically center a div on lap-tops? (...) body {padding: 4% 16%;} body {top:0px; left:0px; bottom:0px; right:0px;} body {border: 12px solid darkred; border-style: double;} body {background-color: #FAFCB4;} p {font-size: 80%; text- ...