Step 1 样式(略)
Step 2 类型选择器
<style>
h1{
text-align:center;
}
</style>
可以通过在 style 元素中指定元素并为其设置属性来向元素添加样式
背景图片,可以是本地的也可以是url(例如.background-image:url(https://cdn.freecodecamp.org/curriculum/css-cafe/beans.jpg) |
|
如果状态相似,可以将它们替换为一个选择器列表
Step 3 css文件
由于会有更多的样式,因此最好将所有样式放在一个单独的文件中并链接到它
在css文件中,不需要加style标签
h1, h2, p {
text-align: center;
}
在源文件中添加一个链接链接到css文件
<link rel="stylesheet" href="styles.css">
同时为了普适性,可以在mata属性中制作屏幕长宽比适中
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
第四步 DIV
div 元素主要用于设计布局目的,这与迄今为止使用的其他内容元素不同。
div元素可以设置id以方便应用后面的id选择器
它处于 body 内
<div id="menu">
<main>
<h1>CAMPER CAFE</h1>
<p>Est. 2020</p>
<section>
<h2>Coffee</h2>
</section>
</main>
</div>
步骤 5 id选择器
id 选择器来选取具有 id 属性的特定元素
将 # 符号直接放在元素的 id 值前面,就形成了 id 选择器。
Step 6 css注释
css内注释格式:/* xxx */
Step 7 类选择器
那类选择器属性就是class=xxx(对比id选择器在html中选择id=xxx
.menu {
width: 80%;
background-color: burlywood;
margin-left: auto;
margin-right: auto;
}
第 8 步文章
article 元素通常包含具有相关信息的多个元素。
<article class="item">
<p class="flavor">French Vanilla</p>
<p class="price">3.00</p>
</article>
<article>
<p>Caramel Macchiato</p>
<p>3.75</p>
</article>
p 元素嵌套在具有 item 属性的 article 元素中。
可以使用名为 item 的类嵌套在元素中任意位置的所有 p 元素的样式,如下所示:
.item p{
display:inline-block;
}
最后一步成品(x)
styles.css
body {
background-image: url(https://cdn.freecodecamp.org/curriculum/css-cafe/beans.jpg);
font-family: sans-serif;
padding: 20px;
}
h1 {
font-size: 40px;
margin-top: 0;
margin-bottom: 15px;
}
h2 {
font-size: 30px;
}
.established {
font-style: italic;
}
h1, h2, p {
text-align: center;
}
.menu {
width: 80%;
background-color: burlywood;
margin-left: auto;
margin-right: auto;
padding: 20px;
max-width: 500px;
}
img {
display: block;
margin-left: auto;
margin-right: auto;
}
hr {
height: 2px;
background-color: brown;
border-color: brown;
}
.bottom-line {
margin-top: 25px;
}
h1, h2 {
font-family: Impact, serif;
}
.item p {
display: inline-block;
margin-top: 5px;
margin-bottom: 5px;
font-size: 18px;
}
.flavor, .dessert {
text-align: left;
width: 75%;
}
.price {
text-align: right;
width: 25%;
}
/* FOOTER */
footer {
font-size: 14px;
}
.address {
margin-bottom: 5px;
}
a {
color: black;
}
a:visited {
color: black;
}
a:hover {
color: brown;
}
a:active {
color: brown;
}
index.html
<h2>Desserts</h2>
<img src="https://cdn.freecodecamp.org/curriculum/css-cafe/pie.jpg" alt="pie icon">
<article class="item">
<p class="dessert">Donut</p><p class="price">1.50</p>
</article>
<article class="item">
<p class="dessert">Cherry Pie</p><p class="price">2.75</p>
</article>
<article class="item">
<p class="dessert">Cheesecake</p><p class="price">3.00</p>
</article>
<article class="item">
<p class="dessert">Cinnamon Roll</p><p class="price">2.50</p>
</article>
</section>
</main>
<hr class="bottom-line">
<footer>
<p>
<a href="https://www.freecodecamp.org" target="_blank">Visit our website</a>
</p>
<p class="address">123 Free Code Camp Drive</p>
</footer>
</div>
</body>
</html>

優(yōu)網(wǎng)科技秉承"專業(yè)團(tuán)隊(duì)、品質(zhì)服務(wù)" 的經(jīng)營理念,誠信務(wù)實(shí)的服務(wù)了近萬家客戶,成為眾多世界500強(qiáng)、集團(tuán)和上市公司的長期合作伙伴!
優(yōu)網(wǎng)科技成立于2001年,擅長網(wǎng)站建設(shè)、網(wǎng)站與各類業(yè)務(wù)系統(tǒng)深度整合,致力于提供完善的企業(yè)互聯(lián)網(wǎng)解決方案。優(yōu)網(wǎng)科技提供PC端網(wǎng)站建設(shè)(品牌展示型、官方門戶型、營銷商務(wù)型、電子商務(wù)型、信息門戶型、微信小程序定制開發(fā)、移動(dòng)端應(yīng)用(手機(jī)站、APP開發(fā))、微信定制開發(fā)(微信官網(wǎng)、微信商城、企業(yè)微信)等一系列互聯(lián)網(wǎng)應(yīng)用服務(wù)。