The scrolling function in CSS is malfunctioning

I encountered a scroll-x issue in CSS

Here is the HTML code snippet:

<div id=main_user_chat_tab_div class="chat-container_div" style="border:4px solid #F00;">
    <div id="chat_box_win" class="chat_box_win" style="position:relative;"></div>
    <div id="chat_user_rec" style="width:100%; height:20%; border:3px solid #333;overflow-y:hidden;overflow-x:scroll; display:table-row; position:relative;">        
        <div id="user_chat_image"></div>
        <div id="user_chat_image"></div>
        <div id="user_chat_image"></div>
        <div id="user_chat_image"></div>
        <div id="user_chat_image"></div>
        <div id="user_chat_image"></div>    
    </div>
</div>

CSS code:

 .chat-container_div {
    width: 20.2%;    
    height:72%;
    margin-right:15%;
    margin-top:11%;
    float:right;
    position:relative;
    display:none;
  }



#user_chat_image {

    position:relative;
    display:inline;
    background: red;
    -moz-border-radius: 50px;
    -webkit-border-radius: 50px;
    border-radius: 50px;
    bottom:0px;
    float:right; margin-right:2%; width:60px; height:60px;  display:block;
}

I am trying to achieve a scroll-x functionality when the outer div chat_user_rec is full. However, it is not working as expected; overflow divs are appearing on the next row. Any insights on what might be causing this issue?

https://i.sstatic.net/FaV8R.png

Answer №1

If I understand your question correctly, it seems like utilizing white-space: nowrap; on the parent element will help achieve the desired outcome. Check out this example here: Codepen

I have simplified your sample a bit. Here is the updated HTML:

<div id=main_user_chat_tab_div class="chat-container_div" style="border:4px solid #F00;">
  <div id="chat_box_win" class="chat_box_win" style="position:relative;"></div>
  <div id="chat_user_rec" style="width:auto; height:20%;overflow-y:hidden;overflow-x:scroll; display:block; position:relative; white-space: nowrap; text-align: right;">
    <div class="user_chat_image"></div>
    <div class="user_chat_image"></div>
    <div class="user_chat_image"></div>
    <div class="user_chat_image"></div>
    <div class="user_chat_image"></div>
    <div class="user_chat_image"></div>
  </div>
</div>

Additionally, here is the corresponding CSS:

.chat-container_div {
  width: 20.2%;
  height: 72%;
  margin-right: 15%;
  margin-top: 11%;
  float: right;
  position: relative;
}

.user_chat_image {
  position: relative;
  display: inline-block;
  background: red;
  -moz-border-radius: 50px;
  -webkit-border-radius: 50px;
  border-radius: 50px;
  margin-right: 2%;
  width: 60px;
  height: 60px;
}

Note: I noticed an error in using ID instead of class for user_chat_image, so I made the necessary corrections in both the HTML and CSS.

Lastly, I suggest transferring all styling information from the HTML to the CSS file for better organization.

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

Ways to eliminate / refresh locomotive scroll when resizing the window?

I am currently working on a website that is designed with a horizontal layout for desktop screens, but switches to a vertical layout for smaller screens. I have implemented locomotive scroll successfully, but I am facing issues with window resizing. Below ...

Ways to modify the screen when a click event occurs

To make the display block when clicking this icon: <div class="index-navi-frame-box"> <p onclick="expandFunction()"> <i class="fa fa-bars"></i> </p> </div> Here is what it should change to: <div class=" ...

Help with guiding and redirecting links

Here's the code snippet: <script> if(document.location.href.indexOf('https://thedomain.com/collections/all?sort_by=best-selling') > -1) { document.location.href = 'https://thedomain.com/pages/bestsellers'; } </script& ...

Mobile devices not showing the Navbar bootstrap menu

My header.php works perfectly on desktop, but the navigation bar is not displaying properly on mobile devices. Here is my code: <!DOCTYPE html> <html> <head> <title>International Pvt. Ltd.</title> <meta name="viewpo ...

What is the best way to minify and concatenate multiple CSS files only after converting SCSS to CSS with Gulp?

When attempting to convert my scss files to css files using gulp, I encountered an issue. After writing the scss code, it is easily converted to css. However, I wanted to minify this css and save it in a different folder called 'min'. Within the ...

Adjusting the height of a link to match the available space within a navbar using Bootstrap 4

I'm facing an issue with my navbar: <nav class="navbar navbar-light bg-light"> <span class="navbar-brand mb-0 h1>Brand</span> <a>I wanna grow</a> </nav> My goal is to have the link inside the navbar expand to ...

Error with an absolutely positioned element within a link in the Firefox browser

I'm experimenting with a unique effect for my links that involves making it look like the upper left corner has been bitten off. To achieve this, I am using absolute positioning of a square element with the same background color as the link itself. W ...

Is there a way to adjust the title length so that it can change dynamically?

https://i.sstatic.net/Tu9QM.pngCurrently, the title has a fixed background color which may widen if the resolution is smaller than the original size. My aim is to create a dynamic background color that adjusts based on the resolution. Regardless of wheth ...

Customize CSS styling

When it comes to the styling of my first line, I have a specific style in mind: * { text-align:left; } This style works well across most parts of the site as they are predominantly left aligned. However, there are few areas where I need the text alig ...

Only IE7 seems to be experiencing a z-index problem with CSS that is not present on any

I’ve encountered a perplexing problem with CSS z-index in IE7 that I just can’t seem to solve. #screen { display: none; background-image: url('/images/bg.png'); background-repeat: repeat; position: fixed; top: 0px; le ...

Ensure the modal content is loaded only when the modal is being displayed, not

I currently have a basic CSS-styled modal that appears when a button is clicked using JavaScript. Here is the JavaScript code: <script> var modal = document.getElementById('myModal'); var btn = document.getElementById("myBtn"); var span = ...

Tips for resolving issues with JS and JQuery not functioning properly in a Chrome extension

Currently configuring a chrome extension and have successfully constructed the settings menu with functional CSS and HTML. Utilizing this button from Codepen, which confirms error-free code via https://i.sstatic.net/0yG0l.png. How should I define the fun ...

I am experiencing issues with CSS functionality in my Ruby on Rails application

Currently, I am in the process of creating a blog based on Mackenzie Child's 12 in 12 RoR tutorials. I diligently followed all the steps in the tutorial and adhered strictly to his code. However, I encountered an issue with the CSS stylesheets not be ...

Interference in the output of .innerHTML leads to disruption

I have been working on a feature to display a calculated price based on the selected quantity for each individual product. I attempted to duplicate the code and modify variable names, but encountered issues with the increase/decrease buttons triggering mul ...

The text relentlessly presses the button within the confines of bootstrap

I am facing an issue with the alignment of the buttons in my HTML code. As the text inside the <p> tag grows, it pushes the button to the right. I want all the buttons to be positioned in the bottom-right corner of every div regardless of the text si ...

Tips for applying a jQuery class when the page is both scrolled and clicked

As I work on building a HTML website, I encountered an interesting challenge. I want to create a dynamic feature where, as users scroll through the page, certain sections are highlighted in the navigation menu based on their view. While I have managed to a ...

The CSS transition will only activate when coupled with a `setTimeout` function

After using JavaScript to adjust the opacity of an element from 0 to 1, I expected it to instantly disappear and then slowly fade back in. However, nothing seems to happen as anticipated. Interestingly, if I insert a setTimeout function before applying th ...

Trouble with CSS: Struggling to apply margins to a line of images in React JS

I've encountered an issue where I can't seem to add margin to the row of images. The margin appears fine without any CSS when viewed on a wide screen, but once I scale it down to mobile view, the margin disappears completely. Even after attemptin ...

The navigation bar seems to have disappeared from the second page of the website

My navigation bar is working perfectly on my landing page, but when I copied and pasted it onto the second page, it's not showing up. I'm puzzled as to what could be going wrong, as I've checked and rechecked the code multiple times. I have ...

The slideshow feature on W3 Schools does not start automatically when the page loads

After following the W3Schools tutorial to create a slideshow, I found that the animations are working correctly. However, only three dots appear on the screen and I have to manually click on one of them to view the pictures. var slideIndex = 0; sh ...