Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Row with 3 columns. 3 Divs with different background image

Featured Replies

Hi,

I'm trying to build a layout which consists of one parent row with 3 child divs within it.

The 3 child divs have a different image which I need to fit as a background image and they need to be responsive also.

So on the child divs I set the over flow to Visible.  And the same Visible overflow on the parent div.

As you will see, the background images don't scale responsive as you reduce the size of the browser window - until they hit the media query.

And the overflow for the parent div (with the yellow border) doesn't seem to be scaling in height to hold the child divs.

Here's the code I'm using:

 


<!DOCTYPE html>
<html lang=en>
<head>
<meta charset=utf-8>
<meta http-equiv=X-UA-Compatible content="IE=edge">
<meta name=viewport content="width=device-width, initial-scale=1">
<title>Row problem</title>
<link rel="shortcut icon" href="img/favicon.ico"/>
<style media=screen type=text/css>html{height:100%;color:#37474f;padding:0;margin:0;font:400 15px/1.8 "Lato",sans-serif;color:#777}
	
	
	

.parentrow{
position:relative;
background-color: 
rgba(255, 255, 255,0.7); 
background: rgba(255, 255, 255,0.7);
width:95%;
min-height:120px;
overflow: visible;
padding:0 8px 0 8px;
border:2px solid blue;
margin: 20px auto 20px auto;
text-align: center;
border: 3px solid yellow;
}

.image1 {
position:relative;
	float: left;
	width: 32%;
min-height:334px;
	background: url("img/image1.jpg") no-repeat;
	  background-size:cover;
	  background-position:center;
	  overflow: visible;
	margin: 0;
	border: 3px solid green;

	}
	
	
	.image2 {
position:relative;
	float: left;
	width: 32%;
min-height:334px;
	background: url("img/image2.jpg") no-repeat;
	  background-size:cover;
	  background-position:center;
	  overflow: visible;
	margin: 0;
	border: 3px solid orange;

	}
	
		.image3 {
position:relative;
	float: left;
	width: 32%;
min-height:334px;
	background: url("img/image3.jpg") no-repeat;
	  background-size:cover;
	  background-position:center;
	  overflow: visible;
	margin: 0;
	border: 3px solid red;

	}
	
@media only screen and (max-width : 700px) {

		.image1 {
position:relative;
		width: 100%;
	}
			.image2 {
position:relative;
		width: 100%;
	}
	
			.image3 {
position:relative;
		width: 100%;
	}


}



</style>
</head>
<body>

<div class=parentrow>
  
						<div class="image1"> 	</div>
						
						<div class="image2"> 	</div>
						
						<div class="image3"> 	</div>
						
</div>





</body>
</html>

I've attached 3 demo images if that helps.

Any advice really appreciated.

Thanks

image1.jpg

image2.jpg

image3.jpg

You can do this with display: inline-block just fine, I wouldn't use floats for something like this though. The issue is that the height of a background image isn't known, you will need to add a height to each row and change it on your media queries. It also sounds like you need to use background-size: cover to get the images to scale inside each column. Here's an example.

One other thing... You have a lot of duplication in your CSS that can be avoided by abstracting out to classes. Whenever I see CSS like this I think it's bound to cause bugs because you need to update your code in multiple places. You would be better of having a grid system that can be used across the site and style your components out separately, abstracting when needed.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.