2017-06-27 217 views
0

触发移动媒体查询时遇到响应问题。 画布刚刚消失。HTML5响应画布大小调整

问题:
调整到移动设备时,水彩画布刚刚消失。

其中一个解决方案:

硬编码的div <canvas id="main" width="1024" height="640"></canvas>

JSBIN: http://jsbin.com/poposopahi/edit?html,css,output

@charset "utf-8"; 
 
/* Global Styles */ 
 

 
body { 
 
\t margin-left: auto; 
 
\t margin-right: auto; 
 
\t width: 92%; 
 
\t max-width: 960px; 
 
\t padding-left: 2.275%; 
 
\t padding-right: 2.275%; 
 
} 
 
/* Header */ 
 
header { 
 
\t text-align: center; 
 
\t display: block; 
 
} 
 
header .profileLogo .logoPlaceholder { 
 
\t background-color: white; 
 
\t color:black; 
 
\t width: 300px; 
 
\t text-align: center; 
 
} 
 
header .logoPlaceholder span { 
 
\t width: 180px; 
 
\t height: 22px; 
 
\t font-family: 'Montserrat', sans-serif; 
 
\t color: black; 
 
\t font-size: 30px; 
 
\t font-weight: 700; 
 
\t line-height: 53px; 
 
} 
 
header .logoPlaceholder2 span { 
 
\t width: 180px; 
 
\t height: 22px; 
 
\t font-family: 'Montserrat', sans-serif; 
 
\t color: black; 
 
\t font-size: 30px; 
 
\t font-weight: 700; 
 
\t line-height: 53px; 
 
} 
 
header .profilePhoto { 
 
\t background-color: rgba(237,237,237,1.00); 
 
\t width: 259px; 
 
\t border-radius: 50%; 
 
\t height: 259px; 
 
\t clear: both; 
 
} 
 
header .profileHeader h1 { 
 
\t font-family: 'Montserrat', sans-serif; 
 
\t color: rgba(146,146,146,1.00); 
 
\t font-size: 30px; 
 
\t font-weight: 700; 
 
\t line-height: 24px; 
 
} 
 
header .profileHeader h3 { 
 
\t font-family: sans-serif; 
 
\t color: rgba(146,146,146,1.00); 
 
\t font-size: 16px; 
 
\t font-weight: 700; 
 
\t line-height: 24px; 
 
} 
 
hr { 
 
\t background-color: rgba(208,207,207,1.00); 
 
\t height: 1px; 
 
} 
 
header .profileHeader p { 
 
\t font-family: sans-serif; 
 
\t color: rgba(146,146,146,1.00); 
 
\t font-size: 14px; 
 
\t font-weight: 400; 
 
\t line-height: 1.8; 
 
\t overflow-y: auto; 
 
} 
 
header .socialNetworkNavBar { 
 
\t text-align: center; 
 
\t display: block; 
 
\t margin-top: 60px; 
 
\t clear: both; 
 
} 
 
header .socialNetworkNavBar .socialNetworkNav { 
 
\t border-radius: 50%; 
 
\t cursor: pointer; 
 
} 
 
header .socialNetworkNavBar .socialNetworkNav img:hover { 
 
\t opacity: 0.5; 
 
} 
 

 

 
/* Media query for Mobile devices*/ 
 
@media only screen and (min-width : 285px) and (max-width : 480px) { 
 
/* Header */ 
 
header { 
 
\t width: 100%; 
 
\t float: none; 
 
} 
 
.wrapper { 
 
    display: inline-block; 
 
    width: 50%; 
 
    height: 50%; 
 
} \t 
 
header .profileLogo .logoPlaceholder { 
 
\t display: inline-block; 
 
\t text-align: left; 
 
} 
 
header .profilePhoto { 
 
\t display: inline-block; 
 
} 
 
header .profileHeader { 
 
\t text-align: center; 
 
\t margin-top: 10%; 
 
} 
 
header .profileHeader p { 
 
\t text-align: justify; 
 
} 
 
header .socialNetworkNavBar { 
 
\t text-align: center; 
 
\t display: block; 
 
\t margin-top: 60px; 
 
\t clear: both; 
 
\t margin-bottom: 15%; 
 
} 
 
header .socialNetworkNavBar .socialNetworkNav { 
 
\t width: 60px; 
 
\t height: 60px; 
 
\t display: inline-block; 
 
\t margin-right: 23px; 
 
} 
 

 
} 
 

 
/* Media Query for Tablets */ 
 
@media only screen and (min-width : 481px) and (max-width : 1024px) { 
 
/* Header */ 
 
header { 
 
\t width: 100%; 
 
\t float: none; 
 
} 
 
header .profileLogo .logoPlaceholder { 
 
\t display: inline-block; 
 
\t font-family: 'Montserrat', sans-serif; 
 
} 
 
header .profilePhoto { 
 
\t float: left; 
 
\t clear: both; 
 
\t margin-right: 3%; 
 
\t margin-top: 5%; 
 
} 
 
header .profileHeader { 
 
\t text-align: left; 
 
\t margin-top: 7%; 
 
} 
 
header .socialNetworkNavBar .socialNetworkNav { 
 
\t width: 74px; 
 
\t height: 74px; 
 
\t display: inline-block; 
 
\t margin-right: 23px; 
 
} 
 

 
} 
 

 
/* Desktops and laptops */ 
 
@media only screen and (min-width:1025px) { 
 
/* Header */ 
 
header .profileLogo .logoPlaceholder { 
 
\t float: left; 
 
\t margin-bottom: 50px; 
 
} 
 
header .profilePhoto { 
 
\t float: left; 
 
\t clear: both; 
 
\t margin-right: 3%; 
 
} 
 
header .profileHeader { 
 
\t text-align: left; 
 
\t padding-top: 10%; 
 
} 
 
header .socialNetworkNavBar .socialNetworkNav { 
 
\t width: 74px; 
 
\t height: 74px; 
 
\t display: inline-block; 
 
\t margin-right: 23px; 
 
} 
 

 

 
\t 
 
.wrapper { 
 
    display: table; 
 
    padding: 0; 
 
    width: 100%; 
 
    height: 100%; 
 
} 
 
.container { 
 
    display: table-cell; 
 
    vertical-align: middle; 
 
} 
 
.canvas-container { 
 
    position: relative; 
 
    max-width: 1024px; 
 
    min-width: 120px; 
 
    margin: 0 auto; 
 
} 
 
#main { 
 
    width: auto; 
 
    background-color: aqua; 
 
} \t 
 
\t 
 
\t 
 
}
<!doctype html> 
 
<html> 
 
<head> 
 
<meta charset="utf-8"> 
 
<meta name="viewport" content="width=device-width, initial-scale=1"> 
 
<title>About Page template By Adobe Dreamweaver CC</title> 
 
<link href="AboutPageAssets/styles/aboutPageStyle.css" rel="stylesheet" type="text/css"> 
 

 
<!--The following script tag downloads a font from the Adobe Edge Web Fonts server for use within the web page. We recommend that you do not modify it.--> 
 
<script>var __adobewebfontsappname__="dreamweaver"</script><script src="http://use.edgefonts.net/montserrat:n4:default;source-sans-pro:n2:default.js" type="text/javascript"></script> 
 
<script> 
 

 
</script> 
 
</head> 
 

 
<body> 
 
<!-- Header content --> 
 
<header> 
 
    <div class="profileLogo"> 
 
    <!-- Profile logo. Add a img tag in place of <span>. --> 
 
    <p class="logoPlaceholder"><!-- <img src="logoImage.png" alt="sample logo"> --><span>Name :</span></p> 
 
    <p class="logoPlaceholder"><!-- <img src="logoImage.png" alt="sample logo"> --><span>Attempts :</span></p> 
 
    <p class="logoPlaceholder"><!-- <img src="logoImage.png" alt="sample logo"> --><span>Score :</span></p> 
 
    </div> 
 
    <section> 
 
<div class="wrapper"> 
 
    <div class="container"> 
 
    <div class="canvas-container"> 
 
     <canvas id="main" width="1024" height="640"></canvas> 
 
    </div> 
 
    </div> 
 
</div> 
 
    </section> 
 
    <!-- Links to Social network accounts --> 
 
    <aside class="socialNetworkNavBar"> 
 
    <div class="socialNetworkNav"> 
 
     <!-- Add a Anchor tag with nested img tag here --> 
 
     <img src="AboutPageAssets/images/social.png" alt="sample"> </div> 
 
    <div class="socialNetworkNav"> 
 
     <!-- Add a Anchor tag with nested img tag here --> 
 
     <img src="AboutPageAssets/images/social.png" alt="sample"> </div> 
 
    <div class="socialNetworkNav"> 
 
     <!-- Add a Anchor tag with nested img tag here --> 
 
     <img src="AboutPageAssets/images/social.png" alt="sample"> </div> 
 
    
 
    </aside> 
 
</header> 
 
<!-- content --> 
 

 
</body> 
 
</html>

回答

1

您定义的CSS样式的主ID

#main { 
    width: auto; 
    background-color: aqua; 
} 

在媒体查询只

@media only screen and (min-width:1025px) { 
    ... 
} 

。把它放在

/* Global Styles */ 

工作例如:https://jsfiddle.net/tnLy9ab6/

+0

感谢您指出我的误差小,我忘记了支架已被关闭。 – FreedomPride