当前位置:网站首页>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]所创,转载请带上原文链接,感谢
边栏推荐
- 代码生成器插件与Creator预制体文件解析
- Analysis of serilog source code -- how to use it
- Filecoin has completed a major upgrade and achieved four major project progress!
- 意外的元素..所需元素..
- Staying up late summarizes the key points of report automation, data visualization and mining, which is different from what you think
- 华为云微认证考试简介
- (1) ASP.NET Introduction to core3.1 Ocelot
- MongoDB与SQL常用语法对应表
- How to get started with new HTML5 (2)
- 华为Mate 40 系列搭载HMS有什么亮点?
猜你喜欢

Live broadcast preview | micro service architecture Learning Series live broadcast phase 3

Bitcoin once exceeded 14000 US dollars and is about to face the test of the US election

事务的隔离级别与所带来的问题

Behind the record breaking Q2 revenue of Alibaba cloud, the cloud opening mode is reshaping

Even liver three all night, jvm77 high frequency interview questions detailed analysis, this?

What is the meaning of sector sealing of filecoin mining machine since the main network of filecoin was put online

嘉宾专访|2020 PostgreSQL亚洲大会阿里云数据库专场:王涛

每个大火的“线上狼人杀”平台,都离不开这个新功能

Contract trading system development | construction of smart contract trading platform

华为Mate 40 系列搭载HMS有什么亮点?
随机推荐
前端未來趨勢之原生API:Web Components
How about small and medium-sized enterprises choose shared office?
[Xinge education] poor learning host computer series -- building step 7 Simulation Environment
Markdown tricks
electron 實現檔案下載管理器
An article will take you to understand CSS alignment
How does filecoin's economic model and future value support the price of fil currency breaking through thousands
事件监听问题
Humor: hacker programming is actually similar to machine learning!
Use modelarts quickly, zero base white can also play AI!
Look! Internet, e-commerce offline big data analysis best practice! (Internet disk link attached)
Jmeter——ForEach Controller&Loop Controller
Network programming NiO: Bio and NiO
In depth to uncover the bottom layer of garbage collection, this time let you understand her thoroughly
Ronglian completed US $125 million f round financing
只有1个字节的文件实际占用多少磁盘空间
Read the advantages of Wi Fi 6 over Wi Fi 5 in 3 minutes
Live broadcast preview | micro service architecture Learning Series live broadcast phase 3
使用 Iceberg on Kubernetes 打造新一代雲原生資料湖
PHP application docking justswap special development kit【 JustSwap.PHP ]