HTML、CSS 和响应性参考表 HTML、CSS 和响应性参考表

2025-06-07

HTML、CSS 和响应性参考表

HTML、CSS 和响应性参考表

HTML、CSS 和响应性参考表

这是我收集的所有 HTML 和 CSS 参考资料,可以在研究它们作为路径时用作参考,这里还提供使用响应性的解释。

你可以在我的Github上获取 markdown


目录

HTML、CSS 和响应性参考表


HTML

基本 HTML

有用的元素


CSS

基本 CSS

定位

动画

图像与转换

样式表单

有用的属性


响应能力

  • 媒体查询

  • 元标记 - <meta name='viewport' content="width=device-width, initial-scale=1.0">

屏幕宽度使用情况

  • 桌面优先:使用最大宽度;(从高到低)
  • 移动优先:使用最小宽度(从低到高)

应用媒体查询的顺序

  1. 基础+排版
  2. 总体布局
  3. 网格
  4. 页面布局
  5. 成分

处理图像

  • 密度切换 -高分辨率(2px 对应 1px)和低分辨率(1px 对应 1px)

    • <img srcset="img1x.png 1x, img2x.png 2x" alt="Image">
  • 艺术指导 -不同屏幕使用不同图像

  <picture>
      <!-- when lower than 600px -->
    <source srcset="imgsmall1x.png 1x, imgsmall2x.png 2x" media="(max-width: 37.5em)"> 
      <!-- using density switching with art directions -->
      <img srcset="img1x.png 1x, img2x.png 2x" alt="img">
  </picture>
Enter fullscreen mode Exit fullscreen mode
  • 分辨率切换 -大屏幕和小屏幕
  <!-- in srcset , the images are specified with their original width-->
  <img srcset="img1.png 300w, img1-large.png 1000w" 
       sizes="(max-width: 900px) 20vw, (max-width: 600px) 30vw, 300px">
  <!-- in sizes , the screen size is speicified with the image width to be used, last one being the default size -->
Enter fullscreen mode Exit fullscreen mode
  • 在 CSS 中处理图像 -媒体查询与屏幕分辨率和宽度相结合
  // for resolution greater than 1px and 600px width or webkit is for safari browser
  @media (min-resolution: 192pi) and (min-width:600px) ,
      (-webkit-min-device-pixel-ratio: 2) and (min-width:600px){
      // image you want to set
      }
Enter fullscreen mode Exit fullscreen mode

功能查询

  • 浏览器
  @supports (-webkit-backdrop-filter: blur(10px)) or (backdrop-filter: blur(10px)){
    -webkit-backdrop-filter: blur(10px);
      backdrop-filter: blur(10px);
      //use only if the browser supports these properties
  }
Enter fullscreen mode Exit fullscreen mode
  • 触摸功能 -这将适用于小屏幕或非悬停屏幕。@media only screen and (max-width: 56.25em), only screen and (hover:none){}

其他有用的概念

  • 优化图像 -通过裁剪或使用Optimizilla

  • 搜索引擎优化 -使用元标签

  • 类命名约定 - BEM

  • 全局重置

  * {
      margin: 0;
      padding: 0;
      box-sizing: inherit; //from body element
  } 
  html{
      font-size: 62.5%; //defines 1rem everywhere as 10px
  }
  body{
      box-sizing: border-box;
      /*
      Define project wide font family and size in body selector
      */
  }
Enter fullscreen mode Exit fullscreen mode

文章来源:https://dev.to/zinox9/html-css-responsiveness-reference-sheet-45i3
PREV
5 种方法让你的 CSS 水平飞速提升
NEXT
带有文本编辑器(Vim、Nano)的命令行备忘单 命令行备忘单