How to efficiently center and adjust the size of a div-wrapper containing multiple responsive divs

I could use some assistance with this particular issue.

What's been successful so far:

I have a large div within my body (and also inside main, for css-related reasons), housing eight smaller divs divided into four columns. I've applied float:left; to the divs to display them side by side. Alternatively, I could achieve the same result using display:inline-block;. The large div has a width of 100%, and the smaller divs are intended to automatically occupy this full width. Among the four columns, two comprise a single div each with height:100%;, while the other two incorporate two divs stacked vertically, each div having height:50%.

Challenges faced:

I'm aiming to maintain these divs seamlessly aligned next to each other without any line breaks, regardless of screen resolution or device orientation.

Therefore, I seek guidance on horizontally centering the large div (and potentially vertically) – I can't seem to understand why margin:0 auto; isn't functioning as expected here. Moreover, I would appreciate insights into why responsive resizing of the divs to fill 100% width of the outer div in correspondence to viewport dimensions is not operational, or where I may be going wrong.

EDIT: The internal divs (containing images) should only scale proportionally; if the viewport height is insufficient compared to the image height, the outer div must be scaled down horizontally. Essentially, I want all divs to be displayed alongside each other in their accurate proportions across varying resolutions/orientations.

PS: The widths of the four columns do not consistently equate (not all are set at 25% of the outer div).

Access the jsfiddle link below:

http://jsfiddle.net/hLzoxmyb/1/

HTML code snippet:

<body>
    <main>
        <div id="wrapper">
            <div id="one">
                <figure id="one">
                    <img src="01.png" alt="01">
                </figure>
            </div>
            <div id="two">
                <figure id="02">
                    <img src="02.png" alt="02">
                </figure>
                <figure id="03">
                    <a href="03.html"><img src="03.png" alt="03"></a>
                </figure>
            </div>
            <div id="three">
                <figure id="04">
                    <a href="04.html"><img src="04.png" alt="04"></a>
                </figure>
                <figure id="05">
                    <a href="05.html"><img src="05.png" alt="05"></a>
                </figure>
            </div>
            <div id="four">
                <figure id="06">
                    <a href="06.html"><img src="06.png" alt="06"></a>
                </figure>
            </div>
        </div>
    </main>
</body>

CSS code excerpt:

body {
    background-color:#cccccc;
    font-family: monospace;
    font-size:120%;
    margin:0;
    padding:0;
    width:100%;
}

div#one figure, div#four figure {
    height:80%;
    height:80vh;
}

div#two figure, div#three figure {
    height:40%;
    height:40vh;
}

figure {
    margin:0;
    padding:0;
}

div#wrapper {
    padding-bottom:10%;
    padding-bottom:10vh;
    padding-top:10%;
    padding-top:10vh;
}

div#wrapper div {
    float:left;
}

div#wrapper div figure img, div#wrapper div figure a img {
    height:100%;
}

main {
    /*
    bottom:0;
    display:block;
    left:0;
    margin:auto;
    max-height:100%;
    max-height:100vh;
    max-width:100%;
    max-width:100vw;
    overflow:auto;
    position:fixed;
    right:0;
    top:0;
    */
    margin:0 auto;
    width:100%;
}

Answer №1

Using display: inline-block; and white-space: nowrap; will position them next to each other without wrapping around.

Check out this example on jsFiddle

I'm a bit confused about the second part of your question. Please provide more details so I can update my response.

Edit: By adding some percentage width rules, you can prevent scrolling by adjusting the size of the content inside #wrapper.

See the updated example here

Edit: If you specify the width of #wrapper and use margin: 0 auto;, it will be centered on the page.

View the centered wrapper on jsFiddle

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

Utilizing CSS grid layouts to ensure images expand to fit the dimensions of the designated column and

I am currently working with a CSS grid layout that is displaying as follows: .image__gallery-grid { max-height: none; grid-template-columns: repeat(4, minmax(0, 1fr)); grid-template-rows: repeat(2, minmax(0, 1fr)); gap: 2.5rem; dis ...

When you hover over HTML tables, they dynamically rearrange or shift positions

Issue: I am encountering a problem with multiple tables where, upon hovering over a row, the tables are floating rather than remaining fixed in place. Additionally, when hovering over rows in the first or second table, the other tables start rendering unex ...

Organizing and Arranging List Elements (li)

Imagine having this list: <ul> <li>item1</li> <li>item2</li> <li>item3</li> <li>item4</li> <li>item5</li> <li>item6</li> <li>item7</li> <li>item8</li> ...

Explore the Shopify assistance on the secondary blog section within a separate page

Hey there, I'm looking for someone who is familiar with Shopify and can assist me. I am currently trying to set up a secondary Blog section on a separate page from my default 'Blog Page', but I'm encountering issues in displaying the a ...

Is it possible to maintain HTML, JS, and CSS files as separate entities when developing Vue.js components, similar to how it is

Is it possible to maintain separate HTML, JS, and CSS files while creating Vue.js components? I recently read the "Why Vue.js doesn't support templateURL" article which discusses this topic. "Proper modularization is a necessity if you want to bu ...

Issue with content not wrapping inside the body tag (apart from using float or setting body and html to 100

Why on earth is the body/html or .main div not wrapping my .container div's when the browser width is between 767-960 px?! This is causing horizontal scrolling and I am completely baffled. This should definitely be working! The only code I have is: ...

Is it possible to have a PHP variable embedded within an HTML link tag?

<?php $message = ' <a href="' . $link . '">here</a> '; ?> My goal is to include a clickable link in the $message variable for use in the mail() function. However, despite setting $link with the desired link string, it ...

Retrieve information following an Ajax call inside a pre-designed template

Upon rendering a page with data put together by EJS, the goal is to refresh a section (thirdRow) of the page whenever the user submits new data. The refreshed section should display both the newly submitted data and the existing data. Although I have obtai ...

Is there a way to control the quantity of items being displayed in my ng-repeat directive?

Here are the objects in my array: 01-543BY: Array[1] 03-45BD23: Array[1] 03-67BS50: Array[1] 06-78FR90: Array[1] 07-467BY3: Array[1] 09-23DF76: Array[1] Currently, I have a total of six objects, but I only want to display four. This is how I am using ng- ...

How can I control audio playback with just a click on an image on an HTML webpage?

I attempted to use a code from this website, but it doesn't seem to be working for me. I was hoping that someone here could lend a hand. The code I tried makes the song play when I click the gif image, but when I click it again, it just restarts. H ...

Issue with Django URLs: Error when trying to match routes

I have recently made changes to some of the URLs in my app, and now I am encountering an error when trying to render my index page. Can someone help me identify the issue? I have already checked for typos in my HTML file. The error message I am receiving i ...

How can you hide all siblings following a button-wrapper and then bring them back into view by clicking on that same button?

On my webpage, I have implemented two buttons - "read more" and "read less", using a Page Builder in WordPress. The goal is to hide all elements on the page after the "Read More" button upon loading. When the button is clicked, the "Read More" button shoul ...

What is the process of compiling HTML code?

In controller, I bind the same data like $scope.name = "<div>geetha teko</div>", this name will now be bound to the HTML like {{name}}. When I view it in the browser, it prints as "<div>geetha tek0</div>". Is there a way to only di ...

Rearrange the entire div container by simply dragging and dropping it. (Shift the Pop-up Modal dialog box)

How can I make a Modal pop-up draggable and change the color of the "Ok" and "Cancel" buttons on hover using a single CSS class? .hidModal{ position: fixed; font-family: Arial, Helvetica, sans-serif; top: 0; right: 0; bottom: 0; ...

AngularJS Encounter: A Grand 404 Glitch

Hey, I'm just getting started with AngularJS and following this helpful tutorial. However, I've run into an issue where the $http.get method is consistently giving me a 404 Error when trying to access a JSON file. The JSON file is located in the ...

Is there a way to replace the default Laravel pagination CSS class with a custom theme CSS class?

Is there a way to update my Laravel pagination CSS to match my theme's CSS? I need help with this adjustment. Here is the HTML for the theme's CSS: <div class="row mt-5"> <div class="col text-center"> ...

Sending values from buttons to different Django templates/views

Initially, the user provides a CSV file. (Template File:) <form method="post" action="{% url 'rowcol' %}" enctype="multipart/form-data"> {% csrf_token %} <input type="file" name="file" accept=".csv"> <button type="sub ...

What steps can I take to modify this script in order to display one image on top of another?

I am working on a script that creates cross fades for images. However, I have some text images that I would like to appear as fading in on each image transition. This means that when the first image appears, it will pause, then the text image will fade i ...

Implementing the Upload Feature using AngularJS

Currently, I'm facing a challenge in implementing an upload button on my webpage using AngularJS and Bootstrap. Specifically, I am having trouble assigning the (upload) function to that button in AngularJS. The goal is for the button to enable users t ...

Excessive CSS overflowing content may result in the appearance of horizontal scrollbars

Looking for help with building a jQuery panel slider on my website. I am not very experienced with JS/Javascript and cannot seem to get rid of the horizontal scrollbar on my site. Check out the demos here! The sliders are located within the Gallery and F ...