这里的另一个新手问题。学习CSS。我正在尝试做一些我认为会很简单的事情,但还没有设法找到解决方法,或者找到合适的答案。使div的宽度等于它包含的图像的宽度
我有一个标题,一些内容和页脚的简单项目。内容有一个带白色边框的div和一个内部的图像。我希望div能够像图片一样宽,不会更宽。我暂时将宽度设置为430px,但我想知道代码将宽度设置为图像的宽度。
代码
HTML
html,
body {
margin: 0px;
padding: 0px;
height: 100vh;
}
#header {
position: relative;
height: 10%;
width: 100%;
background-color: lightgray;
}
#footer {
position: relative;
height: 10%;
width: 100%;
background-color: lightgray;
}
#container {
height: 80%;
width: 100vw;
background-color: red;
}
#imagewrap {
position: relative;
border: 1px solid white;
width: 430px;
display: block;
margin: 0 auto;
top: 50%;
transform: translateY(-50%);
}
<div id="header"> </div>
<div id="container">
<div id="imagewrap">
<img src="Images/01Folder/Image.jpg" height="100%" id="front" />
</div>
</div>
<div id="footer"> </div>