The horizontal overflow in the HTML code was unsuccessful

I stumbled upon an interesting issue where I applied a div with specific styling:

overflow-x: scroll

However, the outcome was not as expected. Instead of overflowing, the content simply started on a new line. Here is the source code for reference:

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8>
  <title>test</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=1>
  <style>
    .fl {
      float: left;
    }
    .cp-header {
      height: 40px;
      padding: 7px 0px;
      border-bottom: 2px solid #cdcdcd;
      box-sizing: border-box;
    }
    .cp-header span {
      display: inline-block;
      border-right: 2px solid #cdcdcd;
      box-sizing: border-box;
      text-align: center;
      height: 24px;
      line-height: 24px;
      font-size: 14px;
    }
  </style>
</head>

<body>
  <div style="width: 30%; box-sizing: border-box" class="fl">
    <div class="cp-header" style="width:100%;">
      <span style="width:100%;">name</span>
    </div>
  </div>

  <div id="tabGrp" style="width: 70%; box-sizing: border-box;" class="fl">
    <div class="cp-header" style="display: inline-block; overflow-x: scroll; white-space: nowrap;">
      <span class="fl" style="width: 100px;">
                    tab
                </span>
      <span class="fl" style="width: 100px;">
                    tab
                </span>
      ... Repeat for remaining tabs ...
    </div>
  </div>
</body>

</html 

Upon inspection, my intention was to have the content within "#tabGrp" horizontally scroll by setting the property overflow-x:scroll. If the child elements' width exceeded their parent's width, scrolling should be enabled. However, this desired functionality did not occur. Can you spot any mistakes in my implementation?

Answer №1

There are 2 issues: the span element should not have a float property, and the cp-header needs a specified width.

Note that mixing inline and external styles is not recommended, so I have converted it to external style.

<!DOCTYPE html>
<html lang="en">

  <head>
    <meta charset="UTF-8>
    <title>test</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=1">
    <style>
      .tabCap {
        width: 30%;
        box-sizing: border-box;
      }
      .tabGrp {
        width: 70%;
        box-sizing: border-box;
      }
      .fl {
        float: left;
      }
      .cp-header {
        display: inline-block;
        white-space: nowrap;
        width: 100%;
        height: 60px;
        padding: 7px 0px;
        border-bottom: 2px solid #cdcdcd;
        box-sizing: border-box;
      }
      .cp-header.scroll {
        overflow-x: scroll;
      }    
      .cp-header span {
        display: inline-block;
        width: 100%;
        border-right: 2px solid #cdcdcd;
        box-sizing: border-box;
        text-align: center;
        height: 24px;
        line-height: 24px;
        font-size: 14px;
      }
      .cp-header.scroll span {
        width: 100px;
      }

    </style>
  </head>

  <body>
    <div class="tabCap fl">
      <div class="cp-header">
        <span>name</span>
      </div>
    </div>

    <div class="tabGrp fl">
      <div class="cp-header scroll">
        <span>tab</span>
        <span>tab</span>
        <span>tab</span>
        <span>tab</span>
        <span>tab</span>
        <span>tab</span>
        <span>tab</span>
        <span>tab</span>
        <span>tab</span>
        <span>tab</span>
      </div>
    </div>
  </body>
</html>


Update regarding the comment about spacing between the spans:

The extra space between the span elements is due to line breaks in the markup. To resolve this, keep the start and end tags on the same line like this:

Updated Plunker link

<span>tab</span><span>tab</span>

Answer №2

Everything is functioning correctly for me, take a look

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8>
    <title>test</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=1">
    <style>
        .fl2 {
            float:left;
        }

        .cp-header {
            height: 40px;
            padding: 7px 0px;
            border-bottom: 2px solid #cdcdcd;
            box-sizing:border-box;
        }

        .cp-header span {
            display: inline-block;
            border-right: 2px solid #cdcdcd;
            box-sizing:border-box;
            text-align: center;
            height: 24px;
            line-height: 24px;
            font-size: 14px;
        }
    </style>
</head>
<body>
    <div style="width:30%; box-sizing: border-box;" class="fl2">
        <div class="cp-header" style="width:100%;">
            <span style="width:100%;">name</span>
        </div>
    </div>

    <div id="tabGrp" style="width:70%; box-sizing:border-box;" class="fl2">
        <div class="cp-header" style="width:100%; display:inline-block; overflow-x: scroll; white-space:nowrap;">
            <span class="fl" style="width:100px;">
                tab
            </span>
            <span class="fl" style="width:100px;">
                tab
            </span>
            <span class="fl" style="width:100px;">
                tab
            </span>
            <span class="fl" style="width:100px;">
                tab
            </span>
            <span class="fl" style="width:100px;">
                tab
            </span>
            <span class="fl" style="width:100px;">
                tab
            </span>
            <span class="fl" style="width:100px;">
                tab
            </span>
            <span class="fl" style="width:100px;">
                tab
            </span>
            <span class="fl" style="width:100px;">
                tab
            </span>
            <span class="fl" style="width:100px;">
                tab
            </span>
            <span class="fl" style="width:100px;">
                tab
            </span>
        </div>
    </div>
</body>
</html>

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

Utilize v-for to dynamically showcase a variety of images on your

My goal is to showcase several JPG pictures located in the src/assets/images folder by utilizing the v-for directive. However, it seems like the browser is having trouble locating them. Interestingly, manually adding the pictures with the same paths works ...

Why isn't my classList .add method working properly?

I've created a video slider background on my website, but I'm having trouble with the Javacript for video slider navigation. When I click on the button to change the video, nothing happens. The console is showing an error message that says "Canno ...

"NODEJS: Exploring the Concept of Key-Value Pairs in Object

I am facing a challenge with accessing nested key/value pairs in an object received through a webhook. The object in req.body looks like this: {"appId":"7HPEPVBTZGDCP","merchants":{"6RDH804A896K1":[{"objectId&qu ...

Unable to make a successful POST request using the JQuery $.ajax() function

I am currently working with the following HTML code: <select id="options" title="prd_name1" name="options" onblur="getpricefromselect(this);" onchange="getpricefromselect(this);"></select> along with an: <input type="text" id="prd_price" ...

The Material-UI DataGrid feature allows for the display of column sums, with the sum dynamically updating based on applied filters

I am struggling with calculating the sum of values in the Total Amount column of my Material-UI DataGrid. How can I achieve this and ensure that the sum is also updated when a filter is triggered? Any guidance on how to sum the entire Total Amount column ...

Tips for adjusting the div style when resizing the browser

As I work on a script, I encounter an issue where the style of a div should change when it becomes larger due to resizing. Even though I have come up with a solution for this problem, there are still some inconsistencies. Sometimes the width is reported a ...

Animate an svg icon to follow a designated path as the user scrolls

I am currently working on a project that involves animating a bee svg icon as the user scrolls through the website. The bee starts at the top and fills in a grey color line with pink as the user moves forward, and moves backward as the user scrolls back. Y ...

Encountering the error "Cannot read property 'header' of undefined" while conducting tests on Nodejs using supertest

In my server.js file, I have set up my express app. I tried to run a demo test in my test file using express, but unfortunately, the test did not run successfully. const request = require('supertest'); const express = require('express' ...

Looking for a new slider option to replace the traditional Conveyor belt slideshow?

I have successfully used the Conveyor belt slideshow script from http://www.dynamicdrive.com/dynamicindex14/leftrightslide.htm. Now, I am looking to find another script that works similar to this one. Does anyone have any recommendations for a tool that ...

Is there a way to reset the yAxes count of a chart.js chart in Angular when changing tabs?

I am currently using chart.js within an Angular framework to visually display data. Is there any method available to reset the y-axis data when changing tabs? Take a look at this Stackblitz demo for reference. Upon initial loading of the page, the data ...

Encountering the error message "myFunction variable is not declared" when using Google Closure Compiler

When attempting to compile two JavaScript files that both use a function declared in only one of the files, an "undeclared" error is returned. To solve this issue, I added the function declaration to my externs file like this: var myFunction = function() ...

The variables are filled with HTML tags that will render the display in

I am facing an issue with displaying HTML tags in my website. When I try to print a variable containing HTML tags in the tpl file, it shows the tags along with the content. This is how it looks in the PHP file: $content = "<h1>Header</h1>< ...

JavaScript loop used to create markers on Google Maps

I am currently in the process of developing a basic Google map which includes markers and involves looping through the data source for the markers. When I replace key.lng or key.lat with hardcoded values in the code below, everything functions correctly. ...

"Enhance Your WordPress Website with the Power of jQuery

I have been developing a unique Wordpress plugin that incorporates a grid loading effect using jQuery. The script I have implemented is as follows: <script type="text/javascript"> new GridScrollFx( document.getElementById( 'grid' ), { ...

Implementing momentLocalizer with moment.js in react-big-calendar alongside fullcalendar.js

I'm currently working with react-big-calendar and I require assistance in setting up localization as per the example provided on GitHub. import BigCalendar from 'react-big-calendar'; import moment from 'moment'; BigCalendar.setLo ...

Retrieve the array element that is larger than the specified number, along with its adjacent index

Consider the following object: const myObject = { 1: 10, 2: 20, 3: 30, 4: 40, 5: 50, }; Suppose we also have a number, let's say 25. Now, I want to iterate over the myObject using Object.entries(myObject), and obtain a specific result. For ...

What steps do I need to follow in order to incorporate and utilize an npm package within my Astro component

I have been working on integrating KeenSlider into my project by installing it from npm. However, I am encountering an error message that says Uncaught ReferenceError: KeenSlider is not defined whenever I try to use the package in my Astro component. Belo ...

Mastering AJAX requests in Zend Framework

I'm facing a challenge in integrating an AJAX search function with the Zend Framework. My Controller and Action look like this: class IndexController extends Zend_Controller_Action { public function indexSearchAction() { $this-> ...

Incorporate numerous style classes into an object using React Material-UI

I am facing an issue with my JSX code: <span className="btn-pause btn"><i class="fa fa-pause"></i></span> I would like to change the color of this button. Here is what I have tried: const styles = { btncolor ...

Passing numerous PHP echo values to multiple text fields through jQuery AJAX

Check out my PHP file where I will be returning two echoes using jQuery Ajax <?php $data=$_POST['data1']; $data2="h"; if($data2==$data) { echo "john"; echo "usa"; } else { echo "Error"; } ?> This is how I call it with Ajax and populate ...