【发布时间】:2014-03-01 03:16:47
【问题描述】:
这里是一个简单的问题,但正在努力寻找实现我想要的最佳方式......我有一个图像,我试图在浏览器中保持居中并做出响应。将宽度设置为 100%,图像响应完美(水平)。我遇到的问题是高度。我不希望浏览器滚动并让图像以正确的比例居中,并带有 20 像素的填充。
Dropbox 查看器有一个很好的例子来说明我想要完成的工作,请参见此处:https://www.dropbox.com/s/7zmau5ckx9qe2q1/P-20131215-00017_HiRes%20JPEG%2024bit%20RGB.jpg
使用更多最新代码更新以下内容
我有一个到目前为止的演示(如果你垂直浏览浏览器,滚动条会出现):http://jsfiddle.net/k7JG5/7/
HTML
<div id="top_nav">Logo Here</div>
<div id="img_wrap">
<center><img src="http://goldenleafdesigns.com/images/random- images/soul_id_select_image1.jpg" /><center>
</div>
CSS
body {
margin: 0px;
padding: 0px;
background-color: #000;
}
#top_nav {
height: 44px;
width: 100%;
background-color: #FFF;
text-align: center;
line-height: 44px;
}
#img_wrap {
max-width: 100%;
max-height: 100%;
padding: 20px;
margin-top: 0px;
margin-right: auto;
margin-bottom: 0px;
margin-left: auto;
}
img {
outline: 0;
max-width: 100%;
max-height: auto;
}
那么,在没有滚动的情况下实现高度以保持响应的最佳方法是什么?
【问题讨论】:
-
你会用javascript吗?
-
我对任何事情都持开放态度。 :)
-
检查我更新的答案,没有js
标签: html css responsive-design width