我目前在调整窗口大小方面遇到了问题,因为窗口会截断很多页面,相对于文档定位的元素也会从页面上飞出。以下是它的样子:
正常:https://i.stack.imgur.com/y0bpY.png
最小化:https://i.stack.imgur.com/NlVTb.png
滚动到最后,同时最小化:https://i.stack.imgur.com/LW5Q7.png
我要么希望蓝色元素向右结束,即使它被最小化(它的宽度:100%),要么让元素根据窗口按比例调整大小并适合所有内容(所有内容都相对于文档定位)
css:
body {
margin:0;
padding:0;
height:100%;
width:100%;
position:relative;
overflow:auto;
}
#headr {
background-image:url(../images/top%20bg.jpg);
background-repeat:no-repeat;
height:400px;
width:100%;
position:relative;
z-index:-100;
overflow:hidden;
}
#lgo {
position:relative;
margin-left:33%;
margin-top:80px;
}
#nav {
background-image:url(../images/nav%20bar.png);
position:relative;
top:0;
margin-top:0px;
width:100%;
width:!important;
height:99px;
}
#listone {
list-style-type:none;
display:inline;
margin-left:570px;
top:25px;
position:relative;
overflow:hidden;
}
.navlist {
display:inline;
font-size:33px;
padding:25px;
color:#FFF;
font-weight:bold;
font-family:Verdana, Geneva, sans-serif;
position:static;
}
#searchb {
background-image:url(../images/search.png);
background-repeat:no-repeat;
width:500px;
height:200px;
position:relative;
padding:0px;
margin-left:1350px;
margin-top:-85px;
}
#searchb form {
display:inline;
}
#searchbar {
background-color:transparent;
border:0px;
position:absolute;
top:50px;
left:60px;
width:200px;
height:80px;
outline:none;
font-size:24px;
}
.searchsubmit {
border:0px;
background-color:transparent;
position:absolute;
top:70px;
left:400px;
width:30px;
height:50px;
}
Html:
<body>
<div id="nav">
<ul id="listone">
<li class="navlist">Home</li>
<li class="navlist">Portfolio</li>
<li class="navlist">Prices</li>
<li class="navlist">Contact</li>
</ul>
<div id="searchb">
<form>
<input type="text" id="searchbar" placeholder="Search">
<input type="image" class="searchsubmit" src="images/searchicon.png" value="">
</form></div>
</div>
</div>
<div id="headr">
<!--<img src="images/head logo.png" id="lgo"> -->
</div>
@Joe-我想你正在寻找一个响应式的设计。我建议您使用Twitter Bootstrap 3。照顾窗口大小的CSS框架。您只需要创建一些div
类就可以使其具有响应性。
与框架相处将使您的页面开发更容易、更快,Twitter Bootstrap 3为我们做到了这一点。
下面是的另一篇帖子,其中给出了相同的答案。
是的,你必须为你想要的每一个大小进行指定,你可以像编写任何其他css文件一样为下一个媒体编写css。以下是的示例
/*if the width is over 768px the background will turn blue*/
@media screen and (min-width: 769px) {
body {
background:blue;
}
}
/*if the width is under 768px the background will turn yellow*/
@media screen and (max-width: 769px){
body {
background:yellow;
}
}
您只需要重写您希望在每个断点更改的属性。CSS的级联属性在这里很重要,所以您应该注意选择器的特殊性和顺序,以便实现DRY的预期结果。
如果你真的想支持多个屏幕截图,你应该看看响应式网络设计。将你的像素替换为em是你将要做的事情的一个例子。