【问题标题】:My Website Won't Align Properly On Zoom In and Out我的网站在放大和缩小时无法正确对齐
【发布时间】:2014-02-26 07:08:55
【问题描述】:

我是创建网站的新手,似乎无法找出为什么我的网站无法正常对齐。

在我的所有三台电脑显示器上,网站看起来都很好:

http://www.spectanium.com

但我在我朋友的一台电脑上查看了它,它看起来不对。

我有一个主体,然后左右都有空间,但是根据我使用的显示器,空间有所不同,看起来很糟糕......

谁能看看我的代码,看看我做错了什么?

index.html -->

<html>
    <head>
        <title>Spectanium Studios</title>
        <link rel="stylesheet" type="text/css" href="default.css" />
    </head>


<body>
    <div id="header">
    </div>


    <div id="menu">
        <ul>
                <a href="http://www.spectanium.com/">Homepage</a><li><a href="/Spectanium%202/products.html">Products</a></li>
                <li><a href="/Spectanium%202/aboutus.html">About Us</a></li>
        </ul>
    </div>


    <div id="content">




         <div id="updatesCol">
                <h2>Recent Updates</h2>
                <h3> * Website Created *</h3>
                <p></p>
                <p style="font-size:small">Website is now done!</p>
         </div>

        <div id="contentCol">
                <h2>Welcome to Spectanium!</h2>
                <p>
                    <em>So far we have to do a few things before we are ready to roll!</em>
                </p>



                    <h3>Game Stuff:</h3>
                    <ol>
                    <li>Finish the actual game.</li>
                    <li>Get final graphics.</li>
                    <li>Get final music.</li>
                    <li>Find out distribution method.</li>
                    </ol>
                    <h3>Website Stuff:</h3>
                    <ol>
                        <li>Write descriptions for about us.</li>
                        <li>Improve it</li>
                        <li>Make it pretty</li>
                    </ol>


        </div>



  <div style="clear: both;"></div>

</div>


<div id="footer">
    <p></p>
  <p> © 2014 Spectanium Studios</p>
</div>
</body>
</html>

default.css -->

body {
    margin: 20px 0;
    padding: 0;
    background: black;
        background-image:url('images/background.png');
        background-size:100%;
        background-repeat:repeat-y;
        width:190%;
    font: normal "Courier New", Courier, Courier, sans-serif;
}

h1, h2, h3 {
    color: #B13413;
}

h2 {
    font-size: 1.6em;
}

h3 {
    margin: 0;
    font-size: 1em;
}

p, ul, ol, blockquote {
    margin-top: 0;
}

a:link {
    border-bottom: 1px dotted #CCCCCC;
    text-decoration: none;
    color: #3284B5;
}

a:hover {
    border: none;
}

img {
    border: none;
}

/* Header */

#header {
    width: 890px;
    height: 273px;
        margin: 4px 0 4px 300px;
    background: url(images/header.png) no-repeat;

}


/* Menu */

#menu {

    background: url(images/topborder.png) repeat-x;
    width: 950px;
    height: 41px;
    margin: 0 auto;
        margin-left:275px;
        background-color: #a1a1a1;

}

#menu ul {
    margin: 0;
    padding: 0;
    list-style: none;
        text-decoration:none;
}


#menu li {
    display: inline;
        text-decoration:none;

}

#menu a {
    display: block;
    float: left;
    height: 28px;
    padding: 15px 20px 0 20px;
    text-decoration: none;
    color: black;
        font-weight:bold;
        border-bottom: 0 dotted #DDDDDD;



}

#menu a:hover{
         height:8px;
         color: #B13413;
}

/* Content */

#content {

    background: url(images/bottomborder.png) repeat-x;
    width: 950px;
        background-color: white;
        margin-left:275px;
        height: 1000px;
}

#updatesCol {
    float: right;
    width: 250px;
        height:1000px;
        border-left:1px black solid;
        text-align:center;

}

#contentCol {
    float: left;
    width: 500px;
    padding: 20px 0 0 0;
        margin-left:25px;


}


/* Footer */

#footer {
    width: 950px;
    margin: 0 auto;
        margin-left:275px;
    padding: 10px 0;
    font-size: smaller;        
    background: url(images/bottomborder.png) repeat-x;
        clear:both;
}

#footer * {
    color: #666666;
}

【问题讨论】:

  • 对我来说看起来不错...
  • 是吗? 0.o 可能是我试过的其他 3 台电脑出了点问题...hmpf
  • 这个问题只针对一个浏览器还是针对所有浏览器?

标签: html css alignment positioning


【解决方案1】:

这就是它在 1920x1080 上运行时的显示方式。

http://s30.postimg.org/s3w6clowg/hello.jpg

问题是你的背景。它设置为repeat-y,但宽度为1450,所以它会repeat-y,但不会延伸得更远。

而且它会看起来有点偏左,因为你以像素为单位设置了所有边距,比如标题:

4 像素 0 4 像素 300 像素。 所以不管它会被从左边推到右边300px。如果我的分辨率很高,它会在页面的右侧显示一个巨大的空白。

【讨论】:

  • 我怎样才能设置它而不是固定的 4px 0 4 px 300px 是一个静态居中对齐,调整 w/ 分辨率?
  • 使用边距:0自动;并删除您在 div 中的许多剩余边距
  • 除此之外,图像中的黑色区域未居中。
  • 我删除了旧图像,我现在只使用黑色背景。
【解决方案2】:

这是因为您使用 margin-left 来对齐整个网站,所以当它放大时它仍然是向左对齐的。使用边距:0 自动;使您的网站居中。但是,如果您希望网站像当前一样与左侧对齐,那么请改用百分比。当页面比背景图像宽时,您可能还应该设置背景颜色或具有重复背景以避免黑色背景。

【讨论】:

    【解决方案3】:

    试试这个。

    body{
      background-position-x:center;
    }
    
    body > div{
      margin:auto !important;
    }
    

    我向您保证,现在内容已居中。但它不会感觉居中,因为您使用的背景图像中的黑色区域不是水平居中的。你可以看到绿线比红线长。纠正这一点,你就可以走了。 我的建议是您在背景上使用没有变黑区域的图像并通过 css 实现

    【讨论】:

      【解决方案4】:

      您指定了导致问​​题的绝对左侧边距。 我更改了您的 css 文件的某些部分,它对我来说很好。

      基本上用

      替换绝对边距
      margin-left:auto
      margin-right:auto
      

      default.css 的变化

      body {
          margin: 20px 0;
          padding: 0;
          background: black;
              background-image:url('http://www.spectanium.com/images/background.png');
              background-size:100%;
              background-repeat:repeat-y;
              width:100%;
          font: normal "Courier New", Courier, Courier, sans-serif;
      }
      
      #header {
          width: 890px;
          height: 280px;          
          margin-left:auto;
          margin-right:auto;
          background: url(http://www.spectanium.com/images/header.png) no-repeat;
      
      }
      #menu {
      
          background: url(http://www.spectanium.com/images/topborder.png) repeat-x;
          width: 950px;
          height: 51px;
          margin-left:auto;
          margin-right:auto;
              background-color: #a1a1a1;
      
      }
      #content {
      
          background: url(images/bottomborder.png) repeat-x;
          width: 950px;
              background-color: white;
              margin-left:auto;
              margin-right:auto;
              height: 1000px;
      }
      /* Footer */
      
      #footer {
          width: 950px;
          margin: 0 auto;
              margin-left:auto;
          margin-right:auto;
          padding: 10px 0;
          font-size: smaller;        
          background: url(http://www.spectanium.com/images/bottomborder.png) repeat-x;
              clear:both;
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-08-15
        • 1970-01-01
        • 2014-07-29
        • 2017-06-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-04-01
        相关资源
        最近更新 更多