Tips for creating a horizontal bar with CSS using the float property

Looking to create a horizontal scroll layout using CSS and floats? Here's my attempt, but I'm not getting the desired result. Flexbox isn't an option as it needs to be supported on IE. Take a look at my code and point out where I might have gone wrong.

.bar {
  float: left;
  background-color: rgb(250, 250, 250);
  min-width: 100%;
  height: 62px;
  padding-top: 8px;
  white-space: nowrap;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  -ms-overflow-style: -ms-autohiding-scrollbar;
}

.box {
  float: left;
  display: block;
  height: 46px;
  width: calc(12.5% - 8px);
  border-radius: 3px;
  background-color: rgba(0, 123, 45, 1);
  box-shadow: 0 3px 4px 0 rgba(211, 246, 250, 1);
  text-align: center;
  margin-left: 13px;
  padding: 5px;
}

.day {
  display: block;
  opacity: 0.76;
  color: rgba(255, 255, 255, 1);
  font-size: 11px;
  line-height: 13px;
}

.date {
  display: block;
  color: rgba(255, 255, 255, 1);
  font-size: 18px;
  font-weight: 500;
  line-height: 22px;
}
      <div class='bar'}>
        <div>
          <div class='box'}>
            <div class='day'>monday</div>
            <div class='date'>25</div>
          </div>
        </div>
        ...
        (repeated for each item)
        ...
        <div>
          <div class='box'}>
            <div class='day'>monday</div>
            <div class='date'>25</div>
          </div>
        </div>
      </div>

Answer №1

The best approach is to use a table instead of nested floating elements, as this will ensure that your code works on IE browsers.

.bar {
  background-color: rgb(250, 250, 250);
  min-width: 100%;
  height: 100px;
  padding-top: 8px;
  white-space: nowrap;
  overflow-x: scroll;
  -webkit-overflow-scrolling: touch;
  -ms-overflow-style: -ms-autohiding-scrollbar;
}

.box {
  float: left;
  display: block;
  height: 46px;
  width: 100px;
  border-radius: 3px;
  background-color: rgba(0, 123, 45, 1);
  box-shadow: 0 3px 4px 0 rgba(211, 246, 250, 1);
  text-align: center;
  margin-left: 13px;
  padding: 5px;
}

.day {
  display: block;
  opacity: 0.76;
  color: rgba(255, 255, 255, 1);
  font-size: 11px;
  line-height: 13px;
}

.date {
  display: block;
  color: rgba(255, 255, 255, 1);
  font-size: 18px;
  font-weight: 500;
  line-height: 22px;
}
<div class='bar'>
  <table>
    <tr>
      <td>
        <div class='box'>
          <div class='day'>monday</div>
          <div class='date'>25</div>
        </div>
      </td>
      <td>
        <div class='box'>
          <div class='day'>monday</div>
          <div class='date'>25</div>
        </div>
      </td>
      <td>
        <div class='box'>
          <div class='day'>monday</div>
          <div class='date'>25</div>
        </div>
      </td>
      <td>
        <div class='box'>
          <div class='day'>monday</div>
          <div class='date'>25</div>
        </div>
      </td>
      <td>
        <div class='box'>
          <div class='day'>monday</div>
          <div class='date'>25</div>
        </div>
      </td>
      <td>
        <div class='box'>
          <div class='day'>monday</div>
          <div class='date'>25</div>
        </div>
      </td>
      <td>
        <div class='box'>
          <div class='day'>monday</div>
          <div class='date'>25</div>
        </div>
      </td>
      <td>
        <div class='box'>
          <div class='day'>monday</div>
          <div class='date'>25</div>
        </div>
      </td>
    </tr>
  </table>

</div>

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

Layering an object on top of a clone using CSS

I am working on a webpage with a jQuery menu located at the following link: Menu To accommodate more items and have greater control, I duplicated the menu twice. However, when hovering over them, the duplication is visible in the background. Is there a ...

Quick question about utilizing Ajax with spans

<span name = "menu"> <!-- javascript here --> <!-- content loaded via ajax --> </span> <span name = "content"> <!-- content loaded via ajax --> <!-- updated by buttons from the menu--> </span> Seeking a ...

Unable to access the suggestion list within the modal

I incorporate the PrimeNG AutoComplete feature within a PrimeNG Dialog, displaying a list of elements below the AutoComplete in the dialog. My objectives are: To set the max-height of the modal dialog to 300, and have a visible scrollbar if the total ...

How to toggle the display of a div by its id using index in Javascript

Currently, I am encountering a problem with toggling the div containers. When I click on the video button, I want the other divs to close if they are already open. However, due to the toggling mechanism, if a div is closed and I click on the corresponding ...

How to style CSS to ensure printed table content fits perfectly within the page

Does anyone know how to resize the contents of a table using CSS so that everything shows up when printing, without wrapping text in individual cells? In this scenario, <table class="datatables" id="table1"> <tr> <td style="white-space:nowr ...

Click a button to show or hide text

I am attempting to create a button that will toggle text visibility from hidden using 'none' to visible using 'block'. I have tried the following code but unfortunately, it did not yield the desired outcome. <p id='demo' s ...

Can you place more than one Twitter Bootstrap carousel on a single webpage?

Latest Version of Twitter Bootstrap: 2.0.3 Sample HTML Code: <!DOCTYPE html> <html dir="ltr" lang="en-US" xmlns:og="http://opengraphprotocol.org/schema/"> <head> <link rel="stylesheet" type="text/css" media="all" href="reddlec/style. ...

Unable to retrieve HTML code with PHP's file_get_contents function

I have been trying to retrieve the HTML content of a webpage using the code below: $url = "http://mysmallwebpage.com/"; $html = file_get_contents($url); Unfortunately, it seems that the file_get_contents function is unable to open URLs in certain formats ...

Conquer the issue of incessant AJAX page refreshing

Currently, I am working on an application where I handle numerous form submissions and utilize ajax to send data to a server running on Node.js. One of the features includes updating a table upon button click, which triggers a spinner to load as an indic ...

Matching multiple divs with different ids in PHP using preg_match_all and regex

I have an HTML page structured like this: <!DOCTYPE html> <html> .... <body> <div class="list-news fl pt10 "> Blue </div> <div class="list-news fl pt1 ...

"Proceeding without waiting for resolution from a Promise's `.then`

I am currently integrating Google Identity Services for login on my website. I am facing an issue where the .then function is being executed before the Promise returned by the async function is resolved. I have temporarily used setTimeout to manage this, b ...

What causes divs to be interspersed among other divs when Float is enabled?

I am looking to create a layout for 4 sections, similar to a table, utilizing only divs and CSS. The intended output is this: Logo-----------Info Business-------Client I initially thought it would be simple by using the Float property. However, when I se ...

Tips for indicating errors in fields that have not been "interacted with" when submitting

My Angular login uses a reactive form: public form = this.fb.group({ email: ['', [Validators.required, Validators.email]], name: ['', [Validators.required]], }); Upon clicking submit, the following actions are performed: ...

Tips for perfectly aligning all elements in a row within a card design

Hi there, I'm trying to figure out how to align the content of this card in a single row instead of stacked on top of each other. Here's the code snippet: <div class="container"> <form onSubmit={submitHandler}> ...

How can I position a Button at the center of my Grid item using Material UI?

In my React 16.13.0 application, I am utilizing Material UI's Grid and trying to center the content of a button in the middle of a row. Here is what I have tried: center: { alignItems: "center", width: "100%", }, halfRow: { width: "5 ...

There seems to be an issue with the CSS file linking properly within an Express application

Every time I run my app.js file, the index.html file is displayed. However, when I inspect the page, I notice that the CSS changes are not taking effect. Strangely, if I open the HTML file using a live server, the CSS changes are visible. Can someone exp ...

Opera's extra space feature allows users to comfortably browse the

I'm attempting to insert a progress bar inside a td element within my table. Below is the code: <td style="width: 150px;"> <div style="height: 16px; max-height: 16px; overflow: hidden; border: 1px solid #80C622;"> < ...

Ways to clear all CSS rules from a class without deleting the class itself using jQuery

Clear out all CSS properties within a class without actually removing the class itself using jQuery For instance : .ui-widget { font-family: Verdana, Arial, sans-serif/*{ffDefault}*/; font-size: 1.1em/*{fsDefault}*/; left: 350 ...

Error: Unable to access the 'nom_gr' property of null - encountered in Chrome

<ion-col col-9 class="sildes"> <ion-slides slidesPerView="{{nbPerPage}}" spaceBetween="5"> <ion-slide *ngFor="let slide of lesClassrooms; let i = index" (click)="saveCurrentSlide(i)"> ...

Encountering difficulties while using JavaScript to complete a form due to issues with loading the DOM

Currently, I am attempting to automate the completion of a multi-page form using JavaScript. Below is the script that I am utilizing: // Page 1 document.getElementById("NextButton").click(); // Page 2 completion(document.getElementById("Rec ...