当前位置:网站首页>前端工程师需要懂的前端面试题(c s s方面)总结(二)
前端工程师需要懂的前端面试题(c s s方面)总结(二)
2020-11-06 20:48:00 【叫我詹躲躲】
实现元素水平垂直居中的几种方法:
<div id="wrap">
<div class="box"></div>
</div>
1. 定位方法实现水平垂直居中
<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>
定位和transform方法实现元素水平垂直居中
<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. 最新版本的flex实现元素的水平垂直居中
<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. 使用老版本flex实现元素水平垂直居中
<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>
用纯css创建一个三角形
主要是把高度和宽度设置成为0,用边框来实现三角形效果
html代码:
<div id="box">
</div>
css代码:
<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>

由上图效果可以根据自己需要三角形类型改成相应边框的颜色,不需要的边框设置成transparent
如例子:左边和上边的边框设置成红色
#box {
width: 0px;
height: 0px;
border: 100px solid ;
border-top-color: red;
border-right-color: transparent;
border-left-color: red;
border-bottom-color:transparent ;
}

如何实现移动端rem适配
html根元素的字体大小设置屏幕区域的宽
<div id="box">
</div>
<style> *{
margin: 0;
padding: 0;
}
#box {
width: 1rem;
height: 1rem;
background: red;
}
</style>
<script type="text/javascript"> window.onload = function () {
// 获取屏幕区域宽度
var width=document.documentElement.clientWidth
// 获取html
var htmlNode = document.querySelector('html')
// 设置字体大小
htmlNode.style.fontSize= width + 'px'
}
</script>
版权声明
本文为[叫我詹躲躲]所创,转载请带上原文链接,感谢
https://my.oschina.net/u/3995971/blog/4558927
边栏推荐
- 熬夜总结了报表自动化、数据可视化和挖掘的要点,和你想的不一样
- Python Jieba segmentation (stuttering segmentation), extracting words, loading words, modifying word frequency, defining thesaurus
- Process analysis of Python authentication mechanism based on JWT
- The practice of the architecture of Internet public opinion system
- Natural language processing - wrong word recognition (based on Python) kenlm, pycorrector
- IPFS/Filecoin合法性:保护个人隐私不被泄露
- Character string and memory operation function in C language
- 业内首发车道级导航背后——详解高精定位技术演进与场景应用
- JVM memory area and garbage collection
- Filecoin主网上线以来Filecoin矿机扇区密封到底是什么意思
猜你喜欢

I'm afraid that the spread sequence calculation of arbitrage strategy is not as simple as you think

Filecoin最新动态 完成重大升级 已实现四大项目进展!

熬夜总结了报表自动化、数据可视化和挖掘的要点,和你想的不一样

hadoop 命令总结

全球疫情加速互联网企业转型,区块链会是解药吗?

Want to do read-write separation, give you some small experience

Grouping operation aligned with specified datum

Don't go! Here is a note: picture and text to explain AQS, let's have a look at the source code of AQS (long text)

Summary of common algorithms of linked list

Python Jieba segmentation (stuttering segmentation), extracting words, loading words, modifying word frequency, defining thesaurus
随机推荐
加速「全民直播」洪流,如何攻克延时、卡顿、高并发难题?
Grouping operation aligned with specified datum
小程序入门到精通(二):了解小程序开发4个重要文件
人工智能学什么课程?它将替代人类工作?
From zero learning artificial intelligence, open the road of career planning!
6.1.1 handlermapping mapping processor (1) (in-depth analysis of SSM and project practice)
I've been rejected by the product manager. Why don't you know
Save the file directly to Google drive and download it back ten times faster
快快使用ModelArts,零基礎小白也能玩轉AI!
Summary of common string algorithms
Natural language processing - wrong word recognition (based on Python) kenlm, pycorrector
Why do private enterprises do party building? ——Special subject study of geek state holding Party branch
Programmer introspection checklist
How to get started with new HTML5 (2)
EOS创始人BM: UE,UBI,URI有什么区别?
(2)ASP.NET Core3.1 Ocelot路由
采购供应商系统是什么?采购供应商管理平台解决方案
Word segmentation, naming subject recognition, part of speech and grammatical analysis in natural language processing
Filecoin主网上线以来Filecoin矿机扇区密封到底是什么意思
html