I'm curious why my divs are stacking vertically instead of aligning horizontally. Can anyone shed some light on this

Here is my code: click this link to view the complete code

I am attempting to create a horizontal array table. The data in the div elements is sourced from my Google spreadsheet, and I have inserted that data into the div with `id="schedule"`. Each time a new row with topics is added to my spreadsheet, a new "topic" appears in my HTML result, which is desirable. However, all the divs (topics) are arranged vertically instead of horizontally. I also wish to include a button to slide each div from left to right. You can understand what I mean by viewing this script: slide divs with a script. I believe I can implement this myself once I resolve why my result is displayed vertically.

In essence, I want to transition from the current vertical layout: https://i.sstatic.net/assns.jpg To this desired horizontal layout: https://i.sstatic.net/dvEW8.jpg

I attempted to utilize `display:inline-block` on the div with `id="schedule"`, but it did not produce the anticipated change.

Could someone pinpoint the section of my code responsible for stacking each "topic" vertically? How should I modify it to arrange them horizontally alongside each other?

My code:

<!doctype html>
<html>
<head>
<!-- additional linked resources -->
</head>
<body>
<div class="New-schedule">
<div id="schedule"></div>
</div>
</body>
</html>

Answer №1

Your current approach

Each item on your list is currently displayed within a <div>. Divs are considered block-level elements, meaning they occupy the entire width of their container. This results in them taking up the full width of the parent container and stacking vertically down the page. To change this layout, consider setting the <div> to have a display: inline-block property with a fixed width after cleaning up the code:

  • The use of <div id="img"> for each list item is not recommended as IDs should be unique and descriptive. Opt for a more semantic class name like class="schedule-item".
  • Moving multiple inline styles to a separate rule can help streamline the code:
    .schedule-item { display: inline-block; width: 300px; border-radius: 8px; /* additional inline styles... */ }
  • The handleResults for loop starting at index 1 might result in skipping the first record.

A suggested improvement

If you're looking for a specific design or functionality, it's advisable to explore carousel/slider plugins available online or on GitHub. By integrating a plugin that aligns with your requirements, the HTML structure and styling/interaction can be handled seamlessly. For example, consider using FlexSlider 2. Consult their documentation for setup details, but a basic JS pseudocode would involve:

  • Initializing the slider plugin on the designated container <div> and fetching spreadsheet data.
  • Iterating through schedule items and utilizing the slider plugin's API methods to insert/add slides dynamically.

To kickstart your implementation, refer to this resource here.

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

CSS vertical alignment property

I'm facing a rather simple problem that has left me scratching my head. The vertical align property is performing correctly, but as soon as I introduce a tag after the text meant to be centered along the image, any text that follows the tag appe ...

Prevent the Bootstrap table from expanding to the entire screen width and causing unnecessary spacing within the cells

I am facing an issue with a table that expands to fill the screen when it exceeds 600px, causing extra spacing on the right of each cell. How can I prevent this automatic growth and eliminate the unwanted space so that the next column aligns with the end o ...

I am encountering a confusing issue where utilizing await does not actually wait for a Promise to resolve. Can you shed some light on why this unexpected behavior is happening?

Here is a function that I am working with: const getCurrentDetails= async () => { const currentDateTime = new Date(moment('00:00','HH:mm') .tz('America/New_York') ...

Eliminate event listener using unique identifier

Is there a way to retrieve information about all event handlers for an element in JavaScript? $._data($('#element_id')[0], "events"); This will provide a detailed record of every event handler attached to the element. 0: {type: "c ...

Encountering an error while attempting to run bcrypt on Meteor and Nodejs - "Undefined property '_handle'."

Having trouble integrating the bcryptjs package into my Meteor app. Successfully installed bcrypt using meteor npm install --save bcrypt. Trying to implement bcrypt functions with import bcrypt from 'bcrypt';. Encountering an error in the cons ...

Uncovering the characteristics of a GeoJSON data layer within Google Maps V3

Is there a way to access the properties of the data layer itself when loading a geoJSON file into a Google Map? I understand how to access the individual properties like posts_here, but I'm interested in obtaining the properties for the layer as a wh ...

What is the default behavior for an invalid select option in Angular 2 model-driven forms?

Is it possible to create an invalid default select option in an Angular 2 model-driven form? I want to do something like the following: <select name="DateExpiryMonth" [(ngModel)]="model.DateExpiryMonth" ngControl="dateExpiryMonth" required> < ...

Submitting form via ajax whenever triggered

I am looking for a way to submit each form individually by clicking on the submit button. My question: How can I send each form separately and display the results accordingly? The code I have tried does not seem to be working, as nothing is being sent and ...

What is the proper way to utilize JQuery and Ajax to communicate with a global function in writing?

My goal is to retrieve data from an AJAX request and store it in a global variable. Despite trying to make the call synchronous, I am encountering issues where the value of the global variable becomes undefined outside of the Ajax request. I have attempt ...

Hold down for File Menu to appear

Can a long press be used for triggering file dialog? I came across an interesting discussion about Long Press in JavaScript, where they discuss how to trigger an event on a long press. However, this method may not work for triggering file input click in ...

Customizing the attribute of an HTML tag using EJS or jQuery

Within my express server, I am rendering a page with the following data: app.get('/people/:personID', function (req, res) { res.render("people/profile", {person: req.person }); }); Inside my profile.ejs file, I can display the data within an ...

Discovering the method for accessing a variable within jQuery from a regular JavaScript function

As someone new to jQuery, I am currently facing a challenge with accessing a variable defined inside a jQuery block from a regular function. Despite my attempts, I have been unsuccessful in accessing it. Can anyone guide me on how to do this? <script l ...

Getting text between Span tags using Selenium in Python

Struggling to extract the name "Margaret Osbon" from the following HTML using Python and Selenium. Despite trying different techniques, the printed output always comes out blank. <div class="author-info hidden-md"> By (autho ...

The AJAX response containing jQuery is failing to produce any visible changes

On Page 1 of my website, there is a form that, upon submission, loads Page 2 using jQuery. This process involves calling a PHP page and displaying the output on Page 1 without actually reloading the entire page. To maintain security, I have set up session ...

Ways to troubleshoot the logic issue in the loop for my simple login interface

I have been able to successfully implement code that detects when a user enters an incorrect username or password, as well as granting access when the correct credentials are provided initially. However, there seems to be a logic error in my loop that prev ...

Using Javascript to establish a connection with a Joomla MySQL database

Recently, I was tasked with building a website in Joomla that utilizes a MySQL database. As part of this project, I am required to develop a JavaScript function that connects to the MySQL database. Do you have any advice or tips for me? ...

The jQuery window.on event is not functioning when trying to handle the same hash change

How to fix jQuery window.on hashchange issue when clicking on the same hash? See the code snippet below for a potential solution: function addMargin() { let header = $('.header__wrapper').outerHeight(); let headerHeight = $('body& ...

When calling an API endpoint, nodeJS is unable to access the local path

I've encountered a strange issue with my code. When I run it as a standalone file, everything works perfectly fine. However, when I try to utilize it in my API endpoint and make a request using Postman, it doesn't seem to function properly. What ...

The Mobile Side Menu Is Not Scrollable

I've encountered an issue with the side menu on my website. While it works perfectly fine on PC, it refuses to scroll on mobile devices. I've tested it on both my iPhone 5 and iPad, but no luck. Additionally, the toggle button isn't function ...

Ways to retrieve "this" while utilizing a service for handling HTTP response errors

I have a basic notification system in place: @Injectable({ providedIn: 'root', }) export class NotificationService { constructor(private snackBar: MatSnackBar) {} public showNotification(message: string, style: string = 'success' ...