css - HTML header 与内容不对齐

标签 css html web header

网站: http://younani.com/finalsite/finalindex.html

当浏览器未最大化时,我的标题对齐。当我最大化它移动并且未对齐时。我怎样才能对齐它,使其永远不会移动。我希望它与其下方的其余内容位于完全相同的位置

CSS:

#header {margin-left:50px; align: center;
         }

#container {

     background-color: #FAFAFA;
     color: #003300;
     font-family: Arial, Helvetica, sans-serif; background-position: center; background-size: cover;

}

#h2 {text-align: center;}

#container {
          margin-right:auto;
          margin-left:auto;
          background-image:url('backgroundflower5.jpg');
          min-width:1000px;
          max-width:1000px;
          padding:0px 70px 50px 70px;
          border:1px ridge #000000;
          border-radius:20px;
          -webkit-box-shadow:inset -3px -3px -3px 3px #18cad0;
          -moz-box-shadow:inset -3px -3px 3px 3px #00332B;
          box-shadow:inset -3px -3px 1px .9px black;
            width: 960px;
            margin: 0 auto;
        }

        #container div {

        }


        #header {}


#center2 {
            float: left;
            margin: 10px 0 10px 20px;
            min-width: 200px; width: 494px; border-radius:8px; 
        }



#centerO {float: left;
            margin: 10px 0 10px 20px;

            min-width: 200px; font-family: "Comic Sans MS", cursive, sans-serif; background-color: #FFFFFF;
            width: 494px; border-radius:8px; text-align: left; box-shadow:inset 1px 1px 10px 1px #000000; }

#center {box-shadow:inset 1px 1px 10px 1px #000000;}

        #left,
        #center,
        #right {
            float: left; margin: 10px 0 10px 20px;



            min-width: 200px;
        }

        #center {font-family: "Comic Sans MS", cursive, sans-serif; background-color: #FFFFFF;
            width: 494px; border-radius:8px; text-align: center;
        } 

        .clear {
            clear: both;
        }

#right2 {float: left;
            margin: 10px 0 10px 20px; border: 0px;

            min-width: 200px;}

#right { font-family: Impact, Charcoal, sans-serif; border-radius:8px; background-color: #FFFFFF; box-shadow:inset 1px 1px 10px 1px #000000; text-align: center;}

#left a {font-family: Arial, Helvetica, sans-serif;
    font-size: 14px;
    color: #ffffff;
        display: block;
    padding: 10px 20px;
    background: -moz-linear-gradient(
        top,
        #ffffff 0%,
        #2a07ed);
    background: -webkit-gradient(
        linear, left top, left bottom, 
        from(#ffffff),
        to(#2a07ed));
    -moz-border-radius: 30px;
    -webkit-border-radius: 30px;
    border-radius: 30px;
    border: 3px solid #ffffff;
    -moz-box-shadow:
        0px 3px 11px rgba(000,000,000,0.5),
        inset 0px 0px 1px rgba(026,020,219,1);
    -webkit-box-shadow:
        0px 3px 11px rgba(000,000,000,0.5),
        inset 0px 0px 1px rgba(026,020,219,1);
    box-shadow:
        0px 3px 11px rgba(000,000,000,0.5),
        inset 0px 0px 1px rgba(026,020,219,1);
    text-shadow:
        0px -1px 0px rgba(000,000,000,0.2),
        0px 1px 0px rgba(255,255,255,0.3);
}





figure{}

#left a:link { background-color: #E6E6E6; }
#left a:visited { background-color: #E6E6E6; }
#left a:hover {border: 3px inset #333333; }

#left ul { list-style-type: none;
          margin: 0;
          padding-left: 0; }



#footer { text-align: center; font-family: Audimat;
    clear: both; width:38%;
        border-radius: 8px;
        background-color:white;
        text-align:center; margin-right:auto;
        margin-left:auto; box-shadow:inset 1px 1px 10px 1px #000000;}

HTML:

<!DOCTYPE html>

<html lang="en">

<head>

   <title>Younani Flower's</title>

   <meta charset="utf-8">

   <link rel="stylesheet" href="final.css" />
</head>


<body>
<div id="header"><img src="header88.png" alt="header" height="200" width="1150" align="left:100px" /></div>
<div id="container" class="clearfix"><!-- Header --> <!-- Left Column -->
<div id="left">
<ul>
<li><a href="finalindex.html">Home</a></li>
<li><a href="gallery.html">Gallery</a></li>
<li><a href="occasions.html">Occasions</a></li>
<li><a href="aboutus.html">About Us</a></li>
<li><a href="contactus.html">Contact Us</a></li>
</ul>
</div>
<!-- Center Column -->
<div id="center">
<p><strong>In-store Specials</strong></p>
<p>Dozen Red Roses: $12.99</p>
<p>Bouquet of TEN different garden flowers: $19.99</p>
<p>Small glass vases: $9.99 <br /> Medium glass vases $14.99 <br /> Large glass vases: $19.99</p>
<p>Buy THREE of the any vases and receive the fourth one FREE!</p>
</div>
<!-- Right Column -->
<div id="right">
<p><span style="text-decoration: underline;"><strong>Birth Month Flowers<strong></strong></strong></span></p>
<p>January Carnation</p>
<p>February Iris</p>
<p>March Daffodil</p>
<p>April Daisy</p>
<p>May Lily</p>
<p>June Rose</p>
<p>July Delphinium</p>
<p>August Dahlia</p>
<p>September Aster</p>
<p>October Calendula</p>
<p>November Chrysanthe</p>
<p>December Poinsettia</p>
</div>
<!-- Footer -->
<div id="footer" class="clear">
<div class="nav"><b><a href="finalindex.html">Home</a>&nbsp;&nbsp; <a href="gallery.html">Gallery</a>&nbsp;&nbsp; <a href="occasions.html">Occasions</a>&nbsp;&nbsp; <a href="aboutus.html">About Us</a>&nbsp;&nbsp; <a href="contactus.html">Contact Us</a>&nbsp;&nbsp;</b></div>
</div>
</div>
<!-- #container -->
<p></p>
</body>

</html>

最佳答案

您正在使用 margin-left:50px; 请改用 margin:0 auto;

#header {
    margin: 0 auto;
    width: 1150px;
 }

它做了什么 margin-left

enter image description here

所以它将离开浏览器 50px,并且在不同的宽度上它看起来会有所不同,所以更好的方法是使用 margin:0 auto;

margin:0 auto 总是居中

enter image description here

enter image description here

关于css - HTML header 与内容不对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13695716/

相关文章:

apache - 在 Apache Web 服务器中读取带有特殊字符的图像

javascript - 如何使用jquery获取div的宽度?

html - 在没有 'folder structure' 的情况下离线呈现 HTML 网站

html - 并排放置 div 会导致换行,而不是溢出

javascript - 在 PHP 中使用 Ajax 提交图像文件

html - Flexbox 内容溢出容器。 Chrome

apache - 在同一台服务器上运行多个域

css - 如何使我的标题在移动设备上看起来更好

javascript - 如何使我的 div 居中并使它们与媒体查询堆叠

html - 如何只在悬停时显示?