gpt4 book ai didi

html - 负责任的设计 - 不要处理所有元素

转载 作者:行者123 更新时间:2023-11-28 03:37:55 26 4
gpt4 key购买 nike

我正在针对定义的标准分辨率测试负责任的设计(定义的分辨率来自 FireFox)。如果页面宽度设置为最大宽度 650px 一切正常,但如果我将浏览器宽度更改为 651px 或更多,则 CSS 代码不会处理。我看不出问题。

        window.onresize = displayWindowSize;
window.onload = displayWindowSize;

function displayWindowSize() {
myWidth = window.innerWidth;
myHeight = window.innerHeight;
// your size calculation code here
document.getElementById("responsible-design-debug").innerHTML = "Responsible design debug: " + myWidth + "x" + myHeight;
};
        body {
background-color: #F5F5F5;
font-family: Verdana, Geneva, Tahoma, sans-serif;
font-size: 0.8em;
}

.Logo {
height: 35px;
margin-bottom: 15px;
}

/**
* DEVICE: Universally
* DIMENSIONS: 1920px and more
* ORIENTATION: Portrait
**/
@media screen and (orientation: portrait) and (min-width: 1920px) {
.responsible-design-debug {
background-color: green;
float: left;
}
}

/**
* DEVICE: Universally
* DIMENSIONS: 1280px - 1920px
* ORIENTATION: Portrait
**/
@media screen and (orientation: portrait) and (min-width: 1280px) and (max-width: 1919px) {
.responsible-design-debug {
background-color: lightgreen;
float: left;
}
}

/**
* DEVICE: Universally
* DIMENSIONS: 980px - 1280px
* ORIENTATION: Portrait
**/
@media screen and (orientation: portrait) and (min-width: 980px) and (max-width: 1279px) {
.responsible-design-debug {
background-color: red;
float: left;
}
}

/**
* DEVICE: Universally
* DIMENSIONS: 800px - 980px
* ORIENTATION: Portrait
**/
@media screen and (orientation: portrait) and (min-width: 800px) and (max-width: 979px) {
.responsible-design-debug {
background-color: orange;
float: left;
}
}

/**
* DEVICE: Universally
* DIMENSIONS: 768px - 800px
* ORIENTATION: Portrait
**/
@media screen and (orientation: portrait) and (min-width: 768px) and (max-width: 799px) {
.responsible-design-debug {
background-color: blueviolet;
float: left;
}
}

/**
* DEVICE: Universally
* DIMENSIONS: 360px - 768px
* ORIENTATION: Portrait
**/
@media screen and (orientation: portrait) and (min-width: 360px) and (max-width: 767px) {
.responsible-design-debug {
background-color: blue;
float: left;
}
}

/**
* DEVICE: Universally
* DIMENSIONS: 320px - 360px
* ORIENTATION: Portrait
**/
@media screen and (orientation: portrait) and (min-width: 320px) and (max-width: 359px) {
.responsible-design-debug {
background-color: aqua;
float: left;
}
}

/**
* DEVICE: Universally
* DIMENSIONS: 0px - 320px
* ORIENTATION: Portrait
**/
@media screen and (orientation: portrait) and (min-width: 0px) and (max-width: 319px) {
.responsible-design-debug {
background-color: yellow;
float: left;
}
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Responsible design</title>
</head>
<body>

<div id="responsible-design-debug" class="responsible-design-debug">Responsible design debug: init</div>
<img src="Image.png" alt="Image.png" class="Logo" />

<div id="example">
<p>Lorem ipsum dolor sit amet consectetuer In et elit diam arcu. Lacus enim molestie dictumst quis convallis pellentesque consectetuer ipsum ligula pellentesque. Nullam elit nunc amet et nec semper lacus ac lacinia et. At Sed Proin tempor lacus tristique senectus eu est lacinia dui. Nisl Ut Vestibulum ac Vestibulum Phasellus lacinia ut auctor consequat felis. Sapien dolor Morbi Ut fringilla at molestie eu.</p>
<p>Augue sodales est ligula eget cursus quis id orci magna et. Dapibus ac elit diam pede mauris Nam interdum adipiscing et suscipit. Nonummy justo laoreet In elit magna condimentum enim quis non tempor. Malesuada eget habitant ligula ut consequat ut felis amet libero cursus. Lobortis tellus volutpat pellentesque leo ipsum id Vestibulum suscipit convallis Donec. Amet eget dui.</p>
</div>

</body>
</html>

谢谢你和最好的问候, 彼得

最佳答案

因为你使用的是and (orientation: portrait),所以一旦窗口的宽度值大于高度,你的CSS都不会被考虑,因为它被认为landscape 方向。如果您从所有媒体查询中删除它,它将按预期工作:

window.onresize = displayWindowSize;
window.onload = displayWindowSize;

function displayWindowSize() {
myWidth = window.innerWidth;
myHeight = window.innerHeight;
// your size calculation code here
document.getElementById("responsible-design-debug").innerHTML = "Responsible design debug: " + myWidth + "x" + myHeight;
};
body {
background-color: #F5F5F5;
font-family: Verdana, Geneva, Tahoma, sans-serif;
font-size: 0.8em;
}

.Logo {
height: 35px;
margin-bottom: 15px;
}

/**
* DEVICE: Universally
* DIMENSIONS: 1920px and more

**/
@media screen and (min-width: 1920px) {
.responsible-design-debug {
background-color: green;
float: left;
}
}

/**
* DEVICE: Universally
* DIMENSIONS: 1280px - 1920px
**/
@media screen and (min-width: 1280px) and (max-width: 1919px) {
.responsible-design-debug {
background-color: lightgreen;
float: left;
}
}

/**
* DEVICE: Universally
* DIMENSIONS: 980px - 1280px
**/
@media screen and (min-width: 980px) and (max-width: 1279px) {
.responsible-design-debug {
background-color: red;
float: left;
}
}

/**
* DEVICE: Universally
* DIMENSIONS: 800px - 980px
**/
@media screen and (min-width: 800px) and (max-width: 979px) {
.responsible-design-debug {
background-color: orange;
float: left;
}
}

/**
* DEVICE: Universally
* DIMENSIONS: 768px - 800px
**/
@media screen and (min-width: 768px) and (max-width: 799px) {
.responsible-design-debug {
background-color: blueviolet;
float: left;
}
}

/**
* DEVICE: Universally
* DIMENSIONS: 360px - 768px
**/
@media screen and (min-width: 360px) and (max-width: 767px) {
.responsible-design-debug {
background-color: blue;
float: left;
}
}

/**
* DEVICE: Universally
* DIMENSIONS: 320px - 360px
**/
@media screen and (min-width: 320px) and (max-width: 359px) {
.responsible-design-debug {
background-color: aqua;
float: left;
}
}

/**
* DEVICE: Universally
* DIMENSIONS: 0px - 320px
**/
@media screen and (min-width: 0px) and (max-width: 319px) {
.responsible-design-debug {
background-color: yellow;
float: left;
}
}
<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Responsible design</title>
</head>

<body>

<div id="responsible-design-debug" class="responsible-design-debug">Responsible design debug: init</div>
<img src="Image.png" alt="Image.png" class="Logo" />

<div id="example">
<p>Lorem ipsum dolor sit amet consectetuer In et elit diam arcu. Lacus enim molestie dictumst quis convallis pellentesque consectetuer ipsum ligula pellentesque. Nullam elit nunc amet et nec semper lacus ac lacinia et. At Sed Proin tempor lacus tristique
senectus eu est lacinia dui. Nisl Ut Vestibulum ac Vestibulum Phasellus lacinia ut auctor consequat felis. Sapien dolor Morbi Ut fringilla at molestie eu.</p>
<p>Augue sodales est ligula eget cursus quis id orci magna et. Dapibus ac elit diam pede mauris Nam interdum adipiscing et suscipit. Nonummy justo laoreet In elit magna condimentum enim quis non tempor. Malesuada eget habitant ligula ut consequat ut
felis amet libero cursus. Lobortis tellus volutpat pellentesque leo ipsum id Vestibulum suscipit convallis Donec. Amet eget dui.</p>
</div>

</body>

</html>

关于html - 负责任的设计 - 不要处理所有元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44375048/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com