当前位置:网站首页>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>

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 ;
}

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]所创,转载请带上原文链接,感谢
边栏推荐
- nacos、ribbon和feign的簡明教程
- 【字节跳动 秋招岗位开放啦】Ohayoo!放学别走,我想约你做游戏!!!
- How to hide part of barcode text in barcode generation software
- WeihanLi.Npoi 1.11.0/1.12.0 Release Notes
- 代码生成器插件与Creator预制体文件解析
- Building a new generation cloud native data lake with iceberg on kubernetes
- Basic principle and application of iptables
- Basic usage of Vue codemirror: search function, code folding function, get editor value and verify in time
- Application of restful API based on MVC
- EOS founder BM: what's the difference between UE, UBI and URI?
猜你喜欢
Look! Internet, e-commerce offline big data analysis best practice! (Internet disk link attached)
Network security engineer Demo: the original * * is to get your computer administrator rights! [maintain]
Use modelarts quickly, zero base white can also play AI!
Outsourcing is really difficult. As an outsourcer, I can't help sighing.
Pn8162 20W PD fast charging chip, PD fast charging charger scheme
ado.net和asp.net的关系
Gather in Beijing! The countdown to openi 2020
文件过多时ls命令为什么会卡住?
The method of realizing high SLO on large scale kubernetes cluster
一部完整的游戏,需要制作哪些音乐?
随机推荐
Flink's datasource Trilogy 2: built in connector
小游戏云开发入门
hdu3974 Assign the task線段樹 dfs序
An article takes you to understand CSS pagination examples
What are PLC Analog input and digital input
代码生成器插件与Creator预制体文件解析
Details of dapr implementing distributed stateful service
嘉宾专访|2020 PostgreSQL亚洲大会阿里云数据库专场:曾文旌
From overseas to China, rancher wants to do research on container cloud market
【字节跳动 秋招岗位开放啦】Ohayoo!放学别走,我想约你做游戏!!!
代码重构之法——方法重构分析
ado.net和asp.net的关系
Git rebase is in trouble. What to do? Waiting line
2020年第四届中国 BIM (数字建造)经理高峰论坛即将在杭举办
Chainlink brings us election results into blockchain everipedia
How to hide part of barcode text in barcode generation software
消息队列(MessageQueue)-分析
[C] (original) step by step teach you to customize the control element - 04, ProgressBar (progress bar)
Helping financial technology innovation and development, atfx is at the forefront of the industry
Look! Internet, e-commerce offline big data analysis best practice! (Internet disk link attached)