javascript - 使元素填充其容器的宽度并且没有边距将其推出该容器?
问题描述
有没有办法让元素动态填充其容器的宽度并具有边距但不会溢出该容器?
body {
-moz-osx-font-smoothing: grayscale;
font-family:Verdana;
font-weight:normal;
font-size:12px;
}
#BorderContainer2085 {
position:absolute;
top:30px;
left:37px;
width:340px;
height:160px;
display:inline-block;
border-width:1px;
border-color:#696969;
border-style:solid;
border-radius:0px;
}
#Button1199 {
position:absolute;
top:19px;
margin-left:20px;
margin-right:20px;
width:100%;
}
<div id="BorderContainer2085">
<input id="Button1199" type="button" value="Button">
</div >
这是我的代码得到的结果:
这是我想要的:
解决方案
使用width:calc(100% - 40px);
按钮元素 - 它会产生预期的效果吗?
例子:
body {
-moz-osx-font-smoothing: grayscale;
font-family:Verdana;
font-weight:normal;
font-size:12px;
}
#BorderContainer2085 {
position:absolute;
top:30px;
left:37px;
width:240px;
height:160px;
display:inline-block;
border-width:1px;
border-color:#696969;
border-style:solid;
border-radius:0px;
}
#Button1199 {
position:absolute;
top:20px;
margin-left:20px;
margin-right:20px;
width:calc(100% - 40px);
}
<div id="BorderContainer2085">
<input id="Button1199" type="button" value="Button">
</div >
推荐阅读
- sql - 如何使用多个过滤器将记录提取到数组
- mysql - 使用 mysql 语句插入图像后,我的照片字段在我的表结构中仍然显示为空
- javascript - 为什么酶“安装”包装只是呈现
- 标签,但没有别的?
- java - 如何删除另一个线程正在使用的文件?
- php - 为什么这段代码在数据库中不起作用?
- math - 找到两个长度之间的交点
- java - 即使没有添加任何内容,我是否应该在子类中覆盖 equals 和 hashCode?
- node.js - 包括来自其他视图文件夹的 pug mixin
- reactjs - this.setState 不适用于我的 React 本机项目
- powerpoint - 在多张幻灯片上销毁图像