Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537 Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537
(OF作品展示)
OF之前介紹了用python實(shí)現(xiàn)數(shù)據(jù)可視化、數(shù)據(jù)分析及一些小項(xiàng)目,但基本都是后端的知識。想要做一個(gè)好看的小系統(tǒng),我們還要學(xué)一些前端的知識,今天OF將講解如何用pycharm(全棧開發(fā)不錯(cuò)的工具)做一張好看的網(wǎng)頁,以后我們就可以自己開發(fā)網(wǎng)頁/網(wǎng)站放到互聯(lián)網(wǎng)上。
主要內(nèi)容:網(wǎng)頁前端布局
適用人群:Python初學(xué)者,前端初學(xué)者
準(zhǔn)備軟件:pycharm
1) 下載完成pycharm, 點(diǎn)擊file-New Project...
2) 按下圖步驟創(chuàng)建一個(gè)項(xiàng)目,目前我們選擇Pure python即可,以后我們可以學(xué)習(xí)用Django/flask等框架來做完整的系統(tǒng)
1)在創(chuàng)建的項(xiàng)目空白處鼠標(biāo)右鍵-New-HTML File
2)輸入英文的網(wǎng)頁名字,盡量不要輸入中文/特殊字符
當(dāng)雙擊打開我們創(chuàng)建后的HTML文件,大家會看到下面的界面
在開始開發(fā)網(wǎng)頁前,我們需要自己設(shè)計(jì)下想要把網(wǎng)頁做成什么樣,為了節(jié)省成本OF都是自己設(shè)計(jì)的頁面樣式,可以手繪,也可以在PPT上畫。
我們先學(xué)習(xí)一個(gè)比較簡單的布局如下圖,大家可以看到下圖已經(jīng)畫出了我們需要添加的內(nèi)容,要注意的地方是比如Taylor的圖片和文字一定要用<div class=bord>框住,否則Taylor圖片與文字將會是左右的關(guān)系,而不是上下
根據(jù)上述的css名字定義,先填充<body>內(nèi)的代碼,那么我們就完成一半的工作了,代碼如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div id="intro">
<p class="peo">人物介紹</p>
</div>
<div id="pic1">
<div class="bord">
<img class="img" src="pic/Taylor.png"/>
<p class="word">Taylor</p>
</div>
<div class="bord">
<img class="img" src="pic/yan.png"/>
<p class="word">東</p>
</div>
<div class="bord">
<img class="img" src="pic/song.png"/>
<p class="word">喬</p>
</div>
</div>
</body>
</html>
1)鼠標(biāo)移到代碼處,在右上角我們會看到一排瀏覽器,我們點(diǎn)擊其中一個(gè)運(yùn)行
2)目前看到的網(wǎng)頁內(nèi)容從上到下顯示
首先我們簡要了解下flex布局,大家可以看到下圖中#main的style樣式中display:flex,在body部分將3個(gè)顏色內(nèi)容框在<div id="main">中,運(yùn)行結(jié)果是3個(gè)顏色的內(nèi)容橫向展示了,而不是上下
1)那么我們先從“人物介紹”的布局開始,“人物介紹”居中展現(xiàn)(用flex中justify-content:center),而且下面有一條黑線,OF準(zhǔn)備用border樣式來實(shí)現(xiàn),所以在<div id=intro>里另加了個(gè)<div class=peo>,代碼如下:
(注:style中的#main對應(yīng)body中的id=main, .main對應(yīng)class=main)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
#intro {
display: -webkit-flex; /* Safari */
display: flex;
justify-content: center;
}
.peo {
max-width: 10rem;
border-bottom: 0.2rem solid #000000;
font-family: sans-serif;
font-size: 1.5rem;
color: #0070C0;
line-height: 3rem;
}
</style>
</head>
<body>
<div id="intro">
<p class="peo">人物介紹</p>
</div>
<div id="pic1">
<div class="bord">
<img class="img" src="pic/Taylor.png"/>
<p class="word">Taylor</p>
</div>
<div class="bord">
<img class="img" src="pic/yan.png"/>
<p class="word">東</p>
</div>
<div class="bord">
<img class="img" src="pic/song.png"/>
<p class="word">喬</p>
</div>
</div>
</body>
</html>
運(yùn)行結(jié)果:
2)圖片部分是3個(gè)<div class=bord>橫向展示,所以要在框住它們的<div id=pic1>樣式中設(shè)置flex布局,在<style>里加入以下代碼:
#pic1 {
display: -webkit-flex; /* Safari */
display: flex;
justify-content: center;
}
運(yùn)行結(jié)果:
3)圖片之間靠太近,圖片大小不一致,文字沒居中,我們在<style>里加入以下代碼:
.bord{
padding: 1rem 2rem;
}
.img {
border: 0.2rem solid #e3e3e3;
max-width: 15rem;
height: 22rem;
}
.word {
text-align: center;
}
運(yùn)行結(jié)果:
今天我們學(xué)會了flex布局,今后所有的網(wǎng)頁排版都可以實(shí)現(xiàn)了,祝愿大家都有所收獲,完整的代碼如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
#intro {
display: -webkit-flex; /* Safari */
display: flex;
justify-content: center;
}
.peo {
max-width: 10rem;
border-bottom: 0.2rem solid #000000;
font-family: sans-serif;
font-size: 1.5rem;
color: #0070C0;
line-height: 3rem;
}
#pic1 {
display: -webkit-flex; /* Safari */
display: flex;
justify-content: center;
}
.bord{
padding: 1rem 2rem;
}
.img {
border: 0.2rem solid #e3e3e3;
max-width: 15rem;
height: 22rem;
}
.word {
text-align: center;
}
</style>
</head>
<body>
<div id="intro">
<p class="peo">人物介紹</p>
</div>
<div id="pic1">
<div class="bord">
<img class="img" src="pic/Taylor.png"/>
<p class="word">Taylor</p>
</div>
<div class="bord">
<img class="img" src="pic/yan.png"/>
<p class="word">東</p>
</div>
<div class="bord">
<img class="img" src="pic/song.png"/>
<p class="word">喬</p>
</div>
</div>
</body>
</html>
今天的知識比較基礎(chǔ)但非常實(shí)用,每天學(xué)會一個(gè)小技能,積少成多,以后就能成為大神。如果大家對網(wǎng)頁上的實(shí)現(xiàn)有什么不懂的,盡請留言,OF一定會一一解答的。
者:sunshine小小倩
轉(zhuǎn)發(fā)鏈接:https://juejin.im/post/599970f4518825243a78b9d5
我們剛開始學(xué)習(xí)Web前端時(shí),就對HTML頁面的布局特別感興趣,上一講《CSS初步介紹》中,講解了CSS的入門知識,現(xiàn)在我們介紹一下HTML布局的知識。
HTML布局的方案有Table布局、最流行的DIV布局、以及HTML5建議的DIV布局的替代方案。
當(dāng)HTML內(nèi)容被瀏覽器顯示時(shí),整個(gè)HTML頁面對使用者來說,就是一個(gè)顯示信息與進(jìn)行操作的界面。我們常常見到和下面類似的界面:
在這個(gè)界面中,整個(gè)HTML網(wǎng)頁被分為標(biāo)題區(qū)、導(dǎo)航區(qū)、內(nèi)容去、狀態(tài)欄區(qū),下面我們分別用Table布局、DIV布局和HTML5建議的布局方案來實(shí)現(xiàn)該界面。
使用Table布局方案,將整個(gè)瀏覽器的展示部分就是一個(gè)表格,然后我們設(shè)置好表格的單元格合并、大小即可。下面是使用Table布局方案的HTML頁面:
<!DOCTYPE html>
<html>
<head>
<title>layout001</title>
<meta charset="utf-8" />
<style type="text/css">
html,body, table{
width:100%;
height:100%;
}
#first_row{
height:6%;
}
#second_row{
height:91%;
}
#third_row{
height:3%;
}
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
#header{
border:1px black solid;
color:white;
text-align:center;
background:green;
}
#navigator{
border:1px black solid;
color:white;
text-align:center;
background:blue;
}
#content{
border:1px black solid;
color:white;
text-align:center;
background:gray;
}
#footer{
border:1px black solid;
color:white;
text-align:center;
background:orange;
}
</style>
</head>
<body>
<table>
<tr id="first_row">
<td id="header" colspan="2">標(biāo)題區(qū)</td>
</tr>
<tr id="second_row">
<td id="navigator" width="15%">導(dǎo)航區(qū)</td>
<td id="content" width="85%">內(nèi)容區(qū)</td>
</tr>
<tr id="third_row">
<td id="footer" colspan="2">狀態(tài)欄區(qū)</td>
</tr>
</table>
</body>
</html>
使用瀏覽器打開這個(gè)HTML文檔,展示效果如下:
這個(gè)框架建立后,我們就可以在各個(gè)<td>內(nèi)進(jìn)行具體的開發(fā)了。
使用DIV布局方案,將整個(gè)瀏覽器的展示部分由各個(gè)DIV來分配。下面是使用DIV布局方案的HTML頁面:
<!DOCTYPE html>
<html>
<head>
<title>layout002</title>
<meta charset="utf-8" />
<style type="text/css">
html,body{
width:100%;
height:100%;
}
body,#header,#second_row,#navigator,#content,#footer{
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
#header{
height:6%;
width:100%;
color:white;
text-align:center;
background:green;
}
#second_row{
height:91%;
width:100%;
}
#navigator{
height:100%;
width:15%;
float:left;
color:white;
text-align:center;
background:blue;
}
#content{
height:100%;
width:85%;
float:right;
color:white;
text-align:center;
background:gray;
}
#footer{
height:3%;
width:100%;
color:white;
text-align:center;
background:orange;
}
</style>
</head>
<body>
<div id="header">
標(biāo)題區(qū)
</div>
<div id="second_row">
<div id="navigator">
導(dǎo)航區(qū)
</div>
<div id="content">
內(nèi)容區(qū)
</div>
</div>
<div id="footer">
狀態(tài)欄區(qū)
</div>
</body>
</html>
使用瀏覽器打開這個(gè)HTML文檔,展示效果如下:
這個(gè)框架建立后,我們就可以在各個(gè)<div>內(nèi)進(jìn)行具體的開發(fā)了。
可以發(fā)現(xiàn),使用DIV元素,我們對頁面進(jìn)行布局時(shí)更方便。
使用DIV布局方案,使用起來特別方便,基本上是前端開發(fā)者的首選。不過在HTML5標(biāo)準(zhǔn)來看,各個(gè)DIV的含義不明確,因此建議使用專門的元素來替代DIV。這是按照HTML5推薦的布局方案的頁面:
<!DOCTYPE html>
<html>
<head>
<title>layout003</title>
<meta charset="utf-8" />
<style type="text/css">
html,body{
width:100%;
height:100%;
}
body,header,#second_row,nav,main,footer{
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
header{
height:6%;
width:100%;
color:white;
text-align:center;
background:green;
}
#second_row{
height:91%;
width:100%;
}
nav{
height:100%;
width:15%;
float:left;
color:white;
text-align:center;
background:blue;
}
main{
height:100%;
width:85%;
float:right;
color:white;
text-align:center;
background:gray;
}
footer{
height:3%;
width:100%;
color:white;
text-align:center;
background:orange;
}
</style>
</head>
<body>
<header>
標(biāo)題區(qū)
</header>
<div id="second_row">
<nav>
導(dǎo)航區(qū)
</nav>
<main>
內(nèi)容區(qū)
</main>
</div>
<footer>
狀態(tài)欄區(qū)
</footer>
</body>
</html>
使用瀏覽器打開這個(gè)HTML文檔,展示效果和上面的一模一樣:
使用這種方案,除了使用了含義明確的<header>、<nav>、<main>、<footer>元素外,和DIV方案沒有區(qū)別。
這種做法貌似HTML更清晰,但實(shí)際上增加了元素的種類,增加了開發(fā)人員的記憶負(fù)擔(dān),容易出錯(cuò)。因此,前端程序員基本上都不喜歡這種方案。
*請認(rèn)真填寫需求信息,我們會在24小時(shí)內(nèi)與您取得聯(lián)系。