利用媒体查询和CSS弹性框.
媒体查询允许您为不同的屏幕尺寸指定不同的样式。移动设备、大屏幕等
CSS flexbox 是创建灵活的布局,自动调整到屏幕的大小。
<style>
/* Mobile styles */
@media only screen and (max-width: 600px) {
/* Make the website full-width */
body {
width: 100%;
}
/* Use flexbox to arrange the website elements */
.container {
display: flex;
flex-direction: column;
}
/* Make the header and footer full-width */
header, footer {
width: 100%;
}
/* Make the images full-width and resize them to fit the screen */
img {
width: 100%;
height: auto;
}
}
</style>
<body>
<div class="container">
<header>
...
</header>
<main>
...
</main>
<footer>
...
</footer>
</div>
</body>