当前位置:网站首页>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]所创,转载请带上原文链接,感谢
边栏推荐
- 给字节的学姐讲如何准备“系统设计面试”
- Filecoin has completed a major upgrade and achieved four major project progress!
- C + + and C + + programmers are about to be eliminated from the market
- GUI engine evaluation index
- 開源一套極簡的前後端分離專案腳手架
- Behind the first lane level navigation in the industry
- hdu3974 Assign the task線段樹 dfs序
- Use modelarts quickly, zero base white can also play AI!
- 意外的元素..所需元素..
- [C] (original) step by step teach you to customize the control element - 04, ProgressBar (progress bar)
猜你喜欢

Multi robot market share solution

华为云微认证考试简介

Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom

Helping financial technology innovation and development, atfx is at the forefront of the industry

Gather in Beijing! The countdown to openi 2020

给字节的学姐讲如何准备“系统设计面试”

2020年第四届中国 BIM (数字建造)经理高峰论坛即将在杭举办

大数据处理黑科技:揭秘PB级数仓GaussDB(DWS) 并行计算技术

GitHub: the foundation of the front end

【学习】接口测试用例编写和测试关注点
随机推荐
Basic usage of GDB debugging
The importance of big data application is reflected in all aspects
nacos、ribbon和feign的簡明教程
Some operations kept in mind by the front end foundation GitHub warehouse management
DRF JWT authentication module and self customization
行为型模式之解释器模式
【学习】接口测试用例编写和测试关注点
华为Mate 40 系列搭载HMS有什么亮点?
一部完整的游戏,需要制作哪些音乐?
Even liver three all night, jvm77 high frequency interview questions detailed analysis, this?
【ElasticSearch搜索引擎】
Network security engineer Demo: the original * * is to get your computer administrator rights! [maintain]
WeihanLi.Npoi 1.11.0/1.12.0 Release Notes
文件过多时ls命令为什么会卡住?
Xmppmini project details: step by step from the principle of practical XMPP technology development 4. String decoding secrets and message package
每个大火的“线上狼人杀”平台,都离不开这个新功能
The AI method put forward by China has more and more influence. Tianda et al. Mined the development law of AI from a large number of literatures
代码重构之法——方法重构分析
前端未來趨勢之原生API:Web Components
To Lianyun analysis: why is IPFs / filecoin mining so difficult?