学习尚硅谷前端——餐厅练习

3 篇文章 0 订阅
1 篇文章 2 订阅
小白一个。此笔记来自于跟尚硅谷老师学习,此篇是对CSS选择器的总结以及视频中的P37的餐厅练习自己做的答案,自己所写,用于自我复习。若对码友有用可参考。

P37尚硅谷_餐厅练习: https://flukeout.github.io/

目录

css选择器:

1.Select the plates

2.Select the bento boxes

3.Select the fancy plate

4.Select the apple on the plate

5.Select the pickle on the fancy plate

6.Select the small apples

7.Select the small oranges

8.Select the small oranges in the bentos

9.Select all the plates and bentos

10.Select all the things!

11.Select everything on a plate

12.Select every apple that's next to a plate

13.Select the pickles beside the bento

14.Select the apple directly on a plate

16.Select the apple and the pickle on the plates

17.Select the small apple and the pickle

18.Select the 3rd plate

19.Select the 1st bento

20.Select first apple

21.Select all even plates

22.Select every 2nd plate, starting from the 3rd

23.Select the apple on the middle plate

24.Select the last apple and orange

25.Select the empty bentos

26.Select the big apples

27.Select the items for someone

28.Select the plates for someone

29.Select Vitaly's meals

30.Select the items for names that start with 'Sa'

31.Select the items for names that end with 'ato'

32.Select the meals for names that contain 'obb'


css选择器:

选择器,通过选择器可以选中页面中的指定元素,以便使用声明块来为指定元素设置样式。比如p的作用就是选中页面中所有的p元素。

一、常用选择器(元素选择器,id选择器,类选择器,class选择器,通配选择器)

1.元素选择器(Type selector)

作用:根据标签名来选中指定的元素

语法:标签名{}

比如:p{}     h1{}

2.id选择器(ID selector)

作用:根据元素的Id属性值选中一个元素

语法:#id属性值{}   比如:#box{}   

3.类选择器(Class selector)

作用:根据元素的class属性值选中一组元素

语法:.class属性值{}

注意:class属性可设置多个属性值,可属于不同的类,如class="blue abc"

4.通配选择器(Universal selector)

作用:选中页面中的所有元素

语法:*{}

二、复合选择器(交集选择器,并集选择器)

1.交集选择器

作用:选中同时符合多个条件的元素

语法:选择器1选择器2选择器3选择器n{}

example:  div.red{} 表示选择标签为div且class为red的元素

注意:交集选择器中如果有元素选择器,必须使用元素选择器开头。

2.并集选择器或选择器分组(Selector list)

作用:同时选择多个选择器对应的元素

语法:选择器1,选择器2,选择器3,选择器n{}

三、关系选择器(子元素选择器,后代元素选择器,选择下一个兄弟,选择下边所有的兄弟)

1.子元素选择器(Child combinator)

作用:选中指定父元素的指定子元素

语法:父元素 > 子元素

2.后代元素选择器(Descendant combinator)

作用:选择指定元素内的指定后代元素

语法:祖先  后代(中间为空格)

3.选择下一个兄弟(Adjacent sibling combinator)

语法:前一个 + 后一个

注意:只能选与前一个紧挨着的下一个元素

4.选择下边所有的兄弟(General sibling combinator)

语法:兄~弟

注意:其选择的是兄下边所有的弟,不能选择其上的元素

四、属性选择器(Attribute selector)

[属性名]  选择含有指定属性的元素;

[属性名=属性值]  选择含有指定属性和属性值的元素;

[属性名^=属性值]  选择属性值以指定值开头的元素;

[属性名$=属性值]  选择属性值以指定值结尾的元素;

[属性名*=属性值]  选择属性值中含有某值的元素。

五、伪类选择器(Pseudo classes)

        伪类(不存在的类,特殊的类),伪类用来描述一个元素的特殊状态,比如:第一个子元素、被点击的元素、鼠标移入的元素等。

        伪类一般情况下使用:开头。

:first-child{} 兄弟元素中第一个元素  比如:ul > li:first-child{}表示ul子元素li中的第一个元素

:last-child{} 兄弟元素中最后一个元素

:nth-child(){} 选中兄弟元素中第几个元素(括号中写几就选中第几个)

        特殊值:

                n 表示选择所有

                2n 或even 表示选中偶数位的元素

                2n+1或odd 表示选中奇数位的元素

注意:以上这些伪类都是根据所有的兄弟元素进行的排序

:first-of-type  

:last-of-type

:nth-of-type()

        这几个伪类的功能与上述的类似,不同点是他们是在同类型的元素中进行排序。

:not(){}  否定伪类:将符合条件的元素从选择器中去除

六、伪元素选择器(Pseudo elements

        伪元素,表示页面中一些特殊的并不真实的存在的元素(特殊的位置)

        伪元素使用::开头

::first-letter  表示其第一个字母

::first-line  表示其第一行

::selection  表示在页面中鼠标选中的内容

::before  表示元素的开始

::after  表示元素的最后

注意:使用::before和::after添加的内容是通过CSS添加的,在网页中选中时,无法选中其添加的内容。

七、伪超链接

:link 用来表示没访问过的链接(正常的链接)  a;link{}    <a></a>为超链接

        注意:在link里修改字体大小时,所有的链接都会改变,因为它也是针对正常的链接。

:visited 用来表示访问过的链接

       注意:由于隐私的原因,所以visited这个伪类只能修改链接的颜色,字体大小无法修改。

:hover 用来表示鼠标移入的状态

:active 用来表示鼠标点击 

1.Select the plates

<div class="'table">
	<plate />
	<plate />
</div>

输入:plate

(元素选择器)

2.Select the bento boxes

<div class="'table">
	<bento />
	<plate />
	<bento />
</div>

输入:bento   (元素选择器)

3.Select the fancy plate

<div class="'table">
    <plate id='fancy'/>
	<plate />
	<bento />
</div>

输入:#fancy

        (id选择器,语法:#id属性值,本题也可输入plate#fancy,但没必要,因为使用id一般是唯一的)

4.Select the apple on the plate

<div class="'table">
	<bento />
	<plate>
		<apple />
	</plate>
	<apple />
</div>

输入:plate > apple 或plate apple

        (子元素选择器或后代选择器。the apple on the plate说明要选择plate标签下的子标签apple,故使用子元素选择器,语法:父元素 > 子元素)

5.Select the pickle on the fancy plate

<div class="'table">
	<bento>
		<orange />
	</bento>
	<plate id='fancy'/>
		<pickle />
	</plate>
	<plate>
		<pickle />
	</plate>  
</div>

输入:#fancy > pickle 或#fancy pickle

        (子元素选择器或后代选择器。the pickle on the fancy plate说明要选择id为fancy的plate标签下的子标签pickle,故使用子元素选择器,语法:父元素 > 子元素

6.Select the small apples

<div class="'table">
	<apple />
	<apple class="small" />
	<plate>
		<apple class="small" />
	</plate> 
	<plate />
</div>

输入:.small

        (使用类选择器,语法:.class属性值)

7.Select the small oranges

<div class="table">
	<apple />
	<apple class="small">
	<bento>
		<orange class="sma1l"/>
    </bento>
	<plate>
		<orange />
	</plate>
	<plate>
		<orange class="sma1l"/>
	</plate>
</div>

输入:orange.small     (交集选择器)

8.Select the small oranges in the bentos

<div class="table">
	<bento>
		<orange />
	</bento>
	<orange class="small" />
	<bento>
		<orange class="small" />
	</bento>
	<bento>
		<apple class="small" />
	</bento>
	<bento>
		<orange class="small" />
	</bento>
</div>

输入:bento > orange.small  或者 bento orange.small (子选择器加交集选择器)

9.Select all the plates and bentos

<div class="table">
	<pickle class="sma1l"/>
	<pickle />
	<plate>
		<pickle />
	</plate>
	<bento>
		<pickle />
	</bento>
	<plate>
		<pickle />
	</plate>
	<pickle />
	<pickle class="small" />
</div>

输入:plate,bento          (并集选择器,语法:选择器1,选择器2,选择器3

10.Select all the things!

<div class="table">
	<apple />
	<plate>
		<orange class=small”/>
	</plate>
	<bento />
	<bento>
		<orange />
	</bento>
	<plate id="fancy" /> 
</div>

输入:*          (通配选择器,选择页面中所有的元素,语法:*)

11.Select everything on a plate

<div class="table">
	<plate id="fancy">
		<orange class="small"/>
	</plate>
	<plate>
		<pickle />
	</plate>
	<apple class="sma11" />
	<plate>
		<apple />
	</plate>
</div>

输入:plate > 或 plate > * 或 plate *  (子选择器)

12.Select every apple that's next to a plate

<div class="tab1e">
	<bento>
		<apple class="sma1l"/>
	</bento>
	<plate />
	<apple class="sma1l"/>
	<plate />
	<apple />
	<apple class="sma11" />
	<apple class="small" />
</div>

输入:plate+apple       (选择下一个兄弟)

13.Select the pickles beside the bento

<div class="table">
	<pickle />
	<bento>
		<orange class="small" />
	</bento>
	<pickle class="small" />
	<pickle />
	<plate>
		<pickle />
	</plate>
	<plate>
		<pickle class="small" />
	</plate>
</div>
		

输入:bento~pickle (选择后面所有的兄弟)

14.Select the apple directly on a plate

<div class="table">
	<plate>
		<bento>
			<apple />
		</bento>
	</p1ate>
	<plate>
		<apple />
	</plate>
	<plate />
	<apple />
	<apple class="small" />
</div>

输入:plate>apple (子元素选择器,不能是祖先选择器,因为其是直接在盘子里的苹果)

15.Select the top orange

<div class="table">
	<bento />
	<plate />
	<plate>
		<orange />
		<orange />
		<orange />
	</plate>
	<pickle class="sma1l" />
</div>	

输入:plate>orange:first-child  (伪类选择器:first-child 选择兄弟元素中的第一个元素)

16.Select the apple and the pickle on the plates

<div class="table">
	<plate>
		<apple />
	</p1ate>
	<plate>
		<pickle />
	</plate>
	<bento>
		<pickle />
	</bento>
	<plate>
		<orange class="small" />
		<orange />
	</plate>
	<pickle class="sma1l" />
</div>

输入:plate > :only-child

17.Select the small apple and the pickle

<div class="table">
	<plate id="fancy">
	<app1e class="sma11" />
</plate>
<plate />
<plate>
	<orange class="sma1l" />
	<orange />
</plate>
<pickle class="smal1" />
</div>

输入:#fancy> ,pickle  或者apple.small,pickle

18.Select the 3rd plate

输入:plate:nth-child(3)

19.Select the 1st bento

输入:bento:first-of-type

20.Select first apple

输入:apple:first-of-type

21.Select all even plates

输入:plate:nth-child(even)

22.Select every 2nd plate, starting from the 3rd

输出:plate:nth-of-type(2n+3)

:nth-of-type(An+B)

The nth-of-type formula selects every nth element, starting the count at a specific instance of that element.

example:span:nth-of-type(6n+2) selects every 6th instance of a span, starting from (and including) the second instance.)

23.Select the apple on the middle plate

<div class="table">
	<plate id="fancy">
		<apple class="sma11" />
		<apple />
	</plate>
	<plate>
		<apple class="small" />
	</plate>
	<plate>
		<pickle />
	</plate>
</div>

输入:plate apple:only-of-type 或: nth-child(2)>apple

(:only-of-type

Selects the only element of its type within another element.

example: p span:only-of-type selects a span within any p if it is the only span in there.)

24.Select the last apple and orange

输入:orange:last-of-type,apple:last-of-type

25.Select the empty bentos

输入:bento:empty

:empty

Selects elements that don't have any other elements inside of them.

example: div:empty selects all empty div elements.)

26.Select the big apples

<div class="table">
	<plate id="fancy">
		<apple class="sma1l" />
	</plate>
	<p1ate>
		<apple />
	</plate>
	<apple />
	<plate>
		<orange class="small"/>
	</plate>
	<pickle class="small" />
</div>

输入:apple:not(.small)

27.Select the items for someone

输入:[for]

28.Select the plates for someone

输入:plate[for] 或者 [for=Sarah],[for=Luke]

29.Select Vitaly's meals

输入:[for=Vitaly]

30.Select the items for names that start with 'Sa'

输入:[for^=Sa]

31.Select the items for names that end with 'ato'

输入:[for$=ato]

32.Select the meals for names that contain 'obb'

输入:[for*=obb]

  • 3
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
HTML5/CSS 餐厅选择器 第一关 plate plate元素 第二关 bento bento元素 第三关 #fancy id为fancy的元素 第四关 plate apple plate祖先元素下的apple后代元素 第五关 #fancy pickle id为#fancy的祖先元素下的pickle后代元素 第六关 .small 组为small的元素 第七关 orange.small 组为small的orange元素 第八关 bento>orange.small bento父元素下的组为small的orange子元素 第九关 plate,bento,div plate,bento兄弟元素在div元素中 第十关 * *代表所有元素 第十一关 plate>* plate父元素的所有子元素 第十二关 plate + apple 兄弟元素选择器,plate元素的后一个元素 第十三关 bento~pickle 兄弟元素选择器,bento元素后的多个pickle元素 第十四关 plate>apple plate父元素下的apple子元素 第十五关 plate orange:first-child 子元素选择器,plate元素下的第一个orange元素 第十六关 plate :only-child 所有plate元素下的元素 第十七关 #fancy :last-child,pickle:last-child id为fancy的元素的最后一个和pickle元素的最后一个 第十八关 div plate:nth-child(3) div元素中的第三个plate元素 第十九关 div bento :nth-last-child(4) div元素中倒数第四个bento元素 第二十关 apple:first-of-type 第一个apple元素 第二十一关 plate:nth-of-type(even) 所有偶数个的plate元素 第二十二关 plate:only-of-type(6n+3),plate:only-of-type(6n+5) plate元素下的第3个和第5个元素 第二十三关 plate apple.small:only-of-type plate元素下满足apple.small元素的唯一一个元素 第二十四关 orange.small:last-of-type,apple.small:last-of-type 是orange.samll和apple.small元素的最后一个元素 第二十五关 bento:empty bento元素里没有包括额外元素 第二十六关 apple:not(.small) apple里没有组是.small的元素
### 回答1: 尚硅谷是一家提供IT技术培训的机构,其中包括Web前端HTML5和CSS3的课程。HTML5是一种用于创建网页内容的标记语言,而CSS3则是一种用于网页样式设计的语言。学习这两门技术可以帮助人们更好地设计和开发网页,提高用户体验和网站的可访问性。 ### 回答2: 尚硅谷Web前端HTML5教程是一门专门针对Web前端开发的课程。HTML5是HTML语言的最新版本,主要用于Web前端开发。该课程从基础知识讲起,依次介绍HTML5的基本语法、语义标签、音视频、Canvas绘图等方面的知识点。通过实际案例,让学员掌握HTML5在前端开发中的应用。 首先,该课程的重点在于HTML5新特性的讲解。HTML5拥有许多新的语义标签,如header、article、section、footer等,这些标签能够更好地描述网站的结构和信息。此外,HTML5还提供了新的多媒体标签,如video、audio等,使得网页能够更加丰富和生动。HTML5还可扩展性强,可以更好地支持其他Web技术。对于Web前端开发者来说,掌握HTML5是非常重要的。该课程深入浅出地讲解了HTML5的语言特性,帮助学员更好地掌握。 其次,该课程以实战案例为主导。课程会使用案例练习来帮助学员更好地理解HTML5的知识点,并将其灵活应用到实践中。案例覆盖面广,包括音视频播放、图片列表展示等多种场景。学员在实践中发现问题、解决问题,能够促进知识的吸收和掌握。学员还可以在课程中学习如何使用Canvas绘图,从而达到更高的前端开发能力。 最后,该课程的授课老师资深且经验丰富。课程老师是尚硅谷资深前端开发工程师,具有多年的实际开发经验。老师会通过自己的经验和教学方法,帮助学员更好地理解和掌握HTML5的知识。学员还可以在课程中与老师进行互动,及时解决问题,进一步提升自己的学习效果。 综上所述,尚硅谷Web前端HTML5课程是一门非常优秀的课程。该课程以HTML5新特性为重点、实战案例为主导、讲师资深有经验为特点,赢得了众多学员的好评和认可。学习该课程,有助于Web前端开发者掌握HTML5,提高自己的开发技能,为自己的职业发展打下坚实的基础。 ### 回答3: 尚硅谷是一家专业的IT培训机构,旨在提供高质量的IT教育解决方案,帮助学生提升技能,实现职业上升。在尚硅谷学习Web前端HTML5,首先需要了解什么是Web前端和HTML5。 Web前端是指在Web网站或应用程序的前端进行开发和设计的过程,设计和实现网站页面的模板和设计要素,实现互动式界面的交互性和动态效果,增强用户体验。HTML5是HyperText Markup Language 5的缩写,是一种标准网页设计语言,可以用来定义和创建网页的内容和结构,是Web前端技术的基础。也是现代Web页面的标准,包含了一些新的功能,比如视频、音频、图像、动画和图形等。 在尚硅谷学习Web前端HTML5,将会得到严谨的课程体系和内容,从基础知识到实践操作全面覆盖。学生将深入了解HTML5、CSS3、Javascript、jQuery等技术,掌握Web前端开发的核心思想和流程。学生们将能够理解和应用HTML5在Web前端开发中的应用,创建和设计网站内容并实现常见的互动效果。同时,学生们还将学习最佳实践、代码规范和优化技巧,全面提升Web前端开发技能。 在尚硅谷学习Web前端HTML5的优势,除了课程内容的全面性和严谨性外,还有课程形式的多样化和灵活性,包括线上直播课程、视频课程、互动问答和实践课程等,可以根据学生的情况进行选择和学习。此外,尚硅谷还提供了完善的支持体系,包括作业批改、实战项目等,帮助学生增加实践经验和应用能力,为今后就业和职业发展奠定了坚实的基础。 总之,尚硅谷Web前端HTML5是一个非常有价值的课程,可以帮助学生深入了解Web前端开发的技术和流程,提升技能和职业竞争力。在现代数字化时代,Web前端开发和设计人才需求越来越多,学习Web前端HTML5也是一条不错的职业发展之路。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值