Udemy The Web Developer Bootcamp - CSS

Intro to CSS

  1. 定义
    cascading style sheets
    skin of your website
  2. general Rule
selector {
	property: value;
	antherProperty: value;
}

eg

/*make all h1's purple and 56px font*/
h1{
	color: purple;
	font-size:56px;
}

/*give all img's a 3px red border*/
img {
	border-color: red;
	border-width: 3px;
}

  1. 单独给某一个要素改style (不推荐)
    不推荐原因:1. 麻烦,如果要改多个地方时,需要逐一修改
    2 原则是把CSS代码和HTML分开,want css self-retained, in its own file
<li style="color: purple;">playing guitar</li>
  1. Style tag (nested in html, still NOT GOOD)
<html>
<head>
	<title>About Rusty</title>
	<style type="text/css">
		li{
			color:red;  /*选择了所有的li,全部改成red*/
		}
		h1 {
			color: purple;
		}
	</style>

</head>
</html>
  1. Link Tag

    单独写一个.css结尾的CSS文件,然后在HTML里面link到该文件

<link rel="stylesheet" type="text/css" href="url(place to find the css file eg: app.css">

CSS Colors

  1. Built In Color
    查看代码对应的颜色: https://colours.neilorangepeel.com/

  2. Hexadecimal - Base 16, 16进制
    格式: # + 6位代码(from 0 - F)

    前两位:how much RED in color
    中两位: GREEN
    后两位: BLUE

    两种方法选择color 代码:
    A colorpicker – 直接复制代码 eg. #0011EF

  3. RGB – 红绿蓝 (0 - 255)
    syntax:

h1{
	color: rgb(0,255,0);  /*注意要有分号结尾*/
}
  1. RGBA
    4个channel 前三个范围和RGB一样,第四个范围(0.0 - 1.0),表示透明度
hi{
	color: rgba(0,200,100,3);
}

Color and Background

  1. 背景颜色 or 图片
h4{
	background: rgb(255,100,23);
}

body{
   brackground: pink; /* 整个网页背景变为粉色*/
}

body{
	background: url(http:// ..........jpg);    /*以图片作为背景*/
	background-repeat: no-repeat; /*图片过小不会拼接,但是会有大量空白*/
	background-size:cover; /*拉伸图片覆盖整个网页,但是分辨率不高时会模糊*/

	
}

  1. 边框
h1{
	border-color: purple;
	border-width: 5px;
	border-style: solid;
	/*只有三个都设置了才会显示边框*/

	border: 5px solid purple;  
	/*两种syntax的功效一样*/
}

Elements, ID and Class

=======HTML=========
<div>
	<p class="highlight">You say yes</p>
	/*把要统一做变化的地方归为一个class*/
</div>

<div>
	<p class="highlight">You say goodbye</p>
	<p id="special">I say hello</p>
	/*把这句话命名一个ID,在CSS里可以单独对这个ID做style,在一个HTML里这个ID只能出现一次*/
</div>

<ul>
	<li class="completed">
		<input type="checkbox" checked>
		/*checked表示方框已打钩*/
		Walk Rusty
	</li>
</ul>

=======css=========
div{
	background: purple;
}
p{
	color: yellow;
}
#special{
	background: yellow;
}

.highlight{
	text-decoration: line-through;
}

inspect element

  1. 谷歌浏览器打开HTML后,右键点inspect element,可以同时看代码和效果,用来debug, 右下角可以看CSS style

More Advanced Selectors

  1. ※ select everything
*{
border: 1px solid lightgrey;
}
  1. Descendant Selector
li a{
}
选择HTML里面每个在list里面的a

li .hello{
}
选择在在li里标记为class hello的
  1. Adjacent Selector
h4 + ul{
	border: 4px solid red;
}
选择h4后面所有跟了ul的
  1. Attribute Selector
a[href="http://www.google.com"]{
	background: blue;
}

input[type="checkbox"]{
	background: blue;
}
  1. Nth of type
ul:nth-of-type(3){
	background: purple;
}
选择HTML里第3个UL

nth-of-type(even)
选择每个偶数

Inherited 和 Specificity

  1. Inherited 下级内容会自动继承上级内容的style
  2. Specificity 多个Style指向同一个内容
  3. more about specificity https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity
  4. Specificity 优先级的可视化网站 https://specificity.keegan.st/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值