使用 Flex或Grid现代布局技术,实现前台首页的布局
时间: 2024-05-27 21:11:29 浏览: 139
由于缺少具体的设计稿或布局要求,下面提供一种基本的前台首页布局方案,使用 Flexbox 技术实现:
HTML 结构:
```
<header>
<nav>
<ul>
<li><a href="#">导航1</a></li>
<li><a href="#">导航2</a></li>
<li><a href="#">导航3</a></li>
<li><a href="#">导航4</a></li>
</ul>
</nav>
<h1>网站名称</h1>
<form>
<input type="text" placeholder="搜索">
<button>搜索</button>
</form>
</header>
<main>
<section>
<h2>最新文章</h2>
<ul>
<li>
<a href="#">
<img src="article1.jpg" alt="">
<h3>文章标题1</h3>
<p>文章摘要1</p>
</a>
</li>
<li>
<a href="#">
<img src="article2.jpg" alt="">
<h3>文章标题2</h3>
<p>文章摘要2</p>
</a>
</li>
<li>
<a href="#">
<img src="article3.jpg" alt="">
<h3>文章标题3</h3>
<p>文章摘要3</p>
</a>
</li>
</ul>
</section>
<section>
<h2>热门商品</h2>
<ul>
<li>
<a href="#">
<img src="product1.jpg" alt="">
<h3>商品名称1</h3>
<p>商品介绍1</p>
</a>
</li>
<li>
<a href="#">
<img src="product2.jpg" alt="">
<h3>商品名称2</h3>
<p>商品介绍2</p>
</a>
</li>
<li>
<a href="#">
<img src="product3.jpg" alt="">
<h3>商品名称3</h3>
<p>商品介绍3</p>
</a>
</li>
</ul>
</section>
</main>
<footer>
<p>版权信息</p>
</footer>
```
CSS 样式:
```
/* 全局样式 */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
/* 头部导航 */
header {
display: flex;
justify-content: space-between;
align-items: center;
background-color: #333;
color: #fff;
padding: 20px;
}
nav ul {
display: flex;
}
nav li {
margin-right: 20px;
}
nav a {
color: #fff;
text-decoration: none;
}
h1 {
font-size: 32px;
font-weight: bold;
}
form {
display: flex;
}
form input[type="text"] {
padding: 10px;
border-radius: 5px;
border: none;
margin-right: 10px;
}
form button {
background-color: #fff;
color: #333;
padding: 10px 20px;
border-radius: 5px;
border: none;
cursor: pointer;
}
/* 主体内容 */
main {
display: flex;
justify-content: space-between;
align-items: flex-start;
padding: 20px;
}
section {
flex-basis: 45%;
}
h2 {
font-size: 24px;
font-weight: bold;
margin-bottom: 10px;
}
ul {
list-style: none;
}
li {
margin-bottom: 20px;
}
section img {
width: 100%;
height: auto;
margin-bottom: 10px;
}
h3 {
font-size: 18px;
font-weight: bold;
margin-bottom: 5px;
}
p {
font-size: 16px;
}
/* 底部信息 */
footer {
background-color: #ccc;
color: #333;
text-align: center;
padding: 20px;
}
```
效果展示:
![flex-layout.png](https://i.loli.net/2021/03/11/hTJrPnNeziKjRlL.png)
阅读全文