How to center in CSS 一步步拆解你的需求,是水平居中还是垂直居中?还是水平垂直居中?父容器是inline还是block,高度知不知,宽度造不造?一个子元素还是多个子元素?一行还是多行?文字?图片? 理论知识 属性:text-align 用法:text-align CSS 属性定义行内内容(例如文字)如何相对它的块父元素对齐.text-align并不控制块级元素自己的对齐,只控制它的行内内容的对齐→→(demo展示text-align对行内元素与块元素的区别) 除了默认的行内元…
css中的::after和::before已经被大量地使用在我们日常开发中了,使用他们可以使我们的文档结构更加简洁.但是很多人对::after和::before仍不是特别了解,究竟他们是做什么的?如何使用他们?什么时候应该使用他们?笔者总结了一些对伪元素的理解和使用经验. 一.概念: 1.定义 The CSS ::before(::after) pseudo-element matches a virtual first(last) child of the selected element.…
翻译自:https://css-tricks.com/centering-css-complete-guide/ Centering things in CSS is the poster child of CSS complaining. Why does it have to be so hard? They jeer. I think the issue isn't that it's difficult to do, but in that there so many different…