Solved

centralising a div over my 'mask'

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
alert on input text 2 42
Navigation Menu Does Not Show on iPad 4 60
CSS - how to make button/link change to black on hover? 2 35
Display Flex does not Wrap Items 2 46
Creating a CSS block that only applies to printing By default, all of your CSS applies to every possible view of your page - whether on screen, printed, landscape, touch-screen, or whatever.  You can, however, add CSS that only applies under certai…
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!
In this tutorial viewers will learn how to define a gradient in CSS. Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Gradient. Define the background as "linear-gradient(to right, #ee3668, black)". Ensure you …
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…

738 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