Solved

centralising a div over my 'mask'

Posted on 2008-10-09
4
398 Views
Last Modified: 2008-10-14
In question:
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/CSS/Q_23743018.html

i was looking for a 'mask' that covered the whole of my page.

I am now working on the div to go on top of the mask that will display the data.

I dont seem to be able to centralise the div.

I thought margin auto would sort it but it doesnt seem to be workin.

This is my div:
<div runat="server" id="floatingDivDisplay" visible="true" class="more_info_div">
           
            </div>

and the class:
.more_info_div {
      padding:30px;
      margin:0 auto;
      background-color:#fff;
      width:800px;
      border:solid 2px #016bd1;
      z-index:100;
      position:fixed;  
      top:50px;
      left:auto;
      right:auto;
}

i have also attached a screen shot of how it is looking at the moment.

Can anyone tell me what i am missing to be able get this centralised?
0
Comment
Question by:scm0sml
  • 2
4 Comments
 
LVL 6

Expert Comment

by:carazuul
ID: 22682276
Hi scm0sml,
You have the right idea, but to center a div you need to specify auto for the left and right margins specifically. So, remove margin: 0 auto; and replace it with margin-right: auto; and margin-left: auto.
Regards,
carazuul
0
 

Accepted Solution

by:
scm0sml earned 0 total points
ID: 22682382
mmm tried that now but it doesnt seem to be working.

i got it working in the end using the following:
left:50%;
then bringing the div back to the left by half of the divs length using:
margin-left:-425px;

this is now working a treat :)

cheers anyway
0
 
LVL 6

Expert Comment

by:carazuul
ID: 22682471
That's a good work-around too :-)
0
 
LVL 42

Expert Comment

by:David S.
ID: 22682875
Auto left and right margins don't seem to work on absolutely or fixed positioned elements.

The drawback to using the left:50% and negative left margin centering technique is that if the viewport isn't wide enough, some of the element will stick of the left side of the page and users won't be able to scroll to it.

@carazuul:

margin: 0 auto;

is the shorthand for this:

margin-top: 0;
margin-bottom: 0;
margin-left: auto;
margin-right: auto;

These are well worth reading:
http://www.communitymx.com/content/article.cfm?cid=90F55
http://www.456bereastreet.com/archive/200502/efficient_css_with_shorthand_properties/
http://www.tyssendesign.com.au/articles/faqs/what-is-shorthand-css/
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

As a result of several questions about how to use Bootstrap I thought it would be a good idea to write down the development aspect of creating a Bootstrapped website in as little time as possible. Part 1 of this article will only concentrate on g…
This article discusses four methods for overlaying images in a container on a web page
In this Micro Tutorial users will learn how to embed custom fonts into websites using @font-face in CSS Select a font: Ensure the EULA allows you to use @font-face: Download the font: Get the browser-compatible files you need: Edit your CSS       - Name …
In this tutorial viewers will learn how to style a decorative dropcap for the first letter in a paragraph using CSS. In CSS, create a new paragraph class by typing "p.fancy": Then, to style only the first letter of the first sentence, include the ps…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question