Css 尝试使用自动左边距/右边距:在左侧自动放置图像
使用left:明确定位图像时,它的位置正确,但是当我删除left:并将其替换为margin left:auto和margin right:auto时,它被定位在左侧。我做错了什么Css 尝试使用自动左边距/右边距:在左侧自动放置图像,css,Css,使用left:明确定位图像时,它的位置正确,但是当我删除left:并将其替换为margin left:auto和margin right:auto时,它被定位在左侧。我做错了什么 <body> <div id = "main_header" href="http://xxx" > <img id = "logo" src="logo.png"/> <h1 id = "main_title">Title<
<body>
<div id = "main_header" href="http://xxx" >
<img id = "logo" src="logo.png"/>
<h1 id = "main_title">Title</h1>
</div>
body {
position:relative;
background-image: url("large_background.png");
font-family: Helvetica;
margin: 0; /* Amount of negative space around the outside of the body */
padding: 0; /* Amount of negative space around the inside of the body */
}
#main_header {
position: relative;
}
#logo {
position:absolute;
top: 5px;
left: 140px;
height: 50px;
width: 50px;
}
标题
身体{
位置:相对位置;
背景图片:url(“large_background.png”);
字体系列:Helvetica;
边距:0;/*主体外部周围的负空间量*/
填充:0;/*主体内部周围的负空间量*/
}
#主割台{
位置:相对位置;
}
#标志{
位置:绝对位置;
顶部:5px;
左:140像素;
高度:50px;
宽度:50px;
}
您的图像的css设置为绝对位置。
使用此属性,您的“徽标”将相对于div“main_header”进行定位,因为此属性设置为position:relative。
这就是为什么利润率不起作用。与位置:绝对只有“左”,“顶”,和其他将工作
要使用边距,您应该删除位置属性。是它:要解析,请删除img的位置:绝对值,并将图像放入div中,例如:Than,将边距:0自动设置为此div