批改状态:合格
老师批语:css 中 @import 尽量不要使用!因为@import引用的CSS会等到页面全部被下载完再被加载,用户体验不好!
示例
<body><!-- 自定义属性必须以data-开始 --><p class="phpcn-intro" data-intro="php.cn">php中文网是php与前端开发者的乐园</p><h3 class="phpcn-intro">Hello PHP.CN</h3><!-- 任何一个html元素都有二种属性: 内置属性, 自定义属性 --><label for="login">用户名:</label><input type="text" name="username" data-index="自定义属性" id="login" /><script>const intro = document.getElementsByClassName("phpcn-intro").item(0);intro.style.backgroundColor = "red";</script></body>
:first-of-type,
:last-of-type,
:nth-of-type(),
:nth-last-of-type(),
:only-of-type
:first-child,
:last-child,
:nth-child(),
:nth-last-child(),
:only-child()
在一个css文件中直接用@import来进行嵌套引用。这样在html中就只要link这个css一个就够了,其他css会直接被引用进来。
@import url("font/iconfont.css");/* @import必须写在css文档的前面 *//* 头部样式的模块 */@import url(header.css);@import url(footer.css);.icon-gouwuchekong:before {font-family: "iconfont";content: "\e602";font-size: 5rem;color: green;}
最后这块是通过伪类元素添加,同时改变iconfont的属性。“\e602”是对应的iconfont的位置或id。
<label for="email">邮箱:</label><inputid="email"class="my-email"type="email"name="email"value="admin@php.cn"placeholder="demo@email.com"autofocusrequired/>
之所以因为这样,是为了长期快速编程做准备。例如如果格式等固定了。在js中就可以非常方便地进行调用和替换等。
<script>const email = document.querySelector("input");const attrs = email.attributes;console.log(attrs);console.log(attrs[0]);console.log(attrs[1]);</script>
.box img {width: 100%;}
<img src="" alt="">
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号