【问题标题】:What css rules would you use to support smaller screens and resizing?你会使用什么 CSS 规则来支持更小的屏幕和调整大小?
【发布时间】:2013-12-07 04:15:25
【问题描述】:

我目前在调整窗口大小时遇到​​问题,该窗口会切断大量页面,并且相对于文档定位的元素会飞离页面。 这是它的样子:

普通:http://i.imgur.com/KpnUOwI.png

最小化:http://i.imgur.com/CfCrmub.png

在最小化时滚动到最后:http://i.imgur.com/p8dwiP9.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>

【问题讨论】:

标签: html css overflow positioning


【解决方案1】:

@Joe - 我猜您正在寻找响应式设计。我建议您与Twitter Bootstrap 3 相处融洽。负责处理窗口大小的 CSS 框架。您只需要创建一些 div 类即可使其响应。

与框架相处将使您的页面开发更加轻松快捷,Twitter Bootstrap 3 为我们完成。

这是另一个post,给出了相同的答案。

【讨论】:

    【解决方案2】:

    是的,你必须为你想要的每个大小进行 sepcifiy,而不是像编写任何其他 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;
            }
        }
    

    【讨论】:

      【解决方案3】:

      您只需要重写您希望在每个断点处更改的属性。 CSS 的级联属性在这里很重要,因此您应该注意选择器的特异性和顺序,以达到预期的 DRY 效果。

      如果你真的想支持多种屏幕尺寸,你应该看看响应式网页设计。将您的 px 替换为 em 是您将要做的事情的一个例子。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-03-24
        • 2014-08-05
        • 2023-01-04
        • 2016-04-20
        • 1970-01-01
        • 2011-08-12
        • 2016-07-14
        相关资源
        最近更新 更多