【问题标题】:Why is left style ignored?为什么忽略左侧样式?
【发布时间】:2013-04-16 16:50:05
【问题描述】:

我在以下代码中的页面上有徽标

<h1 class="site-title">
   <a class="logo custom-logo" href="url" title="Go to Site"> 
      <img alt="Site" height="136" src="url" width="298"> 
   </a> 
</h1>

我已将left 属性添加到logo 样式

.logo {
   display: inline-block;
   line-height: 1;
   vertical-align: middle;
}

这个

left: 400px;

但它被忽略了。 Chrome Developer tools 显示此样式处于活动状态,但图像显示在距浏览器窗口左侧零距离处。

为什么?

【问题讨论】:

  • 因为它还在文档的流中,如果你想让它遵守左边,设置为position: relative;

标签: html css developer-tools


【解决方案1】:

为了使left, top, bottom, right 值生效,必须定位项目。

根据您的需要添加position: absoluteposition: relative

Absolute 将相对于它最近定位的父对象定位它。

Relative 将相对于自身定位。

【讨论】:

    【解决方案2】:

    您可以在 position:relative 的任一侧或将左侧填充设置为 400 像素

    position:relative;
    left: 400px;
    

    padding-left:400px
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-30
      • 1970-01-01
      • 2023-01-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多