css常见样式

1.块级元素和行内元素分别有哪些?动手测试并列出4条以上的特性区别

  • 块级元素
    div h1 h2 h3 h4 h5 h6 p hr form ul dl ol pre table li dd dt tr td th
  • 行内元素
    em strong span a br img button input label select textarea code script
  • 区别
    1. 块级可以包含块级和行内,行内只能包含文本和行内
    2. 块级占据一整行空间,行内占据自身宽度空间
    3. 宽高只对块级元素设置生效,对行内元素设置无效
    4. 行内元素设置width无效,height无效(可以设置line-height),margin上下无效左右有效,padding上下无效左右有效,

2.png

2.什么是 CSS 继承? 哪些属性能继承,哪些不能?

  • CSS继承:父元素设置的属性,自动继承到子孙元素
  • 不可继承的:display、margin、border、padding、background、height、min-height、max-height、width、min-width、max-width、overflow、position、left、right、top、bottom、z-index、float、clear、table-layout、vertical-align、page-break-after、page-bread-before和unicode-bidi。
  • 所有元素可继承:visibility和cursor。
    内联元素可继承:letter-spacing、word-spacing、white-space、line-height、color、font、font-family、font-size、font-style、font-variant、font-weight、text-decoration、text-transform、direction。
    终端块状元素可继承:text-indent和text-align。
    列表元素可继承:list-style、list-style-type、list-style-position、list-style-image

3.如何让块级元素水平居中?如何让行内元素水平居中?

  • 对于块级元素设置左右margin:auto
  • 对于行内元素设置text-align:center

4.用 CSS 实现一个三角形?

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JS Bin</title>
  <style>
    div{
  width: 0px;
  height: 0px;
    border-top:100px solid yellow;
    border-left:100px solid transparent;
    border-bottom:100px solid transparent;
    border-right:100px solid transparent;
}
  </style>
</head>
<body>
  <div>
    
  </div>
</body>
</html>
3.png

5.单行文本溢出加 ...如何实现?

.card > h3{
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

6.px, em, rem 有什么区别

px:固定尺寸
em:相对于父元素的尺寸倍数
rem:相对于根元素的尺寸倍数

7.解释下面代码的作用?为什么要加引号? 字体里\5b8b\4f53代表什么?

body{
  font: 12px/1.5 tahoma,arial,'Hiragino Sans GB','\5b8b\4f53',sans-serif;
}
  • 字体大小为12px;字体行高为1.5倍字体大小;字体可在tahoma,arial,'Hiragino Sans GB','\5b8b\4f53',sans-serif 这些字体中选择(若都不存在,则为浏览器默认字体)
  • 当有空格或者Unicode码时,需要加引号
  • \5b8b\4f53是字体的Unicode码,表示黑体

8.代码

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容