TML和CSS中的幾何圖形案例
HTML代碼
<div class="container"></div> <div class="container2"></div> <div class="container3"></div> <div class="container4"></div> <div class="star"></div> <div class="star2"></div> <div class="star3"></div> <div class="star4"></div> <div class="star5"></div> <div class="star6"></div> <div class="center"></div> <div class="center2"></div> <div class="center3"></div> <div class="center4"></div> <div class="center5"></div> <div class="center6"></div>
css代碼
html,body,div {width:100%;height:100%;} body {background:#2f2933;overflow:hidden;} div { position:absolute; left:0; right:0; top:0; bottom:0; margin-right:auto; margin-left:auto; margin-top:auto; margin-bottom:auto; } .container,.center6 { background-color:#ffffa6; background-image: -webkit-gradient(linear,left top,left bottom,color-stop(0, #ffffa6),color-stop(1, #bdf271)); background-image: -o-linear-gradient(bottom, #ffffa6 0%, #bdf271 100%); background-image: -moz-linear-gradient(bottom, #ffffa6 0%, #bdf271 100%); background-image: -webkit-linear-gradient(bottom, #ffffa6 0%, #bdf271 100%); background-image: -ms-linear-gradient(bottom, #ffffa6 0%, #bdf271 100%); background-image: linear-gradient(to bottom, #ffffa6 0%, #bdf271 100%); } .container2,.center5 { background-color:#bdf271; background-image: -webkit-gradient(linear,left top,left bottom,color-stop(0, #bdf271),color-stop(1, #29d9c2)); background-image: -o-linear-gradient(bottom, #bdf271 0%, #29d9c2 100%); background-image: -moz-linear-gradient(bottom, #bdf271 0%, #29d9c2 100%); background-image: -webkit-linear-gradient(bottom, #bdf271 0%, #29d9c2 100%); background-image: -ms-linear-gradient(bottom, #bdf271 0%, #29d9c2 100%); background-image: linear-gradient(to bottom, #bdf271 0%, #29d9c2 100%); -webkit-animation-delay:200ms; -moz-animation-delay:200ms; -o-animation-delay:200ms; animation-delay:200ms; } .container3,.center4 { background-color:#29d9c2; background-image: -webkit-gradient(linear,left top,left bottom,color-stop(0, #29d9c2),color-stop(1, #01a2a6)); background-image: -o-linear-gradient(bottom, #29d9c2 0%, #01a2a6 100%); background-image: -moz-linear-gradient(bottom, #29d9c2 0%, #01a2a6 100%); background-image: -webkit-linear-gradient(bottom, #29d9c2 0%, #01a2a6 100%); background-image: -ms-linear-gradient(bottom, #29d9c2 0%, #01a2a6 100%); background-image: linear-gradient(to bottom, #29d9c2 0%, #01a2a6 100%); -webkit-animation-delay:400ms; -moz-animation-delay:400ms; -o-animation-delay:400ms; animation-delay:400ms; } .container4,.center { background-color:#f4f4f4; background-image: -webkit-gradient(linear,left top,left bottom,color-stop(0, #f4f4f4),color-stop(1, #2f2933)); background-image: -o-linear-gradient(bottom, #f4f4f4 0%, #2f2933 100%); background-image: -moz-linear-gradient(bottom, #f4f4f4 0%, #2f2933 100%); background-image: -webkit-linear-gradient(bottom, #f4f4f4 0%, #2f2933 100%); background-image: -ms-linear-gradient(bottom,#f4f4f4 0%, #2f2933 100%); background-image: linear-gradient(to bottom, #f4f4f4 0%, #2f2933 100%); -webkit-animation-delay:600ms; -moz-animation-delay:600ms; -o-animation-delay:600ms; animation-delay:600ms; } .container,.container2,.container3,.container4 { -webkit-animation:container 1s infinite linear; -moz-animation:container 1s infinite linear; -o-animation:container 1s infinite linear; animation:container 1s infinite linear; opacity:0.5; } .container{ width:400px; height:400px; border-radius:200px; z-index:6; } .container2 { width:500px; height:500px; border-radius:250px; z-index:5; } .container3 { width:600px; height:600px; border-radius:300px; z-index:4; } .container4 { width:700px; height:700px; border-radius:350px; z-index:3; } .star,.star:after,.star2,.star2:after,.star3,.star3:after,.star4,.star4:after,.star5,.star5:after,.star6,.star6:after { width: 0; height: 0; border-left: 130px solid transparent; border-right: 130px solid transparent; } .star,.star2,.star3,.star4,.star5,.star6 {top:-5%;} .star:after,.star2:after,.star3:after,.star4:after,.star5:after,.star6:after { position: absolute; content: ""; top: 60px; left: -130px; } .star {border-bottom: 250px solid #ff4669;z-index:12;} .star:after {border-top: 250px solid #ff4669;} .star2 { border-bottom: 250px solid #ff86c1; z-index:11; -webkit-transform: rotate(-30deg) translateX(-15px) translateY(0px); -moz-transform: rotate(-30deg) translateX(-15px) translateY(0px); -o-transform: rotate(-30deg) translateX(-15px) translateY(0px); transform: rotate(-30deg) translateX(-15px) translateY(0px); } .star2:after {border-top: 250px solid #ff86c1;} .star3{ border-bottom: 250px solid #ff4691; z-index:10; -webkit-transform: rotate(-35deg) translateX(-15px) translateY(0px); -moz-transform: rotate(-35deg) translateX(-15px) translateY(0px); -o-transform: rotate(-35deg) translateX(-15px) translateY(0px); transform: rotate(-35deg) translateX(-15px) translateY(0px); } .star3:after {border-top: 250px solid #ff4691;} .star4{ border-bottom: 250px solid #ff4691; z-index:9; -webkit-transform: rotate(-40deg) translateX(-15px) translateY(0px); -moz-transform: rotate(-40deg) translateX(-15px) translateY(0px); -o-transform: rotate(-40deg) translateX(-15px) translateY(0px); transform: rotate(-40deg) translateX(-15px) translateY(0px); } .star4:after {border-top: 250px solid #ff4669;} .star5{ border-bottom: 250px solid #ff4669; z-index:8; -webkit-transform: rotate(-45deg) translateX(-15px) translateY(0px); -moz-transform: rotate(-45deg) translateX(-15px) translateY(0px); -o-transform: rotate(-45deg) translateX(-15px) translateY(0px); transform: rotate(-45deg) translateX(-15px) translateY(0px); } .star5:after {border-top: 250px solid #ff4669;} .star6{ border-bottom: 250px solid #ff4669; z-index:7; -webkit-transform: rotate(-50deg) translateX(-15px) translateY(0px); -moz-transform: rotate(-50deg) translateX(-15px) translateY(0px); -o-transform: rotate(-50deg) translateX(-15px) translateY(0px); transform: rotate(-50deg) translateX(-15px) translateY(0px); } .star6:after {border-top: 250px solid #ff4669;} .center,.center2,.center3,.center4,.center5,.center6 { -webkit-animation:container 1s infinite linear; -moz-animation:container 1s infinite linear; -o-animation:container 1s infinite linear; animation:container 1s infinite linear; opacity:0.5; } .center { width:60px; height:60px; border-radius:30px; z-index:13; } .center2 { width:50px; height:50px; border-radius:25px; background:#2f2933; z-index:14; } .center3 { width:40px; height:40px; border-radius:20px; background:#2f2933; z-index:15; } .center4 { width:30px; height:30px; border-radius:15px; z-index:16; } .center5 { width:20px; height:20px; border-radius:10px; z-index:17; } .center6 { width:10px; height:10px; border-radius:5px; z-index:18; } /*animation container*/ @-webkit-keyframes container { 0% {-webkit-transform:rotate(0deg);transform:rotate(0deg);} 100% {-webkit-transform:rotate(360deg);transform:rotate(360deg);} } @-moz-keyframes container { 0% {-moz-transform:rotate(0deg);transform:rotate(0deg);} 100% {-moz-transform:rotate(360deg);transform:rotate(360deg);} } @-o-keyframes container { 0% {-o-transform:rotate(0deg);transform:rotate(0deg);} 100% {-o-transform:rotate(360deg);transform:rotate(360deg);} } @keyframes container { 0% {transform:rotate(0deg);} 100% {transform:rotate(360deg);} }
(本文如有侵權,請聯系作者,必刪)
kinter(也叫Tk接?)是Tk圖形?戶界??具包標準的Python接?。Tk是?個輕量級的跨平臺圖形?戶界?(GUI)開發?具。
Tkinter是Python自帶的官方標準庫,安裝Python之后直接導入就可以使用,我們常見的python IDLE就是使用TKinter實現的。
在Win10命令行窗口輸入python、import tkinter、dir(tkinter)、help(tkinter),可獲得tkinter的相關幫助信息。
help(tkinter)命令的執行結果,列出了模塊幫助文檔的鏈接: https://docs.python.org/3.10/library/tkinter.html
實現打開并顯示圖片的源代碼如下:
import tkinter as tk
import tkinter.filedialog
from PIL import Image,ImageTk
#選擇并顯示圖片
def choosepic():
path_ = tkinter.filedialog.askopenfilename()
path.set(path_)
print(path)
img_open = Image.open(entry.get())
#img = ImageTk.PhotoImage(img_open.resize((200,200)))
img = ImageTk.PhotoImage(img_open)
lableShowImage.config(image=img)
lableShowImage.image = img
if __name__ == '__main__':
#生成tk界面 app即主窗口
app = tk.Tk()
#修改窗口titile
app.title("顯示圖片")
#設置主窗口的大小和位置
app.geometry("800x400+200+200")
#Entry widget which allows displaying simple text.
path = tk.StringVar()
entry = tk.Entry(app, state='readonly', text=path,width = 100)
entry.pack()
#使用Label顯示圖片
lableShowImage = tk.Label(app)
lableShowImage.pack()
#選擇圖片的按鈕
buttonSelImage = tk.Button(app, text='選擇圖片', command=choosepic)
buttonSelImage.pack()
#buttonSelImage.pack(side=tk.BOTTOM)
#Call the mainloop of Tk.
app.mainloop()
假設將源代碼保存在文件“d:\temp\MyShowImage.py”。在命令行執行命令
python d:\temp\MyShowImage.py
程序運行,界面如下圖所示
Tkinter(也叫Tk接?)是Tk圖形?戶界??具包標準的Python接?。Tk是?個輕量級的跨平臺圖形?戶界?(GUI)開發?具。
Tkinter是Python自帶的官方標準庫,安裝Python之后直接導入就可以使用,我們常見的python IDLE就是使用TKinter實現的。
在Win10命令行窗口輸入python、import tkinter、dir(tkinter)、help(tkinter),可獲得tkinter的相關幫助信息。
help(tkinter)命令的執行結果,列出了模塊幫助文檔的鏈接: https://docs.python.org/3.10/library/tkinter.html
實現打開并顯示圖片的源代碼如下:
import tkinter as tk
import tkinter.filedialog
from PIL import Image,ImageTk
#選擇并顯示圖片
def choosepic():
path_ = tkinter.filedialog.askopenfilename()
path.set(path_)
print(path)
img_open = Image.open(entry.get())
#img = ImageTk.PhotoImage(img_open.resize((200,200)))
img = ImageTk.PhotoImage(img_open)
lableShowImage.config(image=img)
lableShowImage.image = img
if __name__ == '__main__':
#生成tk界面 app即主窗口
app = tk.Tk()
#修改窗口titile
app.title("顯示圖片")
#設置主窗口的大小和位置
app.geometry("800x400+200+200")
#Entry widget which allows displaying simple text.
path = tk.StringVar()
entry = tk.Entry(app, state='readonly', text=path,width = 100)
entry.pack()
#使用Label顯示圖片
lableShowImage = tk.Label(app)
lableShowImage.pack()
#選擇圖片的按鈕
buttonSelImage = tk.Button(app, text='選擇圖片', command=choosepic)
buttonSelImage.pack()
#buttonSelImage.pack(side=tk.BOTTOM)
#Call the mainloop of Tk.
app.mainloop()
假設將源代碼保存在文件“d:\temp\MyShowImage.py”。在命令行執行命令
python d:\temp\MyShowImage.py
程序運行,界面如下圖所示
點擊“選擇圖片”按鈕,彈出打開文件對話框,
選擇要打開的圖片文件,點擊“打開”按鈕,圖片就會顯示在圖形界面上了,如下圖所示:
上述代碼實現了圖片的選擇和顯示功能,但也有不足之處,比如“沒有滾動條,無法完全顯示比屏幕大的圖片”。
(1)https://blog.csdn.net/xyzhan/article/details/113856833 (2021年開發Python圖形用戶界面(GUI)的6種最佳Python GUI框架)
(2)https://wenku.baidu.com/view/8f03733bf9d6195f312b3169a45177232e60e44d.html (推薦8款常?的PythonGUI圖形界?開發框架)
(3)https://github.com/honghaier-game/TKinterDesigner (honghaier-game/TKinterDesigner)
(4)https://blog.csdn.net/HG0724/article/details/112248635 (Python之Tkinter進行GUI開發)
(5)https://blog.csdn.net/wj0807/article/details/120890111 (在tkinter中顯示圖片和圖片名)
(6)https://www.cnpython.com/qa/58793 (如何在gui中使用tkinter顯示圖像)
(7)https://m.php.cn/article/419452.html (python idle是什么)
(8)https://docs.python.org/3.10/library/tkinter.html (tkinter — Python interface to Tcl/Tk)
(9)https://blog.csdn.net/tyler880/article/details/106862322?spm=1001.2101.3001.6650.1&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1-106862322-blog-112248635.pc_relevant_aa&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1-106862322-blog-112248635.pc_relevant_aa&utm_relevant_index=2 (python GUI編程(Tkinter))
(10)https://www.cnpython.com/qa/308976 (用滾動條在Tkinter中顯示多個圖像)
維網和其它網絡類型最大的區別就是它在網頁上可呈現豐富多彩的色彩和圖像,還可以播放音頻、視頻,及把圖像作為鏈接使用。
網絡上流行的圖片格式主要有jpg、jpeg、png、gif等,以下是這幾種格式的介紹。
1、gif格式
gif采用LZW壓縮,是以壓縮相同顏色色塊來減少圖像大小。由于LZW壓縮不會造成任何品質的損失,且壓縮率高,支持動畫效果,很適合互聯網平臺,但是它只支持256種顏色。
2、jpg或jpeg格式
以JPEG有損壓縮圖片,通常用來保存超過256色的圖片格式。JPEG壓縮過程會對一些圖像數據造成損失,這部分損失不影響圖片顯示,一般人眼是看不出來差異的。損失數據越多,圖片就越不清晰。
3、png格式
png是一種非破壞性的網頁圖像文件格式,它以最小的方式壓縮圖片且不造成圖片數據損失。它不僅支持像gif大部分優點,還支持48 bit的色彩,跨平臺的圖像亮度控制,更多層的透明度設置。
網頁中通過<img>標簽插入圖片,語法如下:
<img src="圖片路徑" alt="替換文本" />
具體示例:
<!DOCTYPE HTML>
<html>
<body>
<p>
一幅圖像:
<img src="/i/eg_mouse.jpg" width="128" height="128" />
</p>
<p>
一幅動畫圖像:
<img src="/i/eg_cute.gif" width="50" height="50" />
</p>
<p>請注意,插入動畫圖像的語法與插入普通圖像的語法沒有區別。</p>
</body>
</html>
效果如下:
替換文本屬性(Alt)
alt 屬性用來為圖像定義一串預備的可替換的文本。
<img src="boat.gif" alt="Big Boat">
當瀏覽器無法載入圖像時,替換文本屬性可告訴讀者他們失去的信息。此時,瀏覽器將顯示這個替代性的文本而不是圖像。為頁面上的圖像都加上替換文本屬性是個好習慣,這樣有助于更好地顯示信息,并且對于那些使用純文本瀏覽器的人來說是非常有用的。
圖像寬度和高度屬性
如下代碼,在網頁中插入一個寬度和高度都是300像素的圖片。
<img src="/i/ct_netscape.jpg" width="300px" height="300px" />
圖片超鏈接
如下代碼,在網頁中對一個圖片進行超鏈接設置,點擊這張圖片就會跳轉到其它頁面。
<a href="頁面路徑"><img src="/i/ct_netscape.jpg" /></a>
除了對整個圖片進行超鏈接設置外,還可以將圖像劃分成不同區域進行鏈接設置,比如一張地圖中給每個省份圖形進行超鏈接。
圖像熱區鏈接,使用usemap 屬性通過#name指定到名叫name的map元素上,map定義了每個熱區點擊區域形狀、大小、坐標等。
area標簽的 shape 屬性有三種,rect 方形,circle 圓形,poly 多邊形。coords 屬性定義坐標點位置,相對于圖片左上角位置。
示例代碼:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>W3Cschool(w3cschool.cn)</title>
</head>
<body>
<p>點擊太陽或其他行星,注意變化:</p>
<img src="/statics/images/course/planets.gif" width="145" height="126" alt="Planets" usemap="#planetmap">
<map name="planetmap">
<area shape="rect" coords="0,0,82,126" target="_blank" alt="Sun" href="/statics/images/course/sun.gif">
<area shape="circle" coords="90,58,3" target="_blank" alt="Mercury" href="/statics/images/course/merglobe.gif">
<area shape="circle" coords="124,58,8" target="_blank" alt="Venus" href="/statics/images/course/venglobe.gif">
</map>
</body>
</html>
效果可參考 https://www.w3cschool.cn/html5/html5-img.html 這里。
可以看到鼠標在圖片上點擊小行星會打開對應的圖片。
到此網頁中使用圖片已經大體介紹了,自己親手寫下,會加深印象,感謝關注。
上篇:前端入門——html 超鏈接
下篇:前端入門——html 如何在網頁中使用視頻音頻
*請認真填寫需求信息,我們會在24小時內與您取得聯系。