【问题标题】:Center logo in html5 boilerplatehtml5 样板中的中心徽标
【发布时间】:2012-03-20 01:07:13
【问题描述】:

我正在使用 html5 boilerplate 和他们的 .ir 类。我使徽标可点击,我想将其置于页面中心,但到目前为止还没有运气。我试过 margin: 0 auto;和文本对齐:居中;但它们似乎都不起作用。

html

   <a href="/"><h1 class="ir">logo header</h1></a>

和css

    h1 {
    height: 373px;
    }

    .ir {
    display: block;
    border: 0; 
    text-indent: -999em; 
    overflow: hidden; 
    background-color: transparent; 
    background-repeat: no-repeat; 
    text-align: left; 
    direction: ltr; 
    *line-height: 0; 
    background-image: url(http://i.imgur.com/yYnyJ.jpg);
    }
    .ir br { display: none; }

【问题讨论】:

    标签: css boilerplate html5boilerplate


    【解决方案1】:

    我们不建议您直接将样式添加到帮助程序类中。这意味着您不能在再次需要 .ir 类的其他情况下重用它们(如果您有其他背景要替换)。除了名为ir 的类之外,请在要替换为图像的标记中添加一个类名,如下所示:

    <h2 class="ir myh2classname"></h2>
    

    然后像这样添加你的背景:

    .myh2classname {
      background: url(http://i.imgur.com/yYnyJ.jpg) transparent no-repeat center;
    }
    

    这样,如果您想将另一张图片用作其他部分的背景,您只需在该部分的标记中添加另一个类名:

      <h3 class="ir anotherimagereplacement"></h3>
    

    然后像这样为其他部分添加背景:

       .anotherimagereplacement {
            background: url(path/to/image);
        } 
    

    【讨论】:

      【解决方案2】:

      background-postion: center; 添加到规则中。如果您希望在顶部对齐图像并同时居中,您可能希望使用 top center 作为值。

      注意:图片尺寸必须小于&lt;h1&gt;才能出现在中心。

      此外,我还建议使用速记属性。

      .ir {
          display: block;
          border: 0; 
          text-indent: -999em; 
          overflow: hidden; 
          text-align: left; 
          direction: ltr; 
          *line-height: 0; 
          background: url(http://i.imgur.com/yYnyJ.jpg) transparent no-repeat center;
      }
      

      【讨论】:

        【解决方案3】:

        在 .ir 中添加以下内容

        background-position: center center;
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-04-14
          • 2021-04-01
          • 1970-01-01
          • 2014-03-15
          相关资源
          最近更新 更多