我是经验丰富的网站设计师,所以我对这门艺术知之甚少。
我有三个水平放置的元素(左/中/右),它们有固定的大小:
.banner-box {
position: relative;
display: inline-block;
width: 300px;
height: 400px;
margin: 0 auto;
}
并且在每个div中都有很少的图像,这些图像是水平居中的,img的一般样式是:
img {
max-width: 100%;
}
让它们变得流畅。
但由于div不灵活,因此在调整浏览器窗口大小时,其中的图像也不会改变其大小。
是否可以在任何html元素上设置固定大小,但仍然以某种方式使其流畅? 我知道我可以使用百分比而不是像素,但我也有使用百分比设置适当高度为.banner-box的问题 - 框不会延伸到所需的400px,只有281px。
这是html:
<div id="footer">
<img src="footer-line.png" alt="Footer.png" />
<p><span>some span</span> blah</p>
<p>mail: <span>mail@domain.com</span></p>
</div>
我的简单网页的整个CSS:
html {
background: url('mu-media-background-1920.png') no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: 100% 100%;
}
img {
max-width: 100%;
}
#container {
width: 1200px;
margin: 5% auto;
text-align: center;
}
#header {
display: block;
clear: both;
position: relative;
width: 100%;
margin: 0 auto;
}
#content {
display: block;
width: 95%;
height: auto;
margin: 10% auto 5% auto;
}
.banner-box {
position: relative;
display: inline-block;
width: 300px;
height: 400px;
margin: 0 auto;
}
.banner-text {
position: relative;
display: block;
top: 7%;
margin: 0 auto;
}
.see-more-button {
position: absolute;
display: block;
margin: 0 auto;
left: 0; right: 0; bottom: 0;
}
#virtual-studio {
float: left;
}
#mu-animation {
float: right;
}
#shadows {
display: block;
clear: both;
position: relative;
width: 100%;
}
#shadows img {
display: block;
clear: both;
position: relative;
margin: 0 auto;
}
#footer {
display: block;
clear: both;
width: 95%;
margin: 0 auto;
font: 15px Arial, Helvetica, sans-serif;
}
#footer p {
display: table;
clear: both;
position: relative;
margin: 0 auto;
color: #AFBEA5;
text-align: center;
width: auto;
}
#footer span {
font-weight: bold;
color: #BDC9AF;
}
我正在准备响应式布局,因此最好(afaik)仅使用百分比。
答案 0 :(得分:2)
这是一种很好的混合方法,在过去对我有用。
正如您已经提到的,您可以使用百分比宽度来构建流体布局,然后使用max和min值限制/修复特定div大小。例如:
#container {
width: 100%;
max-width: 1200px;
}
这是一个工作示例,横幅框限制为最大300px宽度和最小400px高度(我添加了一些填充和边框,以便您可以看到正在发生的事情):jsfiddle
最后,您仍然需要调整自适应媒体查询以处理固定元素,但这样您只需要更改几个最小值和最大值。
答案 1 :(得分:0)
您需要使用media queries并为您选择的每个屏幕断点定义.banner-box
的固定宽度/高度。
你必须使用尺码,看看哪种尺码最适合哪个断点。