html - 在没有溢出的情况下为父级中的相等子级创建边距

标签 html css

我想在父包装器的两个子 div 之间创建一个间隙。问题是,我将宽度创建为百分比 (50),并希望总计 10px 的固定边距不会溢出父元素。

<div id="wrapper">
    <div id="parent">
        <div id="one" class="child"> </div>
        <div id="two" class="child"> </div>
    </div>    
</div>

当我添加边距或填充到“一”或“二”时,这超出了父宽度的总和 100%。我可以将边距/填充添加到 div 元素,以便将其计算到父元素的 50% 中吗?

这是一个说明问题的 fiddle :http://jsfiddle.net/cusyyddx/

最佳答案

为宽度属性使用 calc:width: calc(50% - 1px);。适用于 IE9+

关于html - 在没有溢出的情况下为父级中的相等子级创建边距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30336262/

相关文章:

html - Bootstrap : changes to the basic code not shown on web browser

html - DOCTYPE 的意义何在?

javascript - 适配 React TS 后运行 treeview 时出现 TS 错误

css - 如何在CSS中使用可缩放像素

javascript - 在 d3 中为 datalist 创建元素

html - 仅当至少选中一个复选框时才使用外部提交按钮提交表单

javascript - 我正在尝试制作一个可折叠菜单,一次只打开 1 个纯 javascript

html - 在折叠的导航栏之后的一行上显示一个表单

javascript - 如何设置Rollover的超时功能

html - 更多 HTML/CSS [min-]height 问题