javascript - set margin around child div when parent's width is set using javascript
问题描述
The site I am working on: https://tricycle-203819.appspot.com/ I would like to replicate the effect on this site where there's multiple sections, and the child divs have margins around the sections: https://www.newyorker.com/
On my site, the div container-spice
's width and margin to the left and right is set using javascript on load, and on window size. I would like the children of left-container
, which is a child of container-spice
, to have a margin on the right that is of some constant pixel.
Changing the padding-right
and margin-right
property of left-container
do not achieve this effect. I would like to avoid changing the properties of the children of left-container
if possible, since they will be reused elsewhere.
解决方案
margin-right
onleft-container
不起作用的原因是因为它right-container
不尊重边距,因为它的位置是固定的。但是,您可以添加一个padding-right
toleft-container
以实现在两个容器之间创建间隙的所需效果。
推荐阅读
- javascript - JQuery如何在鼠标超出控制区域时继续检测textarea调整大小
- python - 如何创建以逗号分隔的字符串列表
- javascript - 在挂钩中设置新标题和正文时 ReactJS 可折叠元素中断
- c# - Rider Bug - C# 8 Nullable 引用参数上的扩展方法显示警告
- highcharts - Highcharts:去掉2系列下方的颜色区域
- html - 面板在按钮单击时展开并在图像顶部溢出
- c++ - 为什么协程不允许使用占位符返回类型?
- python - ModuleNotFoundError:没有名为 sqlparse 的模块
- python - Django 500 错误:WSGIRequest 对象没有属性“范围”
- c# - Razor 页面 PageModel 验证不起作用