Solved

centralising a div over my 'mask'

Posted on 2008-10-09
4
392 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

So you have coded your own WordPress plugin and now you want to allow users to upload images to a folder in the plugin folder rather than the default media location? Follow along and this article will show you how to do just that!
CSS is a visual language used to classify objects and define rules about how they should be displayed. CSS skills aren’t restricted to developers anymore, there is a big benefit to having a basic understanding of the language, regardless of your occ…
In this tutorial viewers will learn how add a full-size background image to a webpage using CSS3. Create a new HTML document with an internal stylesheet.: In CSS, define the html element to have a background image. Use a high resolution image.: In t…
In this tutorial viewers will learn how to style rounded corners for elements in CSS using the border-radius property Begin with a normal styled element such as a div: To style all four corners of the div to be the same degree of roundness, use the …

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now