【问题标题】:Padding between images doesn't pad图像之间的填充不填充
【发布时间】:2010-04-30 16:01:42
【问题描述】:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head>
<style type="text/css">
#action-icons
{
    float:right;
}
#action-icons.img
{
    position:relative;
    top:-30px;
    padding-right:200px;
}
</style>
</head> 

<body> 
    <h1 class="edit">Some nifty title
    <span id="action-icons"> 
    <img src="foo.png" width="64" height="64" alt="" id="newsticky"/> 
    <img src="bar.png" width="60" height="60" alt="" id="trash"/> 
    </span> 
    </h1> 
</body> 
</html>

【问题讨论】:

    标签: html css padding


    【解决方案1】:

    尝试添加:

    #action-icons.img
    {
        position:relative;
        top:-30px;
        padding-right:200px;
    }
    

    可能会。

    编辑:您已将#action-icons.img 删除,因此它是#action-icons img

    点将img 设置为一个类,因此您拥有它,HTML 将如下所示:

    <img src="bar.png" width="60" height="60" alt="" id="trash" class="img"/>
    

    希望对你有帮助。

    编辑 - 这是完整的工作代码:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml"> 
    <head>
    <style type="text/css">
    #action-icons
    {
        float:right;
    }
    #action-icons img
    {
        position:relative;
        top:-30px;
        margin-left:50px;
    }
    </style>
    </head> 
    
    <body> 
        <h1 class="edit">Some nifty title
        <span id="action-icons"> 
        <img src="foo.png" width="64" height="64" alt="" id="newsticky"/> 
        <img src="bar.png" width="60" height="60" alt="" id="trash"/> 
        </span> 
        </h1> 
    </body> 
    </html>
    

    【讨论】:

    • 嘿,原来不需要内联,问题只是我的选择器。
    • 很公平,我花了一段时间才看到选择器:)
    【解决方案2】:

    改变

    #action-icons.img
    

    #action-icons img
    

    并检查

    它在 Firefox 上对我有用

    【讨论】:

      【解决方案3】:

      试试margin-right

      并使用

      #action-icons img 
      

      解决图像。

      #action-icons.img
      

      表示“ID为action-iconsimg的任何元素。

      【讨论】:

      • @ripper 另外,使用img#action-icons 而不是#action-icons.img。就目前而言,该规则没有得到应用。
      • 您的答案仍然无效......@Kyle 成功了。感谢您的努力。
      • @Pekka:除非我弄错了,img#action-icons 会匹配任何带有 id 'action-icons' 的 img。你想要#action-icons img - 任何图像,它是具有 id 'action-icons' 的节点的后代。
      猜你喜欢
      • 2011-11-08
      • 1970-01-01
      • 1970-01-01
      • 2018-01-05
      • 1970-01-01
      • 1970-01-01
      • 2014-08-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多