如何在<div>内对齐图片,以便具有相同的宽度?</div>

时间:2014-09-27 20:35:07

标签: html css html5 alignment

如何在div容器内对齐图片,使其与宽度相符?

这是我走了多远

&#13;
&#13;
<head>

<style>
#left {
	background-color:#81CFE0;
	height:100%;
	width:25%;
	float:left;
}

#img {
    display: block;
    margin-left: auto;
    margin-right: auto;
}
</style>

<meta charset="utf-8">

</head>

<body>

<div id="left">
<img src="/img/001.jpg">
This is a Picture of something representing something

</body>
&#13;
&#13;
&#13;

提前感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

您的代码中存在很多错误,但这应该有效:

&#13;
&#13;
#left {
  background-color:#81CFE0;
  height:100%;
  width:25%;
  float:left;
}

img {
  width:100%;
}
&#13;
<div id="left">
  <img src="/img/001.jpg"/>
</div>
&#13;
&#13;
&#13;