Link to home
Start Free TrialLog in
Avatar of scm0sml
scm0sml

asked on

centralising a div over my 'mask'

In question:
https://www.experts-exchange.com/questions/23743018/creating-a-full-height-div-with-opacity.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?
Avatar of carazuul
carazuul

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
ASKER CERTIFIED SOLUTION
Avatar of scm0sml
scm0sml

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That's a good work-around too :-)
Avatar of David S.
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/