博主信息
博文 25
粉丝 0
评论 0
访问量 16551
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
字体图标和媒体查询实例
PHui
原创
942人浏览过

1. 字体运用

html

  1. <!-- Unicode -->
  2. <link rel="stylesheet" href="css/font-icon.css" />
  3. <!-- class -->
  4. <link
  5. rel="stylesheet" href="//at.alicdn.com/t/c/font_3730474_ld9vzyq9bp.css"
  6. <!-- 1. unicode -->
  7. <div class="iconfont unicode">
  8. <span>&#xe640;</span>
  9. </div>
  10. <!-- 2. class -->
  11. <div class="iconfont class">
  12. <span class="icon-icon-test"></span>
  13. </div>

css

  1. /* unicode安装自定义图标字体 */
  2. @font-face {
  3. font-family: 'iconfont'; /* Project id 3730474 */
  4. src: url('//at.alicdn.com/t/c/font_3730474_ld9vzyq9bp.woff2?t=1666775664196') format('woff2'),
  5. url('//at.alicdn.com/t/c/font_3730474_ld9vzyq9bp.woff?t=1666775664196') format('woff'),
  6. url('//at.alicdn.com/t/c/font_3730474_ld9vzyq9bp.ttf?t=1666775664196') format('truetype');
  7. }

2. 媒体查询

css

  1. /* 当视口宽度小于1050px时,导航标签向右不显示 */
  2. @media (max-width: 1050px) {
  3. .Head .HeadNav {
  4. display: none;
  5. }
  6. .Head .HeadRight {
  7. display: none;
  8. }

3. 实例运用

html

  1. <div class="Head">
  2. <div class="logo">
  3. <img
  4. src="https://mbdp01.bdstatic.com/static/landing-pc/img/logo_top.79fdb8c2.png"
  5. />
  6. </div>
  7. <!-- 导航 -->
  8. <div class="HeadNav">
  9. <nav>
  10. <span class="theam">HTMLl</span>
  11. <span class="theam">CSS</span>
  12. <span class="theam">JavaScript</span>
  13. </nav>
  14. </div>
  15. <div class="HeadRight">
  16. <!-- 搜索 -->
  17. <div class="search">
  18. <input
  19. type="text"
  20. value="输入关键词搜索"
  21. name="text1"
  22. class="text1"
  23. id="key_words"
  24. onblur="if(this.value=='') this.value='输入关键词搜索';"
  25. onfocus="if(this.value=='输入关键词搜索') this.value='';"
  26. />
  27. <button>
  28. <div class="iconfont">
  29. <span class="icon-icon-test"></span>
  30. </div>
  31. </button>
  32. </div>
  33. <div class="iconfont class">
  34. <span class="icon-icon-test1"></span>
  35. </div>
  36. <div class="iconfont class">
  37. <span class="icon-icon-test2"></span>
  38. </div>
  39. </div>
  40. </div>
  41. <!-- 客服 -->
  42. <div class="Request">
  43. <div class="iconfont class">
  44. <span class="icon-icon-test3"></span>
  45. </div>
  46. </div>

css

  1. html {
  2. font-size: 10px;
  3. height: 200rem;
  4. }
  5. .Head {
  6. background-color: lightblue;
  7. width: 100vw;
  8. /* 头部固定视口顶部 */
  9. position: fixed;
  10. top: 0;
  11. left: 0;
  12. }
  13. .Head .logo {
  14. display: inline-block;
  15. width: 20rem;
  16. margin-left: 1rem;
  17. }
  18. .Head .logo img {
  19. width: 12rem;
  20. }
  21. .Head .HeadNav {
  22. width: 45rem;
  23. display: inline-block;
  24. }
  25. .Head .HeadNav .theam {
  26. margin: 2rem;
  27. font-size: 3.5rem;
  28. font-family: "Franklin Gothic Medium", "Arial Narrow", Arial, sans-serif;
  29. }
  30. /* 划过时显示颜色和小手 */
  31. .Head .HeadNav .theam:hover {
  32. background-color: coral;
  33. cursor: pointer;
  34. }
  35. .Head .HeadRight {
  36. float: right;
  37. display: inline-block;
  38. width: 38rem;
  39. }
  40. .Head .search {
  41. margin: 1.1rem;
  42. display: inline-block;
  43. }
  44. .Head .search button:hover {
  45. cursor: pointer;
  46. }
  47. .Head .iconfont.class {
  48. display: inline-block;
  49. margin: 1rem;
  50. font-size: x-large;
  51. }
  52. .Head .iconfont.class:hover {
  53. cursor: pointer;
  54. }
  55. /* 客服按钮固定视口右下角 */
  56. .Request {
  57. position: fixed;
  58. right: 0;
  59. bottom: 35%;
  60. }
  61. .Request .iconfont.class {
  62. font-size: xxx-large;
  63. }
  64. .Request .iconfont.class:hover {
  65. cursor: pointer;
  66. }
  67. /* 当视口宽度小于1050px时,导航标签向右不显示 */
  68. @media (max-width: 1050px) {
  69. .Head .HeadNav {
  70. display: none;
  71. }
  72. .Head .HeadRight {
  73. display: none;
  74. }
  75. }

批改老师:PHPzPHPz

批改状态:合格

老师批语:完成的没什么问题,继续加油
本博文版权归博主所有,转载请注明地址!如有侵权、违法,请联系admin@php.cn举报处理!
全部评论 文明上网理性发言,请遵守新闻评论服务协议
0条评论
作者最新博文
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号

  • 登录PHP中文网,和优秀的人一起学习!
    全站2000+教程免费学