html - 使用 HTML/CSS 的响应式设计中的意外行为

标签 html css responsive-design

我正在学习响应式网站设计,并在我自己尝试的原始代码中遇到了意想不到的行为。

我的指导来源是这个-> W3 Schools Learning responsive website designing. 如果尝试减少小于 600px 的内容,每个 div 将变成 100% 并覆盖整个水平位置。所以我认为这是响应式设计的正常行为。

但在我自己写的代码中,如果我尝试小于 600px,它不会占据整个 100%。它变成了一个小块的内容框。你可以在 chrome 检查中或通过调整大小来检查它。可能出了什么问题?我是否遗漏了任何声明?

这是我自己尝试过的代码。

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
* {
    box-sizing: border-box;
}
[class*="col-"] {
    float: left;
    padding: 15px;
}
html {
    font-family: "Lucida Sans", sans-serif;
}
@media only screen and (min-width: 600px) {
    /* For tablets: */
    .col-m-1 {width: 8.33%;}
    .col-m-2 {width: 16.66%;}
    .col-m-3 {width: 25%;}
    .col-m-4 {width: 33.33%;}
    .col-m-5 {width: 41.66%;}
    .col-m-6 {width: 50%;}
    .col-m-7 {width: 58.33%;}
    .col-m-8 {width: 66.66%;}
    .col-m-9 {width: 75%;}
    .col-m-10 {width: 83.33%;}
    .col-m-11 {width: 91.66%;}
    .col-m-12 {width: 100%;}
}
@media only screen and (min-width: 768px) {
    /* For desktop: */
    .col-1 {width: 8.33%;}
    .col-2 {width: 16.66%;}
    .col-3 {width: 25%;}
    .col-4 {width: 33.33%;}
    .col-5 {width: 41.66%;}
    .col-6 {width: 50%;}
    .col-7 {width: 58.33%;}
    .col-8 {width: 66.66%;}
    .col-9 {width: 75%;}
    .col-10 {width: 83.33%;}
    .col-11 {width: 91.66%;}
    .col-12 {width: 100%;}
}
.box1{
background-color :red;
}
.box2{
background-color :green;
}
.box3{
background-color :blue;
}
</style>
<body>
<div class="row">
<div class="col-4 col-m-12 box1"></div>
<div class="col-4 col-m-12 box2"></div>
<div class="col-4 col-m-12 box3"></div>
</div>

</body>
</html>

最佳答案

您没有用于 max-width:600px 和以上的媒体选择器,您将所有 div 设置为 float:left 这会让他们注意到为 100%,所以在 <600px 时,您的 div 只知道它们应该 float 。

关于html - 使用 HTML/CSS 的响应式设计中的意外行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37468584/

相关文章:

javascript - "Smart"在 HTML 中溢出 : is there any way to put ellipsis "..." with a link at the end to view entire content?

jquery - 响应式导航 'max-height' 问题(CSS3 转换)

html - CSS响应高度失败

html - 需要帮助使此页面响应

html - Rails Image_Tag 无法访问其他目录中的图像

javascript - 我无法使用 jquery 使跨度可编辑

html - Bootstrap 3.3.5 - 让 2 个按钮彼此相邻

javascript - 在所有页面上传播暗模式更改

javascript - 如何在javascript中的两个分隔符之间拆分字符串?

javascript - 如何根据内容动态调整 Twitter Bootstrap 模式的大小