当前位置:网站首页>Summary of front-end interview questions (C, s, s) that front-end engineers need to understand (2)
Summary of front-end interview questions (C, s, s) that front-end engineers need to understand (2)
2020-11-06 20:48:00 【Tell me Zhan to hide】
Several methods to realize the horizontal and vertical center of elements :
<div id="wrap">
<div class="box"></div>
</div>
1. Positioning method to achieve horizontal and vertical center
<style> *{
margin: 0;
padding: 0;
}
#wrap {
width: 500px;
height: 500px;
background: grey;
position: relative;
}
#wrap .box {
width: 200px;
height: 200px;
background: pink;
left: 0;
right: 0;
top: 0;
bottom: 0;
margin: auto;
position: absolute;
}
</style>
Positioning and transform Method to realize the horizontal and vertical center of elements
<style> *{
margin: 0;
padding: 0;
}
#wrap {
width: 500px;
height: 500px;
background: grey;
position: relative;
}
#wrap .box {
width: 200px;
height: 200px;
background: pink;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
}
</style>
3. Latest version flex Achieve horizontal and vertical centering of elements
<style> *{
margin: 0;
padding: 0;
}
#wrap {
width: 500px;
height: 500px;
background: grey;
display: flex;
justify-content: center;
align-items: center;
}
#wrap .box {
width: 200px;
height: 200px;
background: pink;
}
</style>
4. Use old version flex Realize the horizontal and vertical center of elements
<style> *{
margin: 0;
padding: 0;
}
#wrap {
width: 500px;
height: 500px;
background: grey;
display: -webkit-box;
-webkit-box-pack: center;
-webkit-box-align: center;
}
#wrap .box {
width: 200px;
height: 200px;
background: pink;
}
</style>
In pure css Create a triangle
The main thing is to set the height and width to 0, Use borders to achieve triangle effect
html Code :
<div id="box">
</div>
css Code :
<style> *{
margin: 0;
padding: 0;
}
#box {
width: 0px;
height: 0px;
border: 100px solid ;
border-top-color: red;
border-right-color: blue;
border-left-color: yellowgreen;
border-bottom-color: deeppink;
}
</style>
![image.png](https://imgconvert.csdnimg.cn/aHR0cHM6Ly9jZG4ubmxhcmsuY29tL3l1cXVlLzAvMjAyMC9wbmcvMTQ4MTQ2LzE1ODc1MTMxNDUyNTItYTIzMjk5ZDUtMzVjOC00ZmJkLTk3NmEtNDY3ODVhMzA4MDZmLnBuZw?x-oss-process=image/format,png#align=left&display=inline&height=247&margin=[object Object]&name=image.png&originHeight=494&originWidth=542&size=13252&status=done&style=none&width=271)
From the above effect, you can change the triangle type to the corresponding border color according to your own needs , Unnecessary borders are set to transparent
As an example : The left and top borders are set to red
#box {
width: 0px;
height: 0px;
border: 100px solid ;
border-top-color: red;
border-right-color: transparent;
border-left-color: red;
border-bottom-color:transparent ;
}
![image.png](https://imgconvert.csdnimg.cn/aHR0cHM6Ly9jZG4ubmxhcmsuY29tL3l1cXVlLzAvMjAyMC9wbmcvMTQ4MTQ2LzE1ODc1MTM0NDYwMzctZjE2Mzg4YWItMmJiNC00YjdkLTliN2UtYWI1YzEyYTA0OTRkLnBuZw?x-oss-process=image/format,png#align=left&display=inline&height=219&margin=[object Object]&name=image.png&originHeight=438&originWidth=506&size=10239&status=done&style=none&width=253)
How to realize mobile terminal rem adapter
html The font size of the root element sets the width of the screen area
<div id="box">
</div>
<style> *{
margin: 0;
padding: 0;
}
#box {
width: 1rem;
height: 1rem;
background: red;
}
</style>
<script type="text/javascript"> window.onload = function () {
// Get screen area width
var width=document.documentElement.clientWidth
// obtain html
var htmlNode = document.querySelector('html')
// Set font size
htmlNode.style.fontSize= width + 'px'
}
</script>
版权声明
本文为[Tell me Zhan to hide]所创,转载请带上原文链接,感谢
边栏推荐
- 华为云微认证考试简介
- How to turn data into assets? Attracting data scientists
- 2020年数据库技术大会助力技术提升
- Swagger 3.0 brushes the screen every day. Does it really smell good?
- Chainlink brings us election results into blockchain everipedia
- What are the common problems of DTU connection
- How to demote domain controllers and later in Windows Server 2012
- 【转发】查看lua中userdata的方法
- 使用 Iceberg on Kubernetes 打造新一代雲原生資料湖
- Use modelarts quickly, zero base white can also play AI!
猜你喜欢
代码生成器插件与Creator预制体文件解析
CCR coin frying robot: the boss of bitcoin digital currency, what you have to know
【字节跳动 秋招岗位开放啦】Ohayoo!放学别走,我想约你做游戏!!!
Share with Lianyun: is IPFs / filecoin worth investing in?
How about small and medium-sized enterprises choose shared office?
意派Epub360丨你想要的H5模板都在这里,电子书、大转盘、红包雨、问卷调查……
新建一个空文件占用多少磁盘空间?
Who says cat can't do link tracking? Stand up for me
嘉宾专访|2020 PostgreSQL亚洲大会阿里云数据库专场:王涛
What course of artificial intelligence? Will it replace human work?
随机推荐
Behind the record breaking Q2 revenue of Alibaba cloud, the cloud opening mode is reshaping
Use modelarts quickly, zero base white can also play AI!
【转发】查看lua中userdata的方法
What are PLC Analog input and digital input
Contract trading system development | construction of smart contract trading platform
Kubernetes and OAM to build a unified, standardized application management platform knowledge! (Internet disk link attached)
StickEngine-架构12-通信协议
image operating system windows cannot be used on this platform
es创建新的索引库并拷贝旧的索引库 实践亲测有效!
Staying up late summarizes the key points of report automation, data visualization and mining, which is different from what you think
大数据处理黑科技:揭秘PB级数仓GaussDB(DWS) 并行计算技术
What are Devops
Even liver three all night, jvm77 high frequency interview questions detailed analysis, this?
DC-1靶機
How to understand Python iterators and generators?
检测证书过期脚本
Basic usage of Vue codemirror: search function, code folding function, get editor value and verify in time
【学习】接口测试用例编写和测试关注点
Introduction to the structure of PDF417 bar code system
Application of restful API based on MVC