"Ascend to the left"? Begin divs at the top of the container and expand downwards

I have a big container with smaller boxes in it. Here is how it currently appears: https://i.sstatic.net/HBEgZ.png

However, I would like it to appear like this: https://i.sstatic.net/YqIVf.png Basically, I want all the boxes inside the "container" to move up and left instead of down and left. Maybe using float isn't the right approach. How can I solve this problem?

You can view it yourself here: https://jsfiddle.net/sebastian3495/ea6L08bu/9/

HTML

<div class="container">
  <div class="box" style="background: yellow;"></div>
  <div class="box" style="height: 200px;background: brown;"></div>
  <div class="box" style="background: green;"></div>
  <div class="box" style="background: purple;"></div>

</div>

CSS

.container {
  background: red;
  width: 500px;
  height: 500px;
  border: 2px solid black;
  overflow: hidden;
}

.box {
  display: inline-block;
  height: 100px;
  width: 100px;
}

Answer №1

When utilizing the inline-block property, it is important to apply vertical-align:top

.container {
  background: red;
  width: 500px;
  height: 500px;
  border: 2px solid black;
  overflow: hidden;
}

.box {
  display: inline-block;
  height: 100px;
  width: 100px;
  vertical-align: top;
}
<div class="container">
  <div class="box" style="background: yellow;"></div>
  <div class="box" style="height: 200px;background: brown;"></div>
  <div class="box" style="background: green;"></div>
  <div class="box" style="background: purple;"></div>

</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

Converting a Three.js Vector3 to 2D screen coordinates while considering a rotated scene

I need help positioning a div so that it is always at the highest point of an object, slightly offset to the left and up from the vertex. You can check out the example here. If the jsfiddle link is not working, refer to the working with no scene rotation s ...

Utilizing the after pseudo element for an active selector in CSS

I'm struggling to make an active icon selector work with the after pseudo element. Here is the code I have attempted: <html> <head> <style type="text/css"> .btn{ width:25%; } .name{ background: #fff; color: #000; text-alig ...

What steps do I need to take in order to host my webpage on my Mac's localhost?

Currently, I am developing a webpage and I want to test how it appears on my iPhone's Safari browser. Since the project is still in the development stage, I don't plan on purchasing a domain or hosting just yet. My goal is to temporarily view it ...

Retrieve information from server using JavaScript/jQuery and present it on the page

Imagine having a JavaScript file stored in a specific directory on your computer. In that same directory, there is a folder named 'server' which contains three text files. Now, the task is to showcase all three text files (from the 'server& ...

Tips for overriding ng-disable in AngularJSUnleashing the

This is a comment box using AngularJS: <tr> <td colspan="5"><br/>Comments* <div><textarea class="form-control" rows="3" cols="60" ng-model="final_data.drc_scope" placeholder="Add comments here" ng-disabled="is_team==0 || isDis ...

Activate the selected image on click and deactivate all other images

Looking to use Javascript onclick to create an event where the clicked image is enabled and others are disabled. For instance, if there are 6 pictures, how can I achieve this: Clicking on any picture, let's say number 3, will enable that picture whil ...

Exploring the possibility of converting the text input into an option input to customize taxation settings

Currently developing a checkout system with tax implementation. My business qualifies for Nexus, so I will only charge sales tax in the state where my business is located. As of now, the customer inputs their state by typing text. I plan on converting this ...

Invoke the ngOnInit method in Angular 7 or any other method within the component itself

My current dilemma involves a component named user-table-list, which essentially represents a table with entries corresponding to various users. Within this setup, there exists another component called table-list, responsible for defining the structure a ...

Bootstrap for handling screen rotation and responsive design

Utilizing bootstrap to showcase canvas thumbnails within a div for lighter client-side creation. While not the perfect design, it's functional. An issue arises when viewing the app on a mobile device in portrait mode - the col-xs-6 class remains fixe ...

display a dual-column list using ngFor in Angular

I encountered a situation where I needed to display data from an object response in 2 columns. The catch is that the number of items in the data can vary, with odd and even numbers. To illustrate, let's assume I have 5 data items to display using 2 co ...

UI thread was blocked due to withProgress being invoked from an external library function

Currently enhancing an extension that is almost finished, but facing a challenge in adding visual cues for lengthy operations. Initially suspected a missing async/await in the code, but struggling to identify the cause. The progress indicator isn't di ...

Gather information from various Mongoose requests and forward it to the specified route

Recently embarked on my journey of learning Express with the help of online resources. While I have been able to handle pages dependent on a single query, I have hit a roadblock when it comes to creating a pagination table. In this scenario, I need to exec ...

Change Google Map to a static image for downloading with the help of jQuery

One of the features on my website is a dynamic GoogleMap with markers and MarkerClusterer functionality. I am looking for a way to enable users to download an image of the map view, including all zooming, moving, and marker locations. So far, attempts to ...

Unable to reset HighCharts Speedometer value to zero

I am currently experimenting with implementing the highcharts speedometer. The goal is to simulate a connection meter - when there is a good connection, the meter should display values between 30 and 100. If the connection result from an Ajax call is any ...

The jQuery .each function is malfunctioning specifically on Google Chrome browsers

I developed a web application that utilizes jQuery to automatically submit all forms on the page. The code snippet is as follows: $('form').each(function() { $(this).submit(); }); While this functionality works perfectly in Internet Explore ...

Using Reactjs to create a custom content scroller in jQuery with a Reactjs twist

I am attempting to implement the Jquery custom scrollbar plugin here in my React project. Below is a snippet of my code: import $ from "jquery"; import mCustomScrollbar from 'malihu-custom-scrollbar-plugin'; ..... componentDidMount: function() ...

Retrieve the XML file from the webpage and save it to a specific directory using Java and the Selenium framework with the Chrome browser

Retrieve xml file from the website and save it to a specific location using java or selenium with Chrome browser. Here is the snippet of HTML code: <!-- Start of Code which handles XML Download--> <a href="javascript:downloadXML()"> <img s ...

Error message: ".then uncaught in promise with undefined value"

myFunction() { this.initiateTSOAddressSpace().then(this.launchApp); return "placeholder text"; } sendData(contentURL: string) { let response = fetch(contentURL, { method: "POST", credentials: "include", headers: {"Accep ...

How to arrange an array of objects by a property within a nested object using JavaScript?

var originalArray = [ { name: 'Shop1', stock: [ { name: 'Apples', quantity: [{ id: "something", time: 11 }, { id: "something", time: 44 }, { id: "something", time: 53 }] }, ...

Patience is key when using HTML 5's drawImage function in a Vue single-page application

For the past week, I have been troubleshooting an issue and it seems like the problem lies in the drawImage function not completing in time. Within a for loop, I am combining two different canvas elements to create a new canvas called composedCanvas, which ...