美文网首页Web前端之路
css部分基础知识回顾(一)

css部分基础知识回顾(一)

作者: jaimor | 来源:发表于2020-03-02 09:56 被阅读0次

css盒子模型

css和模型有两种,第一种是标准盒子模型(content-box),另一种是怪异盒子模型(IE,border-box)。标准盒子模型的盒子宽度width = contentWidth + paddingLeft + paddingRight + borderLeft + borderRgitht + marginLeft + marginRightheight = contentHeight + paddingTop + paddingBottom + borderTop + borderBottom + marginTop + marginBottom;怪异盒子模型的盒子宽度width = contentWdith + marginLeft + marginRightheight = contentHeight + marginTop + marginBottom,而其中contentWidth包含了内容宽度 + padding + border

link标签和@import标签的区别

link:是html中的标签,跟随html的加载而加载;
@import:是css中提供的一种引入css的一种方式,最后加载,一般会等待页面加载完成后再加载;
link@import优先级,主要看引入的位置,后边覆盖前边的。

垂直居中的方法

垂直居中的方法很多,这里例举三种常用的。

/* flex布局模式: */
.parent {
  display: flex;
  flex-flow: row nowrap;
  justify-content: center;  /* 主轴居中显示 */
  align-items: center;  /* 交叉轴居中显示 */
}
/* position + transform */
.parent {
  width: 1000px;
  height: 1000px;
  position: relative;
}
.child {
  position: absolute;
  width: 100px;
  height: 100px;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}
/* position + margin */
.parent {
  width: 1000px;
  height: 1000px;
  position: relative;
}
.child {
  position: absolute;
  width: 100px;
  height: 100px;
  margin: auto;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
}

opacity=0,visibility=hidden,display:none的区别

opacity=0:在界面上不显示,但是会占住自己所在的位置,如果有点击事件,当点击该区域时也会触发事件。
visibility=hidden:在界面上不显示,但是会占住自己所在的位置,不会触发点击事件。
display:none:在界面上不显示,而且不会占位,也不会触发事件。

清除浮动

因为在使用float属性的时候,父元素不会被撑开,很容易造成样式错乱,所以很多时候都需要清除浮动,清除浮动的方法主要介绍两种常用的。

<!-- 在浮动的的元素最后添加div clear:both的方式 -->
<div class="parent">
  <div style="float:left">a</div>
  <div style="float:left">b</div>
  <div style="clear:both"></div>
</div>
<!-- 这样父级div.parent的高度就能撑开 -->
<!-- 还有另外一种写法,使用伪元素清除浮动 -->
<style>
.parent::after {
  content: "";
  clear: both;
  height: 0;
  display: block;  /*需要设置块级元素才可以*/
}
</style>
<div class="parent">
  <div style="float:left">a</div>
  <div style="float:left">b</div>
</div>
<!-- 使用BFC布局清除浮动 -->
<style>
.parent {
  overflow: hidden;
}
</style>
<div class="parent">
  <div style="float:left">a</div>
  <div style="float:left">b</div>
</div>
<!-- BFC模式可以独立开辟一个空间,其空间内的样式不会影响外部样式,
而且浮动的元素也会计算高度 -->

css伪类和伪元素

伪类:顾名思义,是一个类,就像.parent .child一样(只是写法不一样),为其设置样式,那么该元素就会显示特定的样式。如a:hover表示鼠标移动上a标签的时候需要显示的样式,类似的还有:active :visited :last-child :nth-child(n)等。
伪元素:顾名思义,是一个元素,只是该元素不在文档树种。如:::before ::after等。div::after { content: 'abc'; }会在div后边生成abc字符串,但是并不在文档树中,此方法还可以用来清除浮动。

inline block inline-block 的区别

  • inline:inline元素不会独占一行,设置width height无效,垂直方向margin padding无效。
  • block:block元素会独占一行,默认自动铺满父元素宽度,就算设置宽度,也是独占一行,设置margin padding生效。
  • inline-block:拥有可以设置的block属性,同时拥有inline不会独占一行属性。

相关文章

  • css部分基础知识回顾(一)

    css盒子模型 css和模型有两种,第一种是标准盒子模型(content-box),另一种是怪异盒子模型(IE,b...

  • css部分基础知识回顾(二)

    浏览器回流与重绘 之所以能在页面上看到内容,是因为浏览器拿到服务器发送的数据后,开始做解析标签样式的操作,然后维护...

  • JavaScript部分基础知识回顾(一)

    js的数据类型 string number boolean undefined null object symbo...

  • CSS相关汇总

    CSS命名规范 CSS基础知识 CSS优化技巧 CSS的继承关系 CSS的选择器关系介绍

  • 00.CSS基础知识回顾

    1.选择器 元素选择器 id选择器 类选择器 属性选择器[属性名]选取含有指定属性的元素[属性名="属性值"]选取...

  • 《Head First HTML 与 CSS》读书笔记之CSS篇

    本文为阅读《Head First HTML 与 CSS》的css部分的读书笔记,方便回顾书上的知识,另一篇为Hea...

  • React Native

    (1) 基础知识 1、组件 和React的封装方式一致 2、样式 支持FlexBox布局;支持大部分的css样式;...

  • css基础

    1 、 CSS样式的基础知识 1 认识CSS样式 CSS全称为“层叠样式表 (Cascading Style Sh...

  • CSS 知识总结03

    1. CSS知识: i. CSS基础知识这里不作赘述,有兴趣自查 MDN Web文档。 ii.CSS----- ...

  • CSS基础知识

    CSS基础知识 css,英文Cascading Style Sheets,中文名:级联样式表。层叠样式表。 css...

网友评论

    本文标题:css部分基础知识回顾(一)

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