時間:2023-05-27 00:42:01 | 來源:網(wǎng)站運營
時間:2023-05-27 00:42:01 來源:網(wǎng)站運營
Html+CSS小案例項目:CSS開發(fā)小米商城電商產(chǎn)品展示效果:關(guān)于電商產(chǎn)品展示,無論是從首頁還是到欄目頁,再到產(chǎn)品的詳情頁,產(chǎn)品展示效果不僅僅是在電商平臺,在很多的企業(yè)網(wǎng)站也使用頻繁,今天為大家分享一個HTML+CSS小案例項目:小米電商平臺的商品展示頁面!我們來一起看看吧!<div class='product'></div>
(2)給product 添加寬度、高度 、背景顏色。這里的高度正常情況下是不能設(shè)置死,是為了方便大家理解看效果,所以加上的。后面我們會去掉.product{ width:268px;/*寬度*/ height:400px;/*高度*/ background-color: red;/*背景顏色*/}
(3)、清除body自帶的的默認樣式body{margin:0px;/*外邊距為0px*/}
(4)、設(shè)置.product 長方形盒子與瀏覽器頂部50px間距,同時水平居中顯示.product{margin:50px auto; /*上外邊距50px 左右外邊距自動相等-水平居中*/}
(5)、給盒子添加邊框線,,同時把添加的背景注釋掉。背景是為了開始演示效果.product{ /* background-color: red;背景顏色*/border:1px solid #ddd; /*1像素 實線 灰色邊框*/}
2、代碼<style type="text/css"> body{ margin:0px; } .product{ width:268px; height:400px; /* background-color: red; */ margin:50px auto; border:1px solid #ddd; }</style><div class="product"></div>
3、實現(xiàn)效果<body> <div class="product"> <!--img標簽,用來在頁面當中插入圖片--> <img src="images/kettle.png" alt="電水壺" width="195px"> </div></body>
(2)、設(shè)置圖片在水平方向居中顯示.product{text-align:center;/*設(shè)置內(nèi)容文字或圖片在盒子中水平居中*/}
2、代碼<style type="text/css">body{ margin:0px;}.product{ width:268px; height:400px; /* background-color: red; */ margin:50px auto; border:1px solid #ddd; text-align: center;/*文字和圖片水平居中*/}</style><body> <div class="product"> <img src="images/kettle.png" alt="電水壺" width="195px"> </div></body>
3、實現(xiàn)效果<body> <div class="product"> <img src="images/kettle.png" alt="電水壺" width="195px"> <p class='describe'>快速煮水,安心飲用</p> </div></body>
2、去掉h3自帶的默認margin外邊距樣式body,p{margin:0px;/*同時去掉body和h3標簽的默認外邊距*/}
3、修飾h3中的文字樣式.product p.describe{ font-size:16px ;/*字體大小*/ font-weight: 400;/*字體粗細*/ color:#845f3f;/*字體顏色*/ }
2、實現(xiàn)代碼<style type="text/css">body,h3{ margin:0px;}.product{ width:268px; height:400px; /* background-color: red; */ margin:50px auto; border:1px solid #ddd; text-align: center;}.product h3{ font-size:16px ; font-weight: 400; color:#845f3f;}</style><body> <div class="product"> <img src="images/kettle.png" alt="電水壺" width="195px"> <h3>快速煮水,安心飲用</h3> </div></body>
3、實現(xiàn)效果<body> <div class="product"> <img src="images/kettle.png" alt="電水壺" width="195px"> <p class="describe">快速煮水,安心飲用</h3> <div class="product-text"></div> </div></body>
2、我們給product-text 添加如下樣式。當然里添加的高度也是為了方便看效果,后面我們也會刪除。.product .product-text{ height:100px;/*高度-為了查看效果,后期會刪除*/ background-color: #f8f8f8;/*背景顏色*/ margin-top:20px;/*上外邊距20px*/ padding:15px;/*上下左右內(nèi)邊距15px*/ }
3、我們把最開始為了方便看效果,給.product添加的高度給刪除(或注釋).product{/*height:400px;*/}
2、實現(xiàn)代碼<style type="text/css">body,p{ margin:0px;}.product{ width:268px; /* height:400px; */ /* background-color: red; */ margin:50px auto; border:1px solid #ddd; text-align: center;}.product p.describe{ font-size:16px ; font-weight: 400; color:#845f3f;}.product .product-text{ height:100px; background-color: #f8f8f8; margin-top:20px;/*上外邊距20px*/ padding:15px;/*上下左右內(nèi)邊距15px*/}</style><body> <div class="product"> <img src="images/kettle.png" alt="電水壺" width="195px"> <p class="describe">快速煮水,安心飲用</h3> <div class="product-text"> 添加內(nèi)容邊距,使里面的內(nèi)容與盒子間有上下左右有15px空隙 </div> </div></body>
3
實現(xiàn)效果
<body> <div class="product"> <img src="images/kettle.png" alt="電水壺" width="195px"> <p class="describe">快速煮水,安心飲用</h3> <div class="product-text"> <div class="product-mark"> <img src="images/live.png" alt="直播中" height="20"> <img src="images/odds.png" alt="特惠中" height="20"> <img src="images/30day.png" alt="30天保價" height="20"> <img src="images/server.png" alt="售后免郵" height="20"> </div> </div> </div></body>
.product .product-text .product-mark{ font-size: 0px;/*去掉圖片間的空隙*/ }
(3)、消除空隙后,我們給圖片單獨添加margin外邊距來實現(xiàn)空隙效果。.product .product-text .product-mark img{ margin:0px 2px;/*給圖片設(shè)置左右2像素外邊距*/ }
2、代碼<style type="text/css"> body,p{ margin:0px; } .product{ width:268px; /* height:400px; */ /* background-color: red; */ margin:50px auto; border:1px solid #ddd; text-align: center; } .product p.describe{ font-size:16px ; font-weight: 400; color:#845f3f; } .product .product-text{ height:100px; background-color: #f8f8f8; margin-top:20px;/*上外邊距20px*/ padding:15px;/*上下左右內(nèi)邊距15px*/ } .product .product-text .product-mark{ font-size: 0px; } .product .product-text .product-mark img{ margin:0px 2px; }</style><body> <div class="product"> <img src="images/kettle.png" alt="電水壺" width="195px"> <p class="describe">快速煮水,安心飲用</h3> <div class="product-text"> <div class="product-mark"> <img src="images/live.png" alt="直播中" height="20"> <img src="images/odds.png" alt="特惠中" height="20"> <img src="images/30day.png" alt="30天保價" height="20"> <img src="images/server.png" alt="售后免郵" height="20"> </div> </div> </div></body>
3、實現(xiàn)效果<div class="product"> <img src="images/kettle.png" alt="電水壺" width="195px"> <p class="describe">快速煮水,安心飲用</h3> <div class="product-text"> <div class="product-mark"> <img src="images/live.png" alt="直播中" height="20"> <img src="images/odds.png" alt="特惠中" height="20"> <img src="images/30day.png" alt="30天保價" height="20"> <img src="images/server.png" alt="售后免郵" height="20"> </div> <h3>云米電水壺</h3> </div></div>
(2)、去掉h3自帶的默認margin外邊距body,p,h3{ margin:0px;/*同時去掉body,p,h3的默認外邊距*/ }
(3)、通過以下css來修飾標題.product .product-text h3{ font-size: 20px;/*字體大小*/ font-weight:400 ;/*字體粗細*/ margin-top:10px;/*上外邊距為 10px*/ }
2、代碼<body> <div class="product"> <img src="images/kettle.png" alt="電水壺" width="195px"> <p class="describe">快速煮水,安心飲用</h3> <div class="product-text"> <div class="product-mark"> <img src="images/live.png" alt="直播中" height="20"> <img src="images/odds.png" alt="特惠中" height="20"> <img src="images/30day.png" alt="30天保價" height="20"> <img src="images/server.png" alt="售后免郵" height="20"> </div> <h3>云米電水壺</h3> </div> </div></body>
3、實現(xiàn)效果<body> <div class="product"> <img src="images/kettle.png" alt="電水壺" width="195px"> <p class="describe">快速煮水,安心飲用</h3> <div class="product-text"> <div class="product-mark"> <img src="images/live.png" alt="直播中" height="20"> <img src="images/odds.png" alt="特惠中" height="20"> <img src="images/30day.png" alt="30天保價" height="20"> <img src="images/server.png" alt="售后免郵" height="20"> </div> <h3>云米電水壺</h3> <p>¥59</p> </div> </div></body>
(2)、通過以下css來修飾價格樣式.product .product-text p{ font-size:20px ;/*字體大小*/ color:#a92112;/*字體顏色*/ margin-top:5px;/*上外邊距 5px*/ }
(3)、去掉最開始給 .product-text添中的 高度.product .product-text{ /* height:100px; */ }
2、代碼<style type="text/css"> body,p,h3{ margin:0px; } .product{ width:268px; /* height:400px; */ /* background-color: red; */ margin:50px auto; border:1px solid #ddd; text-align: center; } .product p.describe{ font-size:16px ; font-weight: 400; color:#845f3f; } .product .product-text{ /* height:100px; */ background-color: #f8f8f8; margin-top:20px;/*上外邊距20px*/ padding:15px;/*上下左右內(nèi)邊距15px*/ } .product .product-text .product-mark{ font-size: 0px; } .product .product-text .product-mark img{ margin:0px 2px; } .product .product-text h3{ font-size: 20px; font-weight:400 ; margin-top:10px; } .product .product-text p{ font-size:20px ; color:#a92112; margin-top:5px; }</style> <body> <div class="product"> <img src="images/kettle.png" alt="電水壺" width="195px"> <p class="describe">快速煮水,安心飲用</h3> <div class="product-text"> <div class="product-mark"> <img src="images/live.png" alt="直播中" height="20"> <img src="images/odds.png" alt="特惠中" height="20"> <img src="images/30day.png" alt="30天保價" height="20"> <img src="images/server.png" alt="售后免郵" height="20"> </div> <h3>云米電水壺</h3> <p>¥59</p> </div> </div></body>
<div class="product"> <!--添加超鏈接,實現(xiàn)點擊后跳轉(zhuǎn)到新頁面--> <a href="https://www.icodingedu.com" target="_blank"> <img src="images/kettle.png" alt="電水壺" width="195px"> <p class="describe">快速煮水,安心飲用</h3> <div class="product-text"> <div class="product-mark"> <img src="images/live.png" alt="直播中" height="20"> <img src="images/odds.png" alt="特惠中" height="20"> <img src="images/30day.png" alt="30天保價" height="20"> <img src="images/server.png" alt="售后免郵" height="20"> </div> <h3>云米電水壺</h3> <p>¥59</p> </div> </a> </div>
2、運行效果a{ text-decoration: none;/*去掉下劃線*/}
(2)給h3標簽中的文字加上顏色.product .product-text h3{ color:#000; }
(3)把a標簽轉(zhuǎn)換為塊級元素a{display:block;/*a標簽轉(zhuǎn)換為塊級元素*/}
a標簽?zāi)J的是屬于內(nèi)聯(lián)元素,正常情況下內(nèi)聯(lián)元素中是不能放塊級元素,但a標簽特殊,可以這樣用。但在這里,如果不把標簽轉(zhuǎn)換為塊級元素,會發(fā)生很奇怪的效果。你給a標簽加上 border:1px solid red; 后,如下圖所示:<style type="text/css"> body,p,h3{ margin:0px; }a{ text-decoration: none;/*去掉下劃線*/ } .product{ width:268px; /* height:400px; */ /* background-color: red; */ margin:50px auto; border:1px solid #ddd; text-align: center; }.product a{ display:block;} .product p.describe{ font-size:16px ; font-weight: 400; color:#845f3f; } .product .product-text{ /* height:100px; */ background-color: #f8f8f8; margin-top:20px;/*上外邊距20px*/ padding:15px;/*上下左右內(nèi)邊距15px*/ } .product .product-text .product-mark{ font-size: 0px; } .product .product-text .product-mark img{ margin:0px 2px; } .product .product-text h3{ font-size: 20px; font-weight:400 ; margin-top:10px; color:#000; } .product .product-text p{ font-size:20px ; color:#a92112; margin-top:5px; }</style> <div class="product"> <!--添加超鏈接,實現(xiàn)點擊后跳轉(zhuǎn)到新頁面--> <a href="https://www.icodingedu.com" target="_blank"> <img src="images/kettle.png" alt="電水壺" width="195px"> <p class="describe">快速煮水,安心飲用</h3> <div class="product-text"> <div class="product-mark"> <img src="images/live.png" alt="直播中" height="20"> <img src="images/odds.png" alt="特惠中" height="20"> <img src="images/30day.png" alt="30天保價" height="20"> <img src="images/server.png" alt="售后免郵" height="20"> </div> <h3>云米電水壺</h3> <p>¥59</p> </div> </a> </div>
3、運行效果關(guān)鍵詞:商城,展示,效果,小米,產(chǎn)品,項目
微信公眾號
版權(quán)所有? 億企邦 1997-2025 保留一切法律許可權(quán)利。