【问题标题】:How to remove the margins of child that parent contains some padding?如何删除父级包含一些填充的子级的边距?
【发布时间】:2012-12-28 08:46:48
【问题描述】:

假设我有,

<div style="padding: 15px; width: 100%;">
   <div style="margin: -15px;; width: 100%;">
       <img src="http://imageshack.us/scaled/landing/51/tigerso.jpg" alt="" style="width: 100%;">
   </div>
</div>

父 div 包含 15px 的内边距,并且 - 子 div 想要通过使用边距来删除此内边距,但它不起作用。看到这个小提琴。它总是向我展示一个水平滚动条。 http://jsfiddle.net/2GJnG/

【问题讨论】:

  • 从你的 DIV 中移除 100% 的宽度
  • 你有什么限制/控制?
  • 如果你愿意,你应该定义 px 而不是 percantage

标签: html css


【解决方案1】:

删除两个div 元素的width 属性:

<div style="padding: 15px;">
    <div style="margin: -15px;">
        <img src="http://imageshack.us/scaled/landing/51/tigerso.jpg" alt="" style="width: 100%;">
    </div>
</div>

在此处查看演示 > http://jsfiddle.net/2GJnG/5/

【讨论】:

    猜你喜欢
    • 2011-05-14
    • 1970-01-01
    • 2012-02-14
    • 2013-02-08
    • 1970-01-01
    • 1970-01-01
    • 2021-12-31
    • 2021-12-02
    • 2014-02-20
    相关资源
    最近更新 更多