html对象边距右无功能

  • 本文关键字:功能 对象 html html css
  • 更新时间 :
  • 英文 :


我正在制作一张传单地图,想在地图上方添加一个徽标和一个标题。在尝试定义位置时,我注意到只有margin-left命令有效。CCD_ 2命令只得到"0";忽略";。我目前只使用margin-left命令来解决这个问题,但当我试图最小化浏览器时,对齐方式就不再正确了。

以下是我的html元素中的一些代码:

<!--headline -->
<h2 style="postion:absolute; top:10px; margin-left:7.5%;">Maschinentechnische Anlagen </h2>
<!--logo + position-->
<div style="position:absolute; top:10px; margin-left: 89%">   <!-- ideal would be margin-right: 7.5% -->
<img src="images/DBlogo.png" width="50"/> </div>

<!--map + position-->
<div style="height:860px; width:85%; margin-top:auto; margin-left:7.5%; margin-right:7.5%;" id="map"></div>

注意:定义映射时的margin-right部分也没有任何影响,但这并不是什么大问题,因为它已经用宽度部分定义得足够多了

在这种情况下,忽略右边距,因为左边距小于右边距的必要大小:7.5

你不能让元素在左边空白89%和右边空白7.5%

要将元素放置在右侧7.5,您可以直接使用右侧:7.5%

div, h2 {
background: red;
}
<!--headline -->
<h2 style="postion:absolute; top:10px; margin-left:7.5%;">Maschinentechnische Anlagen </h2>
<!--logo + position-->
<div style="position:absolute; top:10px; right: 7.5%">   <!-- ideal would be margin-right: 7.5% -->
<img src="images/DBlogo.png" width="50"/> </div>

<!--map + position-->
<div style="height:860px; width:85%; margin-top:auto; margin-left:7.5%; margin-right:7.5%;" id="map"></div>

最新更新