html - 左右边距不相等,这是为什么

标签 html css

只是练习 div 定位。在下面的代码中,红色和绿色 div 位于 .content div 内。左边距(红色 div 的左侧)和右边距(绿色 div 的右侧)均设置为 0.3%

因此,左侧和右侧有两条垂直的小深蓝色线条(实际上是 .content div 的颜色)。)但是,如果您注意的话,线条宽度不相等。请查看屏幕截图以更好地理解这一点。为什么即使在两者设置了相等的边距之后仍然如此?

Screenshot

html,body {
	margin: 0px;
	height: 100%;
	width: 100%;
	left: 0px;
	top: 0px;
	background-color: rgba(173,192,241,1);
    }

.wrapper {
	height: 725px;
	max-width: 960px;
	margin-left: auto;
	left: 0px;
	top: 0px;
	/* [disabled]background-color: rgba(15,26,155,1); */
	margin-right: auto;
	position: relative;
}



.topimage {
	width: 100%;
	max-width: 960px;
	height: 100%;
	max-height: 175px;
	/* [disabled]background-color: rgba(0,102,204,1); */
	position: absolute;
	/* [disabled]border: thin solid rgba(255,0,0,1); */
}

.topimage img{
	max-width: 100%;
	max-height: 100%;
	/* [disabled]margin-bottom: -9px; */
	display: block;
	margin-right: auto;
	margin-left: auto;
	border-radius: 15px 15px 0px 0px;
}

.menu {
	background-color: rgba(15,26,155,1);
	height: 100%;
	max-height: 50px;
	max-width: 960px;
	position: relative;
	top: 20px;
}

.content {
	width: 100%;
	height: 500px;
	background-color: rgba(20,35,214,1);
	position: relative;
	top: 20px;
}

.leftcontent {
	background-color: rgba(255,0,0,1);
	float: left;
	height: 100%;
	max-height: 500px;
	width: 100%;
	max-width: 83.7%;
	top: 175px;
	/* [disabled]position: relative; */
	border-left-color: rgba(205,205,205,1);
	margin-left: 0.3%;
}

.rightcontent {
	background-color: rgba(0,255,0,1);
	float: right;
	height: 100%;
	max-height: 500px;
	width: 100%;
	max-width: 15.7%;
	/* [disabled]position: relative; */
	top: 175px;
	margin-right: 0.3%;
}

.footer {
	
}
<div class="wrapper">
<div class="topimage">

</div>
<div class="menu">
</div>

<div class="content">
<div class="leftcontent">
</div>
<div class="rightcontent">
</div>
</div>

</div>

最佳答案

它占据了 rightcontent div 的 0.3% 您的 leftcontent div 和 rightcontent div 不等于边距不等于

关于html - 左右边距不相等,这是为什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37916071/

相关文章:

javascript - jquery p :last-child not working

html - html5 中的 <picture> 元素通过调整大小显示不同的图像

css - 如何使用 Bootstrap 类在 Angular 5 的同一行中对齐 div

javascript - 添加事件链接类

css - 为 div 设置动画以从左向右移动然后返回

css - 具有透明 Angular 的元素边框

javascript - 在同一页面上有多个 jquery 选项卡

html - 覆盖两个 div 时显示奇怪的线条

javascript - 事件选项卡点击问题

javascript - 通过单击位于模态 - ANGULAR 中的 <ul> 选择选项