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.

Negative Margin Bug

Featured Replies

Hi folks.

 

I've came across a little problem on with a site i've been working on, infact, the same problem on a couple of sites and i'm just wondering if there is a way around it.

 

I've used the, pretty common method of centering my site by using

 

position:absolute; left:50%; margin-left:'minus half the width of the div'

 

The problem is...if the windows width is reduced to anything below 'width of the div' the left hand side of the page begins to cut off, and because you can only scroll right, the content is essentially useless.

 

Is there a way i can fix this.

 

Maybe using javascript or something (my knowledge of javascript is limited, but i thought something like this might be along the lines of what i need?

 

lets say the width of the div needing centered is 1000px

<script>
function setMargin()
var width =document.documentElement.­clientHeight/Width;
var difference = 1000 - document.documentElement.­clientHeight/Width;
if (width < 1000) { document.getElementById('the_div').object.style.marginLeft = difference;} 
else {document.getElementById('the_div').object.style.marginLeft="-500";}
</script>

 

The site i'm working on just now can be viewed At this location

Reduce the window size and you will see my problem.

 

Maybe javascript isnt the way to fix it, so any suggestions would be much appreciated.

 

Thanks.

Yes to centre a site use:

 

	

#wrapper {
       width: what ever height in px/ %;
margin-left: auto;
margin-right: auto;
}

 

This will centre your website. - You will need to use text-align: center for ie6 and older but just redeifne left on the wrapper container!

  • Author

AAaach, thanks adam.

 

I did try that earlier, but never took out the position:absolute 's so it stayed the same.

 

[slaps head]

 

Thanks.

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.