1. 程式人生 > >less和reset.css的引用及首頁活動、商品推薦模塊的建立及flex布局

less和reset.css的引用及首頁活動、商品推薦模塊的建立及flex布局

add field base put ide 17. red back text

?記在前面

人生最大的希望在於:自己值得自己等待

先打開運行項目:

技術分享圖片

技術分享圖片

一、less和reset.css的使用

1.less的引用:

安裝less和less-loader(之前補充過了)傳送地址:https://www.cnblogs.com/crystral/p/9117161.html

2.reset.css的引用

①去這個網站(https://cssreset.com/)下載一個reset.css文件,然後copy到src目錄下:

(這個我沒有下載下來,點擊沒反應,所以去老師那裏copy了一份,代碼我放下面)

技術分享圖片


reset.css

/**
* Eric Meyer‘s Reset CSS v2.0 (http://meyerweb.com/eric/tools/css/reset/)
* http://cssreset.com
*/
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header,
menu, nav, output, ruby, section, summary,
time, mark, audio, video, input {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font-weight: normal;
vertical-align: baseline;
}

/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, menu, nav, section {
display: block;
}

body {
line-height: 1;
}

blockquote, q {
quotes: none;
}

blockquote:before, blockquote:after,
q:before, q:after {
content: none;
}

table {
border-collapse: collapse;
border-spacing: 0;
}

/* custom */
a {
color: #7e8c8d;
text-decoration: none;
-webkit-backface-visibility: hidden;
}

li {
list-style: none;
}

::-webkit-scrollbar {
width: 5px;
height: 5px;
}

::-webkit-scrollbar-track-piece {
background-color: rgba(0, 0, 0, 0.2);
-webkit-border-radius: 6px;
}

::-webkit-scrollbar-thumb:vertical {
height: 5px;
background-color: rgba(125, 125, 125, 0.7);
-webkit-border-radius: 6px;
}

::-webkit-scrollbar-thumb:horizontal {
width: 5px;
background-color: rgba(125, 125, 125, 0.7);
-webkit-border-radius: 6px;
}

html, body {
width: 100%;
}

body {
-webkit-text-size-adjust: none;
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}

②在App.vue中引入:


技術分享圖片

③最後,可以去瀏覽器中看看是不是引用成功了,比如h3塊級元素的margin值都為0了


技術分享圖片

二、新建活動、商品推薦組件

1.進入components文件下,新建活動(active)、商品推薦(recommend)的組件


技術分享圖片

技術分享圖片

2.activity.vue的構建

①template


技術分享圖片

技術分享圖片


②style

<style lang="less" scoped>
.activity {
background: #eee;
.title {
width: 100%;
height: 50px;
line-height: 50px;
text-align: center;
color: gray;
border-bottom: 1px solid #000;
background: #fff;
}
.content {
.content_item {
background: #fff;
margin-bottom: 10px;
img {
width: 100%;
height: 150px;
}
}
.name {
font-size: 15px;
color: #000;
margin-bottom: 5px;
}
.desc {
font-size: 13px;
color: #000;
}
}
}
</style>


3.recommend.vue的構建

跟activity.vue的結構大同小異,主要是用了一個flex的布局

在這裏拋送個阮大神的flex布局的鏈接:http://www.ruanyifeng.com/blog/2015/07/flex-grammar.html

①template

技術分享圖片

技術分享圖片


②style

.recommend {
background: #eee;
.title {
width: 100%;
height: 50px;
line-height: 50px;
text-align: center;
color: gray;
border-bottom: 1px solid #000;
background: #fff;
}
.content {
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: space-between;
.content_item {
background: #fff;
margin-bottom: 5px;
width: 200px;
img {
width: 100%;
height: 200px;
}
.name {
padding: 0 5px;
font-size: 15px;
}
.desc {
padding: 0 5px;
overflow: hidden;
font-size: 13px;
.price {
color: red;
}
.price_pre {
color: #8e8e8e;
text-decoration: line-through;
}
}
}
}
}


做完以上之後,刷新瀏覽器是沒有反應的,所以看了一下,少了上一節講的組件的引入

技術分享圖片


三、看效果
這就是我們首頁的活動推薦和商品推薦模塊

技術分享圖片

技術分享圖片

以上,完成~~~

less和reset.css的引用及首頁活動、商品推薦模塊的建立及flex布局