Challenges with text wrapping in a continuously scrolling container in CSS

I am currently developing a project that requires infinite horizontal scrolling for cells containing thumbnails and text. While most of the functionality is in place, I am facing an issue with text wrapping. The CSS and HTML code are provided below. The first two items in the scroll box should have wrapped text, but they overflow instead.

Here is the style (cell 2 is used for demonstration to alternate background colors):

 
        .container {
            display: flex;
            flex-direction: row;
            padding: 10px;
            height: 10%;
            overflow-x: auto;
            white-space: nowrap;
    
            }
    
            .cell {
            background: #818181;
            flex: fit-content;
            padding: 10px;
            width: 220px;
            height: 8%;
            display: inline-block;
    
            }
    
            .cell2 {
            background: #f44336;
            flex: fit-content;
            padding: 10px;
            width: 220px;
            height: 8%;
            display: inline-block;
    
            }
    
            .data {
            justify-content: center;
            word-wrap: break-word;
            }
    
         <div>
           <h2>Scroll Test</h2>
             <div class="container">
               <div class="cell">
                     <a href= "#">
                     <span class="data"> <img src="http://roncabeanz.com/Roncabeanz/images/CoffeeIcon.jpg" width="200px"></span>
                     <span class="data"> <h3>Some text here</h3></span>
                      </a>
                  </div>
                  <div class="cell2">
                      <a href= "#">
                        <span class="data"> <img src="http://roncabeanz.com/Roncabeanz/images/CoffeeIcon.jpg" width="200px"></span>
                        <span class="data"> <h3>Some text here that will over flow</h3></span>
                        </a>
                    </div>
                    <div class="cell">
                        <a href= "#">
                            <span class="data"> <img src="http://roncabeanz.com/Roncabeanz/images/CoffeeIcon.jpg" width="200px"></span>
                            <span class="data"> <h3>Some text here</h3></span>
                        </a>
                    </div>
                    <div class="cell2">
                        <a href= "#">
                            <div class="data"> <img src="http://roncabeanz.com/Roncabeanz/images/CoffeeIcon.jpg" width="200px">    </div>
                            <div class="data"> <h3>Some text here</h3></div>
                        </a>
                    </div>
                    <?php } ?>
                </div>
            </div>

Access the fiddle for more information: https://jsfiddle.net/jonathannah/3rxcktpm/29/

Answer №1

To fix this issue, simply include the following CSS rule: h3 { white-space: normal }. The children of the element with class .container inherit a style attribute that specifies white-space: nowrap, leading to the problem you are experiencing. Furthermore, your HTML code includes an h3 tag nested within a span tag, which is not valid according to best practices. Block elements should not be placed inside inline elements like this. One possible solution could be changing the span tag to a div and giving it the style attribute display: inline.

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

Sliding left and right with the help of jQuery

Hey there! I'm currently working on designing a sliding menu bar that can move left or right based on user interaction with arrow buttons. When the user hovers over the right arrow, the navigation bar smoothly slides from right to left until it reache ...

Custom Sizing for Bootstrap Modals

I need assistance with creating a dynamic bootstrap modal that adjusts its width based on the content and includes a vertical scrollbar when needed. Although the vertical scrollbar is functioning correctly, the horizontal width appears to be static. C ...

Adjusting specific sections of a container in real-time

Fiddle: https://jsfiddle.net/1b81gv7q/ Sorry for the slightly cryptic title; I couldn't come up with a better way to phrase it. Imagine this scenario: there's a container with content that needs to be dynamically replaced. If I wanted to repla ...

The functionality of the click event attached with the addEventListener is

I have a unique project where I am developing a user interface for a paper-rock-scissor game. To create the UI, I included four buttons: "Start game," "rock," "paper," and "scissor." Initially, I wrote separate code for each button, which worked perfectly ...

Controlling div elements using javascript

Is there a way to help me understand or identify my mistake? I seem to have an issue in my javascript and html code related to gathering user input for a flight. I'm trying to create a counter function to tally all flights (function counter()), but it ...

When a div element is clicked, it becomes the selected element and borders are displayed around it

Within a div on my wordpress site, the logo is prominently displayed. Feel free to check it out here: Strange issue - whenever I click on the logo, a large rectangular box suddenly appears. I've experimented with the outline and user-select properti ...

Integrate the ID attribute in CSS to create a scrolling background

I resorted to using Google Translate, so please don't inquire why. Currently, I'm working on a script where I am attempting to incorporate a variable (using JavaScript) into a CSS file. <span id="s-map"></span> {background: ...

Visual element and form entry

I have a follow-up question regarding the same topic. How can I edit it to move up in the list or does that happen automatically? Now, onto the main question - I have an image and an input box both contained within a span, and I want to display them next ...

What's the best way to update the menu element colors as I scroll down the page?

I am looking to update the color scheme of menu elements as the page scrolls using the provided template. I tried a few methods, but they lack dynamism. How can I make it more dynamic? $(document).ready(function(){ //scroll animation $('.navigati ...

Looking to transform a PHP output value

I have a form with checkbox input, and a hidden 'sibling' input attached to it, in order to generate values of either '0' or '3' based on the checkbox status. When unchecked, the value is '0', and when checked, the ...

What is the process for displaying a PHP array in HTML5 audio and video players?

I am currently working with two PHP arrays. The first array, array "a," contains strings that represent paths for MP3 files on the server. The second array, array "b," contains strings representing paths for MP4 files. For example: $test = 'a.mp3&ap ...

CSS border not displaying correctly on high-resolution screens

When resizing the browser window, I noticed that the border of certain elements, such as this deposit button, gets clipped depending on the width. It seems that when I adjust the width pixel by pixel, the border appears and disappears with each movement. C ...

Tips for maintaining consistent webpage layout across various screen sizes

Although this method may seem outdated, I have always been intrigued by how it was accomplished. In the past, before websites became responsive, pages would simply shrink down to fit on mobile devices without adjusting their appearance. How was this achie ...

JavaScript - Modify the proposed content prior to inserting it into the input field

In my current project, I have implemented a feature using jQuery UI - v1.11.4, where an HTML textbox utilizes a JavaScript autocomplete functionality. The suggested string for the textbox is created by concatenating several columns (patient_no, patient_nam ...

Is it possible to change the activation of a link from a double click to just a single click in Angular 5?

I am currently working on an Angular 5 app and have created a navigation component that displays different tabs/links. When a link is active (being viewed), the tab is highlighted with a border to resemble the front of a file folder. However, I am facing ...

What HTML5 form JavaScript polyfill offers the most extensive functionality and compatibility across different browsers?

The improved attributes and tags introduced in HTML5 are quite beneficial. Unfortunately, support for these features is limited in Chrome and Firefox, with virtually no support in IE9 and earlier versions. After researching, I have come across Modernizr a ...

Leveraging SASS for injecting a variable into a mixin where the declaration is in string format

I have been developing a SASS mixin that allows for the input of various variables to construct a font-awesome declaration in the following format: @mixin after-font-awesome($unicode, $size, $margin, $color, $weight) { &:after { content:$unicode ...

Immersive viewing experience

I am facing an issue with my full-screen bootstrap CSS website. The website appears normally, but the problem arises when Google Chrome or Internet Explorer shows the useful links bar. Is there a way to have the website display in full screen even when th ...

Adjust the width of content within a wrapper using HTML and CSS to automatically resize

I am facing an issue with a content div that has variable length content arranged horizontally. I want the width of this content div to adjust automatically based on the length of its content. Removing the arbitrary "20%" value from the width property is c ...

Ways to solve the issue of the mobile dropdown menu in Bootstrap

Check Out the Expected Look Here (Image link) See How it Appears on Mobile Devices The dropdown menu causes an increase in the size of the navbar on the mobile version. Below is the code snippet: <div style=" background-image: url(https://i.imgu ...