PC 端:
手机端:
代码(主要由Flex布局):
<!DOCTYPE html>
<html>
<head>
<title>页面标题</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
* {
box-sizing: border-box;
}
/* body 样式 */
body {
font-family: Arial;
margin: 0;
/* overflow: hidden; /*防止外边距合并的问题*/ */
}
/* 标题 */
.header {
padding: 40px;
text-align: center;
background: #1abc9c;
color: white;
display: flex;
}
.logo{
text-align: left;
}
.logo>p{
margin: 0;
}
.logo>h1{
margin: 0;
}
.search{
margin-left: auto;
-webkit-align-self: center;
align-self: center;
}
.search input{
width: 244px;
height: 40px;
border-radius: 3px 0px 0px 3px; /* CSS3 border-radius - 指定每个圆角四个值: 第一个值为左上角,第二个值为右上角,第三个值为右下角,第四个值为左下角。 */
float: left;
border: 1px solid #e0e0e0;
box-sizing: border-box;
/* margin-top: 25px; */
padding: 0 10px;
outline-right:0;
}
.search button{
width: 52px;
height: 40px;
border-radius: 0px 3px 3px 0px; /* CSS3 border-radius - 指定每个圆角四个值: 第一个值为左上角,第二个值为右上角,第三个值为右下角,第四个值为左下角。 */
float: right;
border: 1px solid #e0e0e0;
/* margin-top: 25px; */
}
.search button:hover{
background: #ff6700;
color: #fff;
}
/* 标题字体加大
.header h1 {
font-size: 40px;
}
/* 导航 */
.navbar {
overflow: hidden;
background-color: #333;
/* box-shadow: 1px 5px 2px #000; */
}
/* 导航栏样式 */
.navbar a {
float: left;
display: block;
color: white;
text-align: center;
padding: 14px 20px;
text-decoration: none;
}
/* 右侧链接*/
.navbar a.right {
float: right;
}
/* 鼠标移动到链接的颜色 */
.navbar a:hover {
background-color: #ddd;
color: black;
}
/* .navbar a:hover .list-menu{
display: block;
}
.list-menu{
width: 300px;
height: 100px;
background-color: #fff;
border-top: 1px solid #eee;
box-shadow: 0 3px 4px rgba(0,0,0,0.1);
position:absolute;
left:30px;
top:190px;
display: none;
} */
/* 列容器 */
.row {
display: -ms-flexbox; /* IE10 */
display: flex;
-ms-flex-wrap: wrap; /* IE10 */
flex-wrap: wrap;
}
/* 创建两个列 */
/* 边栏 */
.side {
-ms-flex: 30%; /* IE10 */
flex: 30%;
background-color: #f1f1f1;
padding: 20px;
}
/* 主要的内容区域 */
.main {
-ms-flex: 70%; /* IE10 */
flex: 70%;
background-color: white;
padding: 20px;
}
/* 测试图片 */
.fakeimg {
background-color: #aaa;
width: 100%;
padding: 20px;
}
/* 底部 */
.footer {
padding: 1px;
text-align: center;
background: #ddd;
}
/* 响应式布局 - 在屏幕设备宽度尺寸小于 700px 时, 让两栏上下堆叠显示 */
@media screen and (max-width: 700px) {
.row {
flex-direction: column;
}
.header{
flex-direction: column;
/* display: none; */
padding: 5px;
}
.search{
margin-left: 0;
-webkit-align-self: flex-start;
align-self: flex-start;
}
}
/* 响应式布局 - 在屏幕设备宽度尺寸小于 400px 时, 让导航栏目上下堆叠显示 */
@media screen and (max-width: 400px) {
.navbar a {
float: none;
width: 100%;
}
}
</style>
</head>
<body>
<div class="header">
<div class="logo">
<h1>网页Logo</h1>
<p>重置浏览器大小查看效果。</p>
</div>
<div class="search">
<form action="">
<input type="text" placeholder="请输入关键词" >
<!-- placeholder 占位符 内容输入自动清除默认值 -->
<button type="submit" value="搜索" >搜索</button>
</form>
</div>
</div>
<div class="navbar">
<a href="#">
首页
<!-- <div class="list-menu" style="">test</div> -->
</a>
<a href="#">商品分类</a>
<a href="#">关于我们</a>
<a href="#" class="right">登陆</a>
</div>
<div class="row">
<div class="side">
<h2>推荐商品</h2>
<h5>商品图片:</h5>
<div class="fakeimg" style="height:200px;background-color: #16b777;"></div>
<p>关于商品简介..</p>
<h3>更多内容</h3>
<p>内容由讯飞星火AI生成</p>
<div class="fakeimg" style="height:60px;background-color: #ffb800;">这边插入图像</div><br>
<div class="fakeimg" style="height:60px;background-color: #31bdec;">这边插入图像</div><br>
<div class="fakeimg" style="height:60px;background-color: #ff5722;">这边插入图像</div>
</div>
<div class="main">
<h2>商品介绍</h2>
<h5>副标题</h5>
<div class="fakeimg" style="height:200px;background-color: #1e9fff;">图像</div>
<p>一些文本..</p>
<p>商品介绍是为了让潜在客户了解产品的特点、功能和优势,从而促使他们产生购买意愿。一个成功的商品介绍应该包括以下几个部分:</p>
<br>
<h2>标题</h2>
<h5>副标题</h5>
<div class="fakeimg" style="height:200px;background-color: #ffb800;">图像</div>
<p>产品名称..</p>
<p>清晰地说明产品的名称,以便消费者快速识别。</p>
</div>
</div>
<div class="footer">
<p>copyright@xxx公司</p>
</div>
</body>
</html>