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.

Help with a simple layout.

Featured Replies

Hello.

 

I experimented all morning with different types of layouts and I seem to have stumbled upon this problem.

 

Here's what I have so far: http://pastebin.com/5qtPi7ff . Please load it in your browser. :)

 

I don't know if you could tell, but I want the black box to be just below those green boxes.

 

Sure, I could use relative or absolute positioning, but I feel like that's not a very good practice because the size of the green box could change anytime new content is added inside of it.

 

So. Is there a simple way to tell the browser to display the black box just below the green ones? (something like overflow: hidden or clear)

Edited by stevefai

<!doctype html>
<html lang="en">

<head>
	<meta charset="UTF-8">
	<title>Exercise</title>
	<style type="text/css">
		body {
			margin: 0;
		}

		.wrap {
			height: 960px;
			width: 960px;
			background: #555555;
			margin: auto;
			margin-bottom: 80px;
			position: relative;
			top: 40px;
		}

		.greenbox {
			width: 100%;
			background: #00FF7F;
			top: 60px;
		}

		.gbox {
			float: left;
			width: 300px;
			height: 160px;
			background: #00C462;
			margin-left: 15px;
			margin-top: 20px;
			margin-bottom: 20px;
		}

		.blackbox {
			width: 615px;
			height: 360px;
			background: black;
			display:inline-block;
		}

	</style>
</head>

<body>

<div class="wrap">
	<div class="greenbox">
		<div class="gbox"></div>
		<div class="gbox"></div>
		<div class="gbox"></div>
	</div>
    <div style="clear:both"></div>
	<div class="blackbox"></div>
</div>

</body>

</html>

something like that?

Edited by inlinedivblock

looks like he will want the clear:both in the greenbox div like so rather then just before the black box, otherwise the light green background does not show

<div class="wrap">
	<div class="greenbox">
		<div class="gbox"></div>
		<div class="gbox"></div>
		<div class="gbox"></div>
		<div style="clear:both"></div>
	</div>
	<div class="blackbox"></div>
</div>

Edited by D4Y0

 

looks like he will want the clear:both in the greenbox div like so rather then just before the black box, otherwise the light green background does not show

<div class="wrap">
	<div class="greenbox">
		<div class="gbox"></div>
		<div class="gbox"></div>
		<div class="gbox"></div>
		<div style="clear:both"></div>
	</div>
	<div class="blackbox"></div>
</div>

agreed ...

  • Author

Thanks a lot, guys.

This wasn't exactly what I had in mind, but your solutions are better. :D

Edited by stevefai

  • Author

no worries, there is more that one solution :) were you trying to do it with less code?

I was trying to leave this bit of code untouched:

  1. greenbox {
  2. width: 100%;
  3. background: #00FF7F;
  4. position: absolute;
  5. top: 60px;
  6. }

The solution provided by you gets rid of the absolute positioning (hence the "top: 60px;" bit doesn't work).

But I figured I don't need that extra space of 60px anyway. :)

Edited by stevefai

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.