当前位置:网站首页>2021 Kent interview question 3
2021 Kent interview question 3
2022-07-28 15:56:00 【PBitW】
List of articles
How do floating elements go up, down, left and right
here , Rookies have never encountered this kind of situation , Because the general interview question is , A big one. div There is a small one in it div, How to make it up, down, left and right , That is, the small inside div There is no floating !
At that time, rookies felt , Anyway, the way up, down, left and right is so 4 individual , Just say it directly , Then I just opened my mouth and said flex Layout ,HR Just say no , I'm so confused , Then I talked about positioning ,HR Still wrong , Then I don't want to answer , Want to see what he said , As a result, he told me a great truth , Say that I don't write enough code , So I don't know , Try !
flex Layout
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style> .wrapper{
width: 400px; height: 400px; background-color: aqua; display: flex; justify-content: center; align-items: center; } .content{
width: 100px; height: 100px; background-color: blueviolet; float: left; } </style>
</head>
<body>
<div class="wrapper">
<div class="content">
</div>
</div>
</body>
</html>
Running results :
position( location )
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style> .wrapper{
width: 400px; height: 400px; background-color: aqua; position: relative; } .content{
width: 100px; height: 100px; background-color: blueviolet; float: left; position: absolute; left: 50%; top: 50%; transform: translate(-50%,-50%); } .content1{
width: 100px; height: 100px; background-color: blueviolet; position: absolute; left: 50%; top: 50%; transform: translate(-50%,-50%); } </style>
</head>
<body>
<div class="wrapper">
<div class="content">
</div>
</div>
<hr>
<div class="wrapper">
<div class="content1">
</div>
</div>
</body>
</html>
Running results :
Be careful
There are two points to note here :
- translate yes Move based on itself ,translate() Method , According to the left (X Axis ) And the top (Y Axis ) Parameters given by position , Move from current element position
- Different positioning ,translate Although it is still 50%, But the positive and negative situations are different
margin and padding
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style> .wrapper{
width: 400px; height: 400px; background-color: aqua; box-sizing: border-box; padding-top: 150px; } .content{
width: 100px; height: 100px; background-color: blueviolet; float: left; /* margin: 0 auto; flaot after auto It doesn't work */ margin-left: 150px; } </style>
</head>
<body>
<div class="wrapper">
<div class="content">
</div>
</div>
</body>
</html>
Running results :
IE Box model and ordinary box model ?
notice box-sizing Remember again HR A question to ask , That's the box model ,IE Box model and ordinary box model ?
I was very confused at that time , This is used box-sizing Can you set it ? The main reason is that I couldn't remember it at that time border-box Corresponding IE still content-box The corresponding is IE 了 !( The rookie searched ,border-box Corresponding IE)
See my blog more :
Box model ( One ): First knowledge of box model 、 Frame [ The fourth day ]
table-cell
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style> .wrapper{
width: 400px; height: 400px; background-color: aqua; display: table-cell; vertical-align: middle; } .content{
width: 100px; height: 100px; background-color: blueviolet; float: left; /* margin: 0 auto; */ margin-left: 150px; } .content1{
width: 100px; height: 100px; background-color: blueviolet; margin: 0 auto; } </style>
</head>
<body>
<div class="wrapper">
<div class="content">
</div>
</div>
<p>fjakfjalk</p>
<div class="wrapper">
<div class="content1">
</div>
</div>
</body>
</html>
Running results :
summary
In fact, whether the elements float or not is only right margin Of auto Use has an impact , It has no effect on others !
- Set to Flex After the layout , The child element float、clear and vertical-align Property will fail !
- Positioning is also to get sub elements out of the document flow , therefore float Just one step ahead !
边栏推荐
- 远距离串口服务器( 适配器)UART/I2C/1-Wire/SPI PS304常见问题及注意事项
- 深部位移监测系统wk813应用边坡、大坝、堤防、铁路和建筑基坑开挖等深部位移测量
- 低成本/小体积模块RS485/232转模拟信号的原理以及应用IBF33
- Remember the common JS methods of projects
- 数据实时反馈技术
- DNS domain name resolution protocol
- A tour of grp:05 - GRP server streaming service end stream
- 便携式钻孔测斜仪数据采集仪测量原理与测斜探头的连接及使用方法
- How to turn on and off flight mode through ADB
- One channel encoder, two channels Di speed measurement, RS485 serial port connected to one channel do alarm module ibf151
猜你喜欢

Software architecture and design (IV) -- data flow architecture

What is the concept of game testing? What are the test methods and processes?

Principle and application of low cost / small volume module rs485/232 to analog signal ibf33

远距离串口服务器( 适配器)UART/I2C/1-Wire/SPI PS304常见问题及注意事项

2021 肯特面试题3
![[live broadcast reservation] a new challenge under the evolution of data architecture - Shanghai railway station](/img/46/2a641ea3a0c805ff2377253a824a04.png)
[live broadcast reservation] a new challenge under the evolution of data architecture - Shanghai railway station

如何有效进行回顾会议(上)?

VM501开发套件开发版单振弦式传感器采集模块岩土工程监测

Multifunctional mixed signal AI acquisition / switching value di/do acquisition to rs485/232/modbus module

2021 肯特面试题1
随机推荐
Preparing for listing in the United States? Arm announced that it would divest the Internet of things service business: the future will focus on the underlying chip design
How to quickly access the unified authentication system
Rxdart is used instead of stateful in fluent
热敏电阻PT100,NTC转0-10V/4-20mA转换器
低成本/小体积模块RS485/232转模拟信号的原理以及应用IBF33
Note: numerical accumulation animation
Software architecture and design (IX) -- component based architecture
激光测距仪非接触式地表裂缝监测仪
一波骚操作解决Laya场景编辑器报错问题
Voice social system -- improve the audio system industry chain
阿里云的rds mysql 只读实例在哪里创建
Event express | Apache Doris Performance Optimization Practice Series live broadcast course is open at the beginning. You are cordially invited to participate!
知识点qwer
Principle and application of low cost / small volume module rs485/232 to analog signal ibf33
射频模块无线收发RF63U芯片应用数据传输和基建网络
js 链表 02
Knowledge points qwer
高速计数器转RS485Modbus RTU模块IBF150
28.55亿元!青岛芯恩增资完成:兴橙集电成第一大股东,持股57.10%
Youdao cloud notes remove the bottom advertisement