A container with smaller divs that can be scrolled horizontally

Within my website lies a div container housing smaller divs that are arranged horizontally for horizontal scrolling. My intention is to have them appear as follows:

+-Container------------------+
| +-a-+  +-b-+  +-c-+  +-d-+ |
| |   |  |   |  |   |  |   | |
| +---+  +---+  +---+  +---+ |
+----------------------------+

However, the actual layout currently looks like this:

+-Container------------------+
| +-a-+         +-c-+        |
| |   |  +-b-+  |   |        |
| +---+  |   |  +---+  +-d-+ |
+----------------------------+

Upon reviewing the CSS code provided below:

#a,#b,#c,#d{
    display: inline-block;
    margin-left: 2.5%;
    height: 450px;
    white-space: normal;
}
#container{
    display: block;
    margin: auto;
    overflow-x: auto;
    white-space: nowrap;
    height: 450px;
}

It appears that the top space within each box is influenced by its content (based on experimentation). Is there a method to ensure the boxes remain anchored to the top of the container during horizontal scrolling? Should this behavior be occurring in the first place?

Answer â„–1

To ensure proper alignment, it is important to adjust the default vertical align value from baseline to top.

#a, #b, #c, #d{
  vertical-align: top;
}

For more information, you can refer to: vertical-align

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

Using PHP and AJAX to send a form

Currently, I am attempting to integrate ajax functionality into my form in order to submit it without refreshing the page. However, I have encountered an issue with the php echo command not functioning as expected. When I remove the ajax code, the form s ...

Struggling with transferring a value between two input fields using jQuery

I'm currently working on a project to create a simple "to-do list" and I've encountered an issue that seems pretty basic. I am trying to pass the main input from #myInput at the top, down to the next line below, but I'm facing some challenge ...

Troubleshooting problem with SVG icons not highlighting correctly when clicked on mobile devices

I recently incorporated SVG icons into my website. However, when I tap on them using a mobile browser, the browser highlights the icon. Is there a way to disable this highlighting effect? Example: highlight Code: <div class="ictg-before"> <svg ...

How to position Bootstrap 4 navbar to the right side

I recently started using the latest version of Bootstrap for a personal project. While working on creating a navbar, I encountered an issue with aligning the links to the right. Despite my efforts to find a solution, I have been unable to figure out how to ...

Unable to implement CSS styling on Bootstrap collapsible menu

When you visit this website and resize the browser window to reveal the toggle buttons, clicking on either one will only expand the dropdowns to a small portion of the screen width. I would like both dropdowns to stretch out and fill 100% of the available ...

What is the best way to create a table row when there is no data available?

<?php include "db.php"; if ($_SERVER["REQUEST_METHOD"] == "POST") { $search_date = $_POST['search']; } $show_result = mysqli_query($con, "SELECT * FROM data_input where input_date = '$search_date' "); ...

Suggestions for retaining buttons functionality during drag and drop operations using jQuery UI?

My goal is to create new preset buttons when a button is dropped into the "timeslot" div. However, I am struggling to achieve this and ended up creating a function called "init()" which removes all existing buttons and generates new preset buttons every ti ...

What is the best way to transmit success and failure alerts using ajax?

I've integrated MailChimp's API into my system, allowing me to subscribe email addresses by sending them to a specific URL. When an email is submitted, MailChimp responds with either a success or failure code. For example: myurl.com/[email  ...

developing a popup window using HTML

I'm looking to incorporate a popup or alert window that displays a URL. For example: alert(localhost:2828\index.html); I feel like I've come across this feature before. It would be great if there's a bootstrap option available as wel ...

How to redirect a form submission using jQuery

Is there a way to make this code work upon submission instead of on click? This is the form I am working with: <form> <input type="radio" name="value" value="http://google.com"><span>Google</span><br> <input type= ...

Only the first column of a row in Flexbox will have a line break when exceeding the

Currently, I am utilizing flex with a row direction for a set of items with fixed widths causing overflow and a horizontal scrollbar, which is the desired outcome. Nevertheless, my requirement is for the first column in these rows to be full-width, while ...

What is the best way to loop through every header tag within a designated div container?

Is there a way to cycle through all the header tags within a specific div tag? I am looking to automatically generate a document map tree for everything inside my div tag and display it in a sidebar menu... If there is a user-friendly javascript library av ...

Clicking again on the second onclick attribute

I have an image file named image1.png. When the button is clicked for the first time, I want it to change to image2.png. Then, when the button is clicked for a second time, I want it to change to yet another image, image3.png. So far, I've successful ...

Guide on designing a form for generating custom URLs

I have a form on my website that generates a URL, but it requires the user to wait until the entire page is loaded in order to function properly. I believe this is because I am using window.onload and should switch to using $(document).ready instead. How ...

Is it possible for you to pinpoint the mistake in the code below?

I've been trying to locate an error in the function but have been unable to do so. As a beginner in this area, I would appreciate your patience. <html> <head><title>print names</title> <script langua ...

hover effect with fading transition while mouse is still hovering

Is there a way to create a fade-in/fade-out effect on a div without the mouse needing to leave the area? Let me provide a clearer explanation: When the mouse enters the object The object gradually fades in Then, after a delay, the object fades out while ...

remove a section from the main body

body { display: flex; justify-content: center; align-items: center; background: #0e1538; } <canvas id="spaceholder" width="804" height="604"></canvas> </div> <div class="MenĂ¼Center"> <canvas id="canvas" width="800" ...

What is the reason for Angular Material using pixels to measure fonts?

We are in the process of developing an Angular Material application, and our designer has requested that we convert all CSS styles to be measured in em units. He believes that using px will require multiple styles for different media query breakpoints. Cur ...

The opacity attribute in CSS is not producing the desired outcome

After numerous attempts, I have yet to successfully create the desired effect on the screen I am currently working on: https://i.sstatic.net/BonQa.png My goal is to achieve a transparent effect using a gradient as a background, but so far my efforts have ...

Issue with bootstrap 4: Specific column grid not displaying scroll-bar on overflow

I'm working with 3 columns inside my main tag (<main role="main" class="container">). The first column contains a table with multiple rows. I'm trying to make this column vertically scrollable while keeping it extended between the header an ...