开发者

Javascript Center [duplicate]

开发者 https://www.devze.com 2023-04-08 03:54 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: How to align a <div> to the middle of the page
This question already has answers here: Closed 11 years ago.

Possible Duplicate:

How to align a <div> to the middle of the page

This is a simple question with what should be a simple answer but I don't know how to do it.

Well, use this code:

<html>
<head>
     <style type="text/css">
     body{
         min-width: 710px;
     }
     #backdrop{
         min-width: 710px;
         max-width:开发者_如何学Go 710px;
     }
     </style
</head><body>

<div id="backdrop">
</div>

</body></html>

How do you get #backdrop to center on page load and stay centered on the page when you resize? (until you resize to less than 710px wide, then the horizontal scroll bar would appear)

Knowing this information would improve the layout quality of my page immensly and I could probably do it if I had a more adept knowledge of javascript and jQuery... but I don't yet.


If all you need is to have the #backdrop div centered horizontally, there is no need for javascript. The whole thing can be achieved through CSS.

#backdrop{ 
    display:block;
    width: 710px;  //just specify the width. no need for min-width or max-width if this is not meant to change.
    margin: 0 auto; //this will center the div in its container
}


You don't need javascript to do this, just try:

<html>
<head>
     <style type="text/css">
     body{
         min-width: 710px;
     }
     #backdrop{
         width:710px; 
         margin:0 auto;
     }
     </style
</head><body>

<div id="backdrop">
</div>

</body></html>

[EDIT] This was already answered on stackoverflow: How to align a <div> to the middle (horizontally/width) of the page


I'm not really sure about what you want, but:

#backdrop{
   width:710px;
   margin: 0 auto;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消