美文网首页
CSS常见样式

CSS常见样式

作者: kumabearplus | 来源:发表于2017-04-27 21:07 被阅读19次

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

    • 块级元素(block-level)
      div h1 h2 h3 h4 h5 h6 p hr
      form ul dl ol pre table
      li dd dt tr td th
    • 行内元素(inline-level)
      em strong span a br img
      button input label select textarea
      code script

    区别

    1. 块级元素占据一整行空间,行内元素只占据自身宽度的空间,一行中可以排列多个行内元素。
    1. 块级元素可以包含块级元素和行内元素,行内元素只能包含行内元素和文本。
    2. 块级元素可以设置宽高,行内元素设置宽高是无效的。
    3. 块级元素上下左右都可以设置margin和padding,而行内元素只有设置左右margin和padding时有效,设置上下margin和padding时无效。

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

    CSS继承:每个 CSS 属性定义的概述都指出了这个属性是默认继承的还是默认不继承的。当元素的一个继承属性没有指定值时,则取父元素的同属性的计算值,这就是继承。

    • 有继承性的属性:
      字体相关属性:font,font-family,font-weight,font-size,font-style,font-stretch,font-size-adjust
      文本相关属性:text-indent(文本缩进),text-align,line-height,word-spacing,letter-spacing,text-transform,direction,color
      元素可见性:visibility
      表格布局属性:caption-side,border-collapse,border-spacing,empty-cells,table-layout
      列表布局属性:list-style-type,list-style-image,list-style-position,list-style
      生成内容属性:quotes
      光标属性:cursor
      页面样式属性:page,page-break-inside,window,orphans
      声音样式属性:speak,speak-punctuation
    • 无继承性的属性
      文本属性:vertical-align,text-shadow,text-decoration,white-space,unicode-bidi
      盒子模型相关属性:width,height,margin相关属性,border相关属性,padding相关属性
      背景相关属性:background,background-XXX
      定位属性:float,clear,position,top,right,bottom,left,min-width,min-height,max-width,max-height,overflow,clip,z-index
      生成内容属性:content,counter-reset,counter-increment
      轮廓样式属性:outline-style,outline=width,outline-color,outline
      页面样式属性:size,page-break-before,page-break-after
      声音样式属性:pause-before,pause-after,pause,cue-before,cue-after,cue,play-during

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

    • 块级元素水平居中:margin: 0 auto;
    • 行内元素水平居中:在包含行内元素的块级元素中加入属性 text-align: center;

    4、用CSS绘制一个三角形

    代码如下:

        .tri {
          width: 0px;
          height: 0px;
          border-bottom: 30px solid transparent;
          border-left: 30px solid transparent;
          border-top: 30px solid transparent;
          border-right: 30px solid yellow;
        }
    

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

    代码如下:

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

    6、px, em, rem 有什么区别?

    • px —— 像素,固定单位
    • em —— 相对单位,相对于父元素字体的大小,一般指字体高度
    • rem —— 相对单位,相对于根元素(html)字体的大小

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

    body{
       font: 12px/1.5 tahoma,arial,'Hiragino Sans GB','\5b8b\4f53',sans-serif;
    }
    
    • 上面代码表示body里面的字体大小为12px,行高为12px的1.5倍,即18px.字体优先采用tahoma字体,后面用,分开的都是备选字体,若前面的字体浏览器找不到则按照顺序依次往下选择。
    • 引号表明字体名称包含空格,引号内部是一个字体的整体名称。
    • 在 CSS 中设置字体时,直接写字体中文或英文名称浏览器都能识别,直接写中文的情况下编码(GB2312、UTF-8 等)不匹配时会产生乱码。保险的方式是将字体名称用Unicode来表示。代码中的'\5b8b\4f53'就是用Unicode表示的字体宋体。

    相关文章

      网友评论

          本文标题:CSS常见样式

          本文链接:https://www.haomeiwen.com/subject/mmpnzttx.html