Container automatically resizes to fit the width of an image, while ensuring all other buttons and elements remain neatly enclosed within

My website consists of four main sections, each with a background image of the same size. These images contain important elements that I always want to be visible. Initially, the images would resize based on the browser window size, but a recent CSS cleanup project changed that so they always display at 100% height. This adjustment worked perfectly, until I realized that changing the browser window height caused the elements to spill out of the four main sections. This issue arose because the document only specified the height at 100vh, with no width specified for any section.

Is there a simple solution to this dilemma? I need to set boundaries for the inner divs and buttons by defining a right and left border for the page, while still maintaining the 100% vertical height of the four main sections. The current CSS properties being used for the divs are:

            background-attachment: fixed;
            background-size: cover;
            background-repeat: no-repeat;
            min-height: 100vh;

Essentially, I require a container that surrounds the four main sections, expanding to the width of the images while allowing them to resize with the window. This container should also keep all buttons and divs contained within it.

You can view the page here: view-source: The current setup works well, but the buttons overflow the sides if the browser window height is too short.

Answer №1

Big shoutout to Justin for the guidance. After some reconsideration, I decided to revamp the design strategy. I was keen on maintaining the background collages concept while ensuring a responsive layout. To achieve this, I repositioned the homepage logo from the background image to the banner section. I also reorganized the collage elements, placing the key components in the center and the less significant ones to the sides to avoid cropping issues. Additionally, I opted to eliminate the rounded text boxes in sections 1 and 3, replacing them with succinct landing page text in a sleek font size and focusing the bulk of the content in sections 2 and 4. Although the text additions are pending, you can view the updated background and banner design at

A valuable lesson learned from this experience, applicable beyond my specific situation, is that when incorporating crucial information in a background image on a responsive site, ensure the important elements are centered to avoid potential cropping at the edges.

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

Browser inconsistencies result in varying appearance of Bootstrap selection in Firefox and Chrome

Issue with Bootstrap select rendering in Firefox and Chrome: Firefox: https://i.sstatic.net/HWEcR.png Chrome: https://i.sstatic.net/GBuDP.png Looking for ways to make the two browsers render consistently, preferably in Chrome's style. This questio ...

What is the best way to resize an SVG to perfectly fit the parent div container?

I need to display multiple SVGs from various sources, each with different height, width, and viewbox. I want them all to render within a fixed height and width div, filling up the available space. How can I scale these SVGs to fit the container div? For i ...

CSS: Achieving Full Container Width Text with Respect to Another Container's Height

Hello, I am facing a very specific issue that I can't seem to resolve: I have two containers (ion-card) and I want them to always be the same height. I was able to achieve this by following the solution provided here: https://i.sstatic.net/he8O7.png ...

iOS - Streamline the process of iterating through subviews and retrieving a specific subset of UIViews

Exploring the implementation of a CSS selector traversal technique in Swift. Here's what I have so far: var CLASSNAME_HANDLE: UInt8 = 0 extension UIView { @IBInspectable var className: String { get { //code to get className ...

Material UI Grid Items not stretching to fill the entire available width

I'm currently working with a nested Grid system in Material UI, but the Grid items are only occupying a fixed width and leaving some empty space. The issue arises when this fixed space is used up and instead of adjusting their internal free space, the ...

Arranging particular placement

How can I position my links to the right of the second photo (opus1) and slightly below the first photo (coverPhoto)? I've tried various methods but haven't found a simple solution yet. <!DOCTYPE html> <html lang="en"> <head ...

The out directory is lacking Styled JSX integration for Next.js

I have a straightforward project in NextJs and I am looking to serve the files via NginX. Here are the dependencies listed in my package.json file: "dependencies": { "isomorphic-unfetch": "^2.0.0", "next": "^7.0.2", "next-routes": "^1.4.2", ...

Desktop media queries are functioning properly, yet experiencing issues on mobile devices

I've come across this same question multiple times, but the solutions I've found so far haven't been helpful. My media queries are working perfectly on desktop, but they don't seem to take effect on three different android devices. It&a ...

Having trouble with implementing checkbox hack syntax

I'm trying to achieve a unique effect where a label gets styled and a div gets revealed when a checkbox is checked. Surprisingly, I've managed to make one happen without the other in my attempts. Even though the CSS is consistent in both instance ...

Challenges arise with CSS alignment when adding d3.js charts to a webpage

I'm puzzled by the empty space that appears between the left column (highlighted in the image) and the header. This peculiar gap only seems to occur when the middle column is filled with a chart. I've scrutinized the code using Chrome Developer t ...

One-of-a-kind Design: Linear Gradient Background Image

Can you help me with Linear Gradient? Is it feasible to incorporate an actual image instead of just displaying a color like #000000 or #ffffff? background-image: -webkit-linear-gradient(30deg, #000000 50%, #ffffff 50%); In the scenario mentioned above ( ...

Problem with Internet Explorer

There seems to be an issue with the center content on this website. In Internet Explorer, a few letters are getting cut off by the sidebar. I've tried adding some extra margin to the right, but it didn't solve the problem. It's happening on ...

using dynamic CSS classes in a Vue app

I am currently in the process of developing a component with vuejs and tailwindcss. I have run into an issue where the colors for the background and text are not being applied properly. <template> <div :class="[isDark ? `bg-${color}-900 t ...

Customize the progress bar color in Bootstrap by setting a unique color to it

Is it possible to apply a custom color to the progress bar in Bootstrap that is not one of the standard options like success, info, warning or danger? I attempted adding the following code snippet to my bootstrap-theme.css file: .progress-bar-custom { b ...

Difficulty displaying SVG in Opera browser when using the Raphael JS library

Currently, I am experimenting with Raphael JS to create visually appealing SVG graphics on a webpage. You can view my progress at . Most browsers display the graphics properly except for Opera 11. In Opera, the graphics fail to render when clicking on any ...

Buttons containing two lines of text appear bigger compared to those with only one line of text, but it is essential for all buttons to be consistent in size with the single line buttons

I am facing an issue with the buttons on my website, as they seem to resize based on the amount of text present. When there are 2 lines of text, the buttons appear larger compared to those with just one line. How can I rectify this situation? Although thi ...

Automatically adjust the size of a parent div that houses two child divs

@media only screen and (min-width: 900px) { .map_left { display: inline; float:left; width: 100px; height: 100px; border: 3px solid green; } .map_right { display: inline; float:right; width: 100px; height: 100 ...

Differences in Behavior of jQuery Element Styles in Firefox and Chrome When Modals Are Visible

I'm new to working with jQuery and JavaScript. Currently, on my website, I have implemented several unique modal/popups that are activated using a CSS :target selector, which changes their display property to block. Additionally, I am attempting to us ...

Instructions for connecting a button and an input field

How can I connect a button to an input field? My goal is to make it so that when the button is clicked, the content of the text field is added to an array (displayed below) const userTags = []; function addTags(event) { userTags.push(event.target.__ wha ...

Guide on eliminating flex in CSS

Having an issue with aligning two grids created in HTML using Bootstrap. Below is the code: <!DOCTYPE html> <html lang="en"> <head> <title>IRIS Flower Classification</title> <link rel="stylesheet" href="{{ url_for( ...