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.

div margin

Featured Replies

I've created a div over another div. The top div has a margin-bottom: 0px; The bottom div has a margin-top: 0px;

Why is there about 15 px between them?

Edited by gigman7

btw instead of using a png  for the background to your nav ,you could use a css linear gradient and then with a border 1px solid white for the top

20 hours ago, davep said:

btw instead of using a png  for the background to your nav ,you could use a css linear gradient and then with a border 1px solid white for the top

Being a bit pedantic but you can do all that just the linear gradient with a hard stop.  Removes the need for a border taking up space.

Edited by rbrtsmith

1 hour ago, rbrtsmith said:

Being a bit pedantic but you can do all that just the linear gradient with a hard stop.  Removes the need for a border taking up space.

nothing wrong with a bit of pedantism :) i did think about that after posting actually but didn't want to hog all the glory ;)

 

  • Author

Why did the creators of the css world not make a margin 0 actually be 0? I'm still having trouble with a margin-bottom:0 and a margin-top:0 not be margins of 0. I guess logic wasn't something they were considering.

If you look on my vacation guide page, there's a big gap between the top nav and the main content.

8 hours ago, gigman7 said:

Why did the creators of the css world not make a margin 0 actually be 0? I'm still having trouble with a margin-bottom:0 and a margin-top:0 not be margins of 0. I guess logic wasn't something they were considering.

If you look on my vacation guide page, there's a big gap between the top nav and the main content.

By default all browsers have their own slightly quirky display, for example the body has a margin as standard. If you're having trouble I'd suggest looking with developer tools in Chrome as it will highlight issues.

Taking the issue with margin, it can be written many ways, e.g. these are all the same;

.margin { margin-top: 10px; margin-bottom: 10px; margin-left: 15px; margin-right: 15px; }
.margin { margin: 10px 15px 10px 15px; } /* top / right / bottom / left */
.margin { margin: 10px 15px; } /* top and bottom / left and right */

with your css you could write for instance ...

header {
	width: 70%;
	margin: 0 auto;
	padding-top: 0;
}

instead of

header {
	width: 70%;
	margin: auto;
	margin-top: 0px;
	margin-bottom: 0px;
	padding-top: 0;
}

 

On 7/11/2018 at 12:36 AM, gigman7 said:

Why did the creators of the css world not make a margin 0 actually be 0? I'm still having trouble with a margin-bottom:0 and a margin-top:0 not be margins of 0. I guess logic wasn't something they were considering.

If you look on my vacation guide page, there's a big gap between the top nav and the main content.

Setting margin to zero will result in it being zero unless you are overriding it somewhere.

Why criticise the creators of CSS, when the issue you are having (no offence) is down to your own lack of understanding of the spec?

Edited by rbrtsmith

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.