本篇文章给大家谈谈你所不知道❌CSS居中,同时本文还将给你拓展)预期css(css-rparentexpected)"用于@media查询中的第4级css语法、、不起作用、Angular:添加的doc
本篇文章给大家谈谈你所不知道 ❌ CSS 居中,同时本文还将给你拓展) 预期 css(css-rparentexpected)" 用于@media 查询中的第 4 级 css 语法、、 不起作用、Angular: 添加的 document.execCommand 只看到 style.css 中的 css 规则而不是组件的 css
等相关知识,希望对各位有所帮助,不要忘了收藏本站喔。
- 你所不知道 ❌ CSS 居中
- ) 预期 css(css-rparentexpected)" 用于@media 查询中的第 4 级 css 语法
- ">
- 不起作用"> 不起作用
- Angular:
- 添加的 document.execCommand 只看到 style.css 中的 css 规则而不是组件的 css
你所不知道 ❌ CSS 居中
前言
这次翻译一篇来自 Chris Coyier 的 《Centering in CSS: A Complete Guide》
居中
是在CSS
中经常被抱怨的问题之一。这个问题真的有这么难吗?事实上这个问题并没有那么复杂
,它困难
在于对于不同的情景
,解决
居中问题需要用到不一样
的方法。
在这里,我们会一起建立思维导图
来帮助大家来解决
这个问题。
github 地址 传送门
脑图
水平居中
行内元素
display
属性为inline
或者 inline-*
行内元素?(例如:文本或者链接)
如果你需要居中的行内元素
在块级元素
中,你可以使用下面方法。
.center-children {
text-align: center;
}
例子:传送门
单个 - 块级元素
如果需要使得块级元素居中
,可以利用margin-left
和margin-right
。
.center-me {
margin: 0 auto;
}
例子:传送门
注意:不能是一个浮动的块级元素哦~
多个 - 块级元素 - 同行居中
如果需要使得多个块级元素居中
,这个时候用 magin
可就不行啦,但是我们可以使用inline-block
或者flexbox
来实现居中。
inline-block
利用行内元素
在块级元素
中的居中方法,先让内部
的块级元素
变为行内元素,再对父级
的块级元素
使用居中。
.center-parent {
text-align: center;
}
.center-parent .center-child{
display: inline-block;
}
flexbox
.center-parent {
display: flex;
justify-content: center;
}
例子:传送门
多个 - 块级元素 - 同列居中
利用单个块级元素
的居中
方法,来实现多个块级元素
的垂直居中
。
.center-me {
margin: 0 auto;
}
例子:传送门
垂直居中
单行 - 行内元素
display
属性为inline
或者 inline-*
行内元素?(例如:文本或者链接)。可以利用padding
或者line-height
来实现。
padding
.text {
padding-top: 30px;
padding-bottom: 30px;
}
例子:传送门
line-height (值和height
一样)
.text {
height: 100px;
line-height: 100px;
}
例子:传送门
多行 - 行内元素
对于多行行内元素
,如果使用单行
的方法,在换行之后,会出现错误。这个时候可以利用表格
的vertical-align
或者flexbox
或者伪类
来实现。
vertical-align
.center-table {
display: table;
}
.center-table p {
display: table-cell;
vertical-align: middle;
}
例子:传送门
flexbox
.center-flexbox {
display: flex;
justify-content: center;
flex-direction: column;
}
例子:传送门
伪类
.center-parent {
position: relative;
}
.center-parent::before {
content: "";
display: inline-block;
height: 100%;
width: 1%;
vertical-align: middle;
}
.center-parent p {
display: inline-block;
vertical-align: middle;
}
例子:传送门
块级元素
元素高度知道
.parent {
position: relative;
}
.child {
position: absolute;
top: 50%;
height: 100px;
margin-top: -50px; // 高度的一半
}
例子:传送门
元素高度不知道
.parent {
position: relative;
}
.child {
position: absolute;
top: 50%;
transform: translateY(-50%);
}
例子:传送门
flexbox
.parent {
display: flex;
flex-direction: column;
justify-content: center;
}
例子:传送门
垂直水平居中
宽度和高度知道(利用垂直居中
的块级元素
高度知道)
.parent {
position: relative;
}
.child {
width: 200px;
height: 100px;
position: absolute;
top: 50%;
left: 50%;
margin: -50px 0 0 -100px;
}
例子:传送门
宽度和高度不知道(利用垂直居中
的块级元素
高度不知道)
.parent {
position: relative;
}
.child {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
例子:传送门
flexbox
.parent {
display: flex;
justify-content: center;
align-items: center;
}
例子:传送门
一起成长
在困惑的城市里总少不了并肩同行的 伙伴
让我们一起成长。
- 如果您想让更多人看到文章可以点个
点赞
。 - 如果您想激励小二可以到 Github 给个
小星星
。 - 如果您想与小二更多交流添加微信
m353839115
。
本文原稿来自 PushMeTop
) 预期 css(css-rparentexpected)" 用于@media 查询中的第 4 级 css 语法
Visual Studio Code does not support 4 级范围语法呢。此外,MDN 表示目前只有 Firefox 支持该语法。如果您需要跨浏览器支持,您现在需要坚持使用原始的 max-width
语法:
@media (max-width: 768px) {
h1 {
font-size: 3em;
color: mediumvioletred;
}
nav a {
display: flex;
flex-direction: column;
align-items: center;
color: mediumaquamarine;
}
}
否则,你所拥有的是正确的。
" alt="">
OSC 请你来轰趴啦!1028 苏州源创会,一起寻宝 AI 时代
css 样式 引入 href="css/layout.css?id=7" 是什么意思?
不起作用" alt=" 不起作用">
不起作用"> 不起作用
如何解决<link rel="stylesheet" type="text/css" href="{% static ''css/style.css'' %}"> 不起作用
我在 vs-code 上将 css 链接到 html。 center-aliend 在这里不起作用。有没有人知道哪个部分有问题? 我想设置文本“Hello Static!!”到浏览器的中心。
{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
<Meta charset="UTF-8">
<Meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="{% static ''css/style.css'' %}">
<title>Static Practice</title>
</head>
<body>
<div>Hello Static!!</div>
</body>
</html>
body {
text-align: center;
}
# Static files (CSS,JavaScript,Images)
# https://docs.djangoproject.com/en/3.1/howto/static-files/
STATIC_URL = ''/static/''
STATICFILES_Dirs = [
BASE_DIR / ''static''
]
Angular: 添加的 document.execCommand 只看到 style.css 中的 css 规则而不是组件的 css
如何解决Angular: <ol> 添加的 document.execCommand 只看到 style.css 中的 css 规则而不是组件的 css
我正在 angular 中创建富文本编辑器,当我执行 document.execCommand(''insertOrderedList'')
时,我得到 <ol>
项,它不受我组件的 css 的影响,只有 styles.css
中的 css(主 css 文件在项目的根目录)影响我使用 document.execCommand
添加的项目。
是否有可能改变这种行为?
解决方法
当然。它的名字是view encapsulation。将其更改为 ViewEncapsulation.none
会产生所需的行为。
@Component({
...
encapsulation: ViewEncapsulation.none
})
今天关于你所不知道 ❌ CSS 居中的介绍到此结束,谢谢您的阅读,有关) 预期 css(css-rparentexpected)" 用于@media 查询中的第 4 级 css 语法、、 不起作用、Angular: 添加的 document.execCommand 只看到 style.css 中的 css 规则而不是组件的 css
等更多相关知识的信息可以在本站进行查询。
本文标签: