我的CSS有什么问题,元素移动和重叠时将窗口大小更小? [英] What's wrong with my CSS , elements move and overlap when resizing window to smaller size?

查看:86
本文介绍了我的CSS有什么问题,元素移动和重叠时将窗口大小更小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,下面是我的CSS和HTML代码。我已经使用百分比的div,以便那些div可以重新调整到更大的屏幕尺寸。令人讨厌的是,当我在我的计算机上将窗口调整为较小的大小,这些元素保持移动,直到它们重叠,我不想要。如何使用百分比来使这些div重新调整为更大的分辨率,但根据下面的CSS和HTML将窗口大小调整为较小的大小时不会移动

Ok , so below is my CSS AND HTML code. I have been using percentage for the divs so that those divs can re-adjust to bigger screen sizes . The annoying thing is that when I resize the window to a smaller size on my computer , those elements keep moving till they overlap and I don't want that . How can I use percentages to make those divs re-adjust to bigger resolutions , yet not move when resizing the window to a smaller size based on the CSS and HTML I have below

这里是CSS

body{
    background:#F4F4F4;
    background-size:100%;
    width:100%;
    height:100%;
    margin:0 auto;
            min-width:1300px;
            min-height:750px;
}
.logo{
    position:absolute;
    left:40%;
    top:5%;
}
    .logo_homepage{
    position:absolute;
    left:4%;
    top:5%;
}
   .homepage_slogan{
    position:absolute;
    left:3%;
    top:45%;
}
    .search_box{
    position:absolute;
    left:30%;
    top:30%;
            width:35%;
            height:50%;
            min-width:35%;
            min-height:50%;

}


    .user_info{
    position:absolute;
    left:75%;
            height:100%;
            width:20%;
            min-width:20%;
            background:white;
}
.header{
    position:absolute;
    top:0px;
    width:100%;
            min-width:98%;
    height:100px;
            min-height:100px;
    left:0;
    background:#EB6A4A; 
}

.slogan{
    position:absolute;
    top:60%;
    left:40.5%;
}

.login{
    position:absolute;
    top:15%;
    left:90%;
}

    .whitebackground{
    background:#FFFFFF;
}

#slides{
    position:absolute;
    top:20%;
    width:50%;
    background:transparent;
    height:20%;
    left:25%;
}
.socialfeeds{
    position:absolute;
    top:41%;
    width:25%;
    height:52%;
            min-width:25%;
            min-height:52%;
    left:25%;
} 
    .heading{
    position:absolute;
    top:20%;
    width:100%;
            min-width:100%;
    height:10%;
            min-height:10%;
    left:2%;
}

    .bucket{
    position:absolute;
    top:18%;
    left:20%;
            width:13%;
            min-width:13%;
}

     .title{
    position:absolute;
    top:20%;
    left:32%;
            width:30%;
            min-width:30%;
}

    .feed_icons{
      margin:20px;

}

.featured{
    position:absolute;
    top:30%;
    width:30%;
            min-width:30%;
    background:transparent;
    height:60%;
            min-height:60%;
    left:60%;
}

和HTML

<body class="whitebackground">
    <div class="header">
        <div class="logo"><img draggable="false" src="/images/logo.png" /></div>
        <div class="slogan"><img draggable="false" src="/images/slogan.png" /></div>
        <div class="login"><a href="/twitter/redirect.php"><img draggable="false" src="/images/login.png" /></a></div>
    </div>
    <div class="bucket">
        <span class="feed_icons"><a href="#"><img draggable="false" src="/images/bucket.png"/></a></span>
    </div>
        <div class="title">
        <span class="feed_icons"><a href="#"><img draggable="false" src="/images/title.png"/></a></span>
    </div>
    <div class="socialfeeds">
        <span class="feed_icons"><a href="#"><img draggable="false" src="/images/social_feeds.png" width="100%" height="100%"/></a></span>
    </div>
    <div class="featured"><img draggable="false" src="/images/featured_list.png" width="100%" height="100%" /> </div>
    <div class="footer"> <span style='margin-left:45%;'> COPYRIGHT 2013&copy;</span></div>


</body>


推荐答案

位置:规则。 CSS写的告诉浏览器总是将这些元素放置在X位置,无论元素或屏幕的大小。 List Apart有一个很好的文章,用于确定如何工作的定位: http:// alistapart。

Position: absolute pulls the elements out of the DOM rendering rules. The CSS as written tells the browser to always place these elements at X position no matter what size of the element or screen. A List Apart has an excellent article for getting a good grounding in how positining works: http://alistapart.com/article/css-positioning-101

删除定位,而改用display:或float:属性。事情将根据DOM渲染规则开始流动。

Remove the positioning and instead use either the "display:" or "float:" properties. Things will begin to flow according to the DOM rendering rules.

此外,确保应用的CSS类具有函数或语义命名。避免使用引用设计处理的类,因为像颜色/大/小这样的东西可以随着时间而改变,例如whitebackground。使用类似client-name或.theme这样的代码,然后声明该类或BODY标签的背景颜色更好地提供代码。

In addition, make sure applied CSS classes have functional or semantic naming. Avoid using classes that make reference to design treatment since things like colors/big/small can and do change over time., ie, "whitebackground". The code is much better served using something like the "client-name" or .theme and then declaring the background color for that class or on the BODY tag.

HTML标记-up

HTML Mark-up

<body class="site-body">
    <div class="header">
        <div class="logo"><img draggable="false" src="/images/logo.png" /></div>
        <div class="slogan"><img draggable="false" src="/images/slogan.png" /></div>
        <div class="login"><a href="/twitter/redirect.php"><img draggable="false" src="/images/login.png" /></a></div>
    </div>
    <div class="bucket">
        <span class="feed_icons"><a href="#"><img draggable="false" src="/images/bucket.png"/></a></span>
    </div>
        <div class="title">
        <span class="feed_icons"><a href="#"><img draggable="false" src="/images/title.png"/></a></span>
    </div>
    <div class="socialfeeds">
        <span class="feed_icons"><a href="#"><img draggable="false" src="/images/social_feeds.png" width="100%" height="100%"/></a></span>
    </div>
    <div class="featured"><img draggable="false" src="/images/featured_list.png" width="100%" height="100%" /> </div>
    <div class="footer"> <span style='margin-left:45%;'> COPYRIGHT 2013&copy;</span></div>


</body>

CSS:

.header {
height: auto; 
overflow: hidden; /* clears floated child elements */ 
width: 100%; 
min-width: 98%;
}
.logo, .slogan, .login {
display: inline-block;
} 
/* or... 
.logo, .slogan, .login {
float: left;
} */
.slogan {
margin-left: 40.5%;
}

这篇关于我的CSS有什么问题,元素移动和重叠时将窗口大小更小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆