Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

centralising a div over my 'mask'

Posted on 2008-10-09
4
Medium Priority
?
406 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 43

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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

When applying CSS to your HTML, there are many different ways to select which element(s) the CSS applies to.  Some of these selectors are more commonly known and used than others - Here are the more common ones: #X - Matches an ID of X .X - Matche…
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 to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
Suggested Courses

670 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