当前位置:网站首页>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]所创,转载请带上原文链接,感谢
边栏推荐
- C + + and C + + programmers are about to be eliminated from the market
- [C] (original) step by step teach you to customize the control element - 04, ProgressBar (progress bar)
- How to demote domain controllers and later in Windows Server 2012
- electron 實現檔案下載管理器
- An article will take you to understand CSS3 fillet knowledge
- Shh! Is this really good for asynchronous events?
- Live broadcast preview | micro service architecture Learning Series live broadcast phase 3
- FastThreadLocal 是什么鬼?吊打 ThreadLocal 的存在!!
- Xmppmini project details: step by step from the principle of practical XMPP technology development 4. String decoding secrets and message package
- 視覺滾動[反差美]
猜你喜欢
Will blockchain be the antidote to the global epidemic accelerating the transformation of Internet enterprises?
只有1个字节的文件实际占用多少磁盘空间
What are the common problems of DTU connection
Behind the first lane level navigation in the industry
CCR coin frying robot: the boss of bitcoin digital currency, what you have to know
It is really necessary to build a distributed ID generation service
代码重构之法——方法重构分析
Take you to learn the new methods in Es5
Filecoin has completed a major upgrade and achieved four major project progress!
给字节的学姐讲如何准备“系统设计面试”
随机推荐
image operating system windows cannot be used on this platform
Small program introduction to proficient (2): understand the four important files of small program development
【自学unity2d传奇游戏开发】地图编辑器
How to turn data into assets? Attracting data scientists
What is alicloud's experience of sweeping goods for 100 yuan?
Get twice the result with half the effort: automation without cabinet
Kubernetes and OAM to build a unified, standardized application management platform knowledge! (Internet disk link attached)
The dynamic thread pool in Kitty supports Nacos and Apollo multi configuration centers
Share with Lianyun: is IPFs / filecoin worth investing in?
Staying up late summarizes the key points of report automation, data visualization and mining, which is different from what you think
Gather in Beijing! The countdown to openi 2020
Even liver three all night, jvm77 high frequency interview questions detailed analysis, this?
Details of dapr implementing distributed stateful service
递归、回溯算法常用数学基础公式
意派Epub360丨你想要的H5模板都在这里,电子书、大转盘、红包雨、问卷调查……
How does filecoin's economic model and future value support the price of fil currency breaking through thousands
To Lianyun analysis: why is IPFs / filecoin mining so difficult?
美团内部讲座|周烜:华东师范大学的数据库系统研究
An article will take you to understand SVG gradient knowledge
Diamond standard