Flex实现PHP中文网首页
示例代码
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<link rel="stylesheet" href="css/common.css" />
<link rel="stylesheet" href="css/index.css" />
<link rel="stylesheet" href="iconfont/iconfont.css" />
</head>
<body class="flexDis flexDirV flexNoWrap flexAlignC">
<header class="flexDis flexDirH flexNoWrap">
<a href=""></a>
<a href="">首页</a>
<a href="">视频教程</a>
<a href="">入门教程</a>
<a href="">社区问答</a>
<a href="">技术文章</a>
<a href="">资源下载</a>
<a href="">编程词典</a>
<a href="">工具下载</a>
<a href="">php培训</a>
<a href="" class="iconfont"></a>
<a href="">登录</a>
</header>
<main class="flexDis flexDirV flexNoWrap flexAlignC">
<div class="box1 flexDis flexDirH flexNoWrap">
<ul class="flexDis flexDirV flexNoWrap flexContentV flexAlignS">
<li><a href="">php开发</a></li>
<li><a href="">前端开发</a></li>
<li><a href="">服务端开发</a></li>
<li><a href="">移动开发</a></li>
<li><a href="">数据库</a></li>
<li><a href="">服务器运维&下载</a></li>
<li><a href="">在线工具箱</a></li>
<li><a href="">常用类库</a></li>
</ul>
<div class="submeun flexDis flexDirV flexNoWrap flexContentA">
<div
class="submeun-list flexDis flexDirH flexNoWrap flexAlignC flexContentA"
>
<a href="">PHP头条</a>
<a href="">独孤九贱</a>
<a href="">学习路线</a>
<a href="">在线工具</a>
<a href="">趣味课堂</a>
<a href="">社区问答</a>
<a href="">直播课程</a>
<input type="search" name="" id="" placeholder="请输入关键词搜索" />
</div>
<div class="slider">
<img src="image/i12.png" alt="" />
</div>
<div class="submeun-buttom flexDis flexDirH flexNoWrap flexContentA">
<a href=""><img src="image/index_yunv.jpg" alt="" /></a>
<a href=""><img src="image/index_php_item2_.png" alt="" /></a>
<a href=""><img src="image/index_php_item3.jpg" alt="" /></a>
<a href=""><img src="image/index_php_new4.jpg" alt="" /></a>
</div>
</div>
</div>
<div class="box2">
<a href=""><img src="image/index_ad222.jpg" alt="" /></a>
</div>
<div class="box3 flexDis flexDirH flexNoWrap flexContentB">
<div class="box3-left flexDis flexDirV flexNoWrap flexContentB">
<h4>头条</h4>
<a href=""
>php中文网原创视频:《天龙八部》公益php培训系列课程汇总!</a
>
<a href="">php中文网《玉女心经》公益PHP培训系列课程汇总</a>
<a href="">PHP 8 来了! PHP团队发布了首个测试版本 Alpha1</a>
<a href="">php的版本发展历史(1995-2020)</a>
<a href="">您知道吗?最好的语言:PHP 25 岁了!</a>
<a href="">史上最污技术解读,我竟然秒懂了</a>
<a href="">2020年最新5个简洁优秀的个人博客模板免费下载</a>
<a href="">5款优秀的vue后台管理系统模板推荐(免费下载)</a>
<a href="">6个大气的bootstrap后台管理系统模板推荐(免费下载)</a>
<a href="">5款简洁的layui后台管理模板推荐(免费下载)</a>
<a href="">5款个性的网页回到顶部特效代码</a>
<a href="">小皮面板 v0.53 版本今日发布!</a>
</div>
<div class="box3-center flexDis flexDirV flexNoWrap">
<h4>最新课程</h4>
<div class="center-item flexDis flexDirH flexWrap">
<a href="">
<img src="image/5eeb3345b206d506.jpg" alt="" />
<h3><i>中级</i>PHP代码整洁之道</h3>
</a>
<a href="">
<img src="image/5eec277230a4a933.png" alt="" />
<h3><i>初级</i>前端课程(五郞八卦棍系列)第一棍:HTML5</h3>
</a>
<a href="">
<img src="image/5ecbc289676f6665.png" alt="" />
<h3><i>初级</i>小皮面板使用视频教程</h3>
</a>
<a href="">
<img src="image/5eba3e40b2fc6218.jpg.png" alt="" />
<h3><i>初级</i>从零进入C语言</h3>
</a>
<a href="">
<img src="image/5eb5222662408719.jpg.png" alt="" />
<h3><i>中级</i>C语言进阶篇</h3>
</a>
<a href="">
<img src="image/5e0d6387e45cc764.png" alt="" />
<h3><i>中级</i>PHP快速操控Excel之PhpSpreadsheet</h3>
</a>
</div>
</div>
<div class="box3-right flexDis flexDirV flexNoWrap">
<h4 class="flexDis flexDirH flexNoWrap flexContentB">
常用手册<a href="">更多</a>
</h4>
<div class="right-item flexDis flexDirH flexNoWrap">
<img src="image/57d55fe881432245.jpg.png" alt="" />
<div class="item-link flexDis flexDirH flexWrap flexAlignC">
<a href="">php手册</a>
<a href="">Linux手册</a>
<a href="">ThinkPHP6.0</a>
<a href="">CI手册大全</a>
</div>
</div>
<div class="right-item flexDis flexDirH flexNoWrap">
<img src="image/57d55f537896d439.jpg.png" alt="" />
<div class="item-link flexDis flexDirH flexWrap flexAlignC">
<a href="">JavaScript中文参考手册</a>
<a href="">jQuery手册大全</a>
</div>
</div>
<div class="right-item flexDis flexDirH flexNoWrap">
<img src="image/57d560a2c0e5f831.jpg.png" alt="" />
<div class="item-link flexDis flexDirH flexWrap flexAlignC">
<a href="">MySQL参考手册大全</a>
<a href="">laravel5.8速查表</a>
</div>
</div>
<div class="right-item flexDis flexDirH flexNoWrap">
<img src="image/57d56222bfab2642.jpg.png" alt="" />
<div class="item-link flexDis flexDirH flexWrap flexAlignC">
<a href="">Python参考手册大全</a>
<a href="">Node.js中文学习手册</a>
</div>
</div>
<div class="right-item flexDis flexDirH flexNoWrap">
<img src="image/57d55f07ccfb6991.jpg.png" alt="" />
<div class="item-link flexDis flexDirH flexWrap flexAlignC">
<a href="">html手册</a>
<a href="">CSS手册</a>
<a href="">AngularJS</a>
<a href="">Ajax手册</a>
</div>
</div>
<div class="right-item flexDis flexDirH flexNoWrap">
<img src="image/5a911102396d0195.jpg" alt="" />
<div class="item-link flexDis flexDirH flexWrap flexAlignC">
<a href="">ASP参考手册大全</a>
<a href="">Bootstrap3参考手册</a>
</div>
</div>
</div>
</div>
</main>
<footer class="flexDis flexDirV flexNoWrap">
<div class="nav-bottom flexDis flexDirH flexNoWrap flexContentS">
<a href="">网站首页</a>
<a href="">PHP视频</a>
<a href="">PHP实战</a>
<a href="">PHP代码</a>
<a href="">PHP手册</a>
<a href="">词条</a>
<a href="">手记</a>
<a href="">编程词典</a>
</div>
<p>
php中文网:公益在线php培训,帮助PHP学习者快速成长!
<a href=""><img src="image/label_lg_90030.png" alt="" /></a>
合肥彼岸互联信息技术有限公司
</p>
<p>
Copyright 2014-2020 https://www.php.cn/ All Rights Reserved |
皖B2-20150071-9
</p>
<p>
座机号码:0551-64933227 安徽省合肥市政务新区置地广场D座2101
</p>
</footer>
</body>
</html>
CSS
页面主体样式
header {
width: 100%;
height: 60px;
background-color: #000;
box-shadow: 0 4px 8px 0 rgba(7, 17, 27, 0.1);
}
header > a {
height: 60px;
line-height: 60px;
margin: 0 10px;
padding: 0 20px;
color: rgba(255, 255, 255, 0.7);
}
header > a:first-of-type {
width: 160px;
height: 60px;
background: url(../image/logo.png) no-repeat center center;
}
header > a:nth-last-of-type(2) {
/* 后面两项靠左 */
margin-left: auto;
}
header > a:not(:first-of-type):hover {
color: #fff;
border-bottom: 5px solid seagreen;
}
main {
width: 1200px;
}
main > .box1 {
width: inherit;
height: 510px;
overflow: hidden;
margin-top: 30px;
background-color: #fff;
border-radius: 8px;
box-shadow: 0 12px 24px 0 rgba(7, 17, 27, 0.2);
}
main > .box1 > ul {
width: 216px;
height: 510px;
background-color: #2b333b;
border-top-left-radius: 4px;
border-bottom-left-radius: 4px;
}
/* 左导航 */
main > .box1 > ul > li {
width: 100%;
height: 60px;
}
main > .box1 > ul > li:hover {
color: #fff;
background-color: gray;
}
main > .box1 > ul > li > a {
color: rgba(255, 255, 255, 0.6);
height: 60px;
line-height: 60px;
padding: 0 16px;
font-size: 16px;
}
/* 上导航 */
main > .box1 > .submeun > .submeun-list {
width: 100%;
height: 60px;
}
main > .box1 > .submeun > .submeun-list input {
width: 260px;
height: 40px;
padding-left: 12px;
background-color: #f1f0f0;
border: none 0;
font-size: 12px;
}
main > .box1 > .submeun > .submeun-list a:hover {
color: #777;
}
main > .box1 > .submeun > .submeun-buttom {
margin-bottom: 10px;
}
main > .box1 > .submeun > .submeun-buttom img {
border-radius: 8px;
}
main > .box2 img {
margin-top: 20px;
border-radius: 8px;
}
main > .box3 {
width: inherit;
height: 416px;
margin-top: 20px;
padding: 15px 0;
}
main > .box3 h4 {
height: 35px;
line-height: 35px;
margin-bottom: 10px;
padding: 0 15px;
border-bottom: 1px dotted #e9e9e9;
color: #343535;
border-radius: 2px 2px 0 0;
}
main > .box3 > .box3-left {
width: 300px;
height: 100%;
margin-right: 10px;
padding: 0 10px 10px 10px;
box-shadow: 0 4px 8px 0 rgba(7, 17, 27, 0.05);
border-radius: 8px;
background: #fff;
}
main > .box3 > .box3-left > a {
width: 100%;
overflow: hidden;
margin-bottom: 10px;
white-space: nowrap;
}
main a:hover {
color: #777;
}
main > .box3 > .box3-center {
width: 620px;
height: 100%;
padding: 0 20px 20px 20px;
box-shadow: 0 4px 8px 0 rgba(7, 17, 27, 0.05);
border-radius: 8px;
background: #fff;
}
main > .box3 > .box3-center a {
width: 172px;
height: 140px;
margin: 10px 10px 20px 10px;
box-shadow: 0 5px 10px 0 rgba(0, 0, 0, 0.1);
border-radius: 8px;
position: relative;
}
main > .box3 > .box3-center img {
width: 170px;
height: 90px;
margin-bottom: 10px;
border-radius: 8px;
}
main > .box3 > .box3-center h3 {
width: 100%;
height: 144px;
background-color: #fff;
border-radius: 8px;
padding-left: 10px;
font-size: 14px;
max-height: 40px;
line-height: 21px;
position: absolute;
top: 70px;
}
main > .box3 > .box3-center h3 > i {
font-style: normal;
font-size: 12px;
line-height: 12px;
border-radius: 1px;
background-color: #93999f;
margin-right: 4px;
}
main > .box3 > .box3-right {
width: 260px;
padding: 5px 15px 15px 15px;
box-shadow: 0 4px 8px 0 rgba(7, 17, 27, 0.05);
border-radius: 8px;
background: #fff;
}
main > .box3 > .box3-right .right-item {
padding-bottom: 20px;
}
main > .box3 > .box3-right > .right-item img {
width: 40px;
margin-right: 10px;
}
main > .box3 > .box3-right .item-link > a {
font-size: 12px;
margin-right: 15px;
}
footer {
width: 100%;
background-color: #393d49;
}
footer > * {
width: 1200px;
margin: auto;
}
.nav-bottom > a {
height: 50px;
line-height: 50px;
font-size: 12px;
color: #c8cdd2;
margin: 0 8px;
}
.nav-bottom > a:hover {
color: #fff;
}
footer > p {
font-size: 11px;
color: #787d82;
padding: 12px;
}
footer > p img {
width: 50px;
}
flex通用布局样式
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
overflow: hidden;
overflow-y: auto;
background-color: #f3f5f7;
font: 14px Helvetica Neue, Helvetica, PingFang SC, 微软雅黑, Tahoma, Arial,
sans-serif;
}
a {
color: #444;
text-decoration: none;
}
li,
dd {
list-style: none;
}
button,
img {
border: none;
outline: none;
}
.flexDis {
display: -webkit-flex;
display: -moz-flex;
display: -o-flex;
display: -ms-flexbox;
display: flex;
}
.flexShrinkStatic {
flex-shrink: 0;
}
.flexShrinkAuto {
flex-shrink: 1;
}
.flexDirV {
flex-direction: column;
}
.flexDirH {
flex-direction: row;
}
.flexWrap {
flex-wrap: wrap;
}
.flexNoWrap {
flex-wrap: nowrap;
}
.flexContentS {
justify-content: flex-start;
}
.flexContentC {
justify-content: center;
}
.flexContentV {
justify-content: space-evenly;
}
.flexContentA {
justify-content: space-around;
}
.flexContentB {
justify-content: space-between;
}
.flexAlignS {
align-items: flex-start;
}
.flexAlignC {
align-items: center;
}
.flexAlignE {
align-items: flex-end;
}
.flexAlignB {
align-items: baseline;
}
.flexAlignT {
align-items: stretch;
}
实际效果
总结
- PHP中文网的内容很多,在此只实现了页眉页脚以及简单的主体部分网页设计
- 还有一些弹出菜单没有做到
- 使用flex布局能够快速实现项目的分布对齐等操作
- CSS样式表还需要多练习 部分语句还可以精简