在CSS中使用负边距或填充是不好的做法 [英] Is it bad practice to use Negative Margins or Padding in CSS
问题描述
以下是我正在开发的项目的图片...
蓝色背景是一个DIV,在另一个DIV里面,包含所有的侧边栏联系部分。要让 Blue BG DIV
具有圆形边框,并且没有间隙,因为父母边距/填充,我不得不使用负边距 < br>
margin:-9px -2px 8px -6px;
Take for example this image below of a project I am working on...
The Blue background is a DIV that is inside of another DIV that wraps all that sidebar contact section together. To get the Blue BG DIV
to have the round border and not have a gap because of the parents margin/padding I had to use negative margins
margin: -9px -2px 8px -6px;
是,是否使用负边际或填充?
So the question is, is it bad practice to use Negative Margins or Padding?
推荐答案
这不是坏习惯,只要你知道你使用负边距,这必然'拉'/'移动'元素从他们的正常的位置。
No; it's not bad practice, so long as you're aware of the fact you're using negative margins, and that this necessarily 'pulls'/'moves' elements from their otherwise-'normal' position.
为什么你会担心这个?
这篇关于在CSS中使用负边距或填充是不好的做法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!