当前位置:网站首页>2021 肯特面试题3
2021 肯特面试题3
2022-07-28 14:51:00 【PBitW】
浮动的元素怎么上下左右具中
这里,菜鸟没有遇见过这种情况,因为一般的面试题问的是,一个大的div里面有个小的div,如何使其上下左右具中,也就是里面的小div是没有浮动的!
当时菜鸟就感觉,反正上下左右具中的方式就那么4个,直接都说一下不就好了,然后我刚开口说flex布局,HR就说不对,我很懵逼,然后又说了定位,HR还是说不对,然后我就不想回答了,想看看他怎么说的,结果他给我讲了一番大道理,说什么我写的代码不够多,所以不知道,要试!
flex布局
<!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>
运行结果:
position(定位)
<!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>
运行结果:
注意
这里要注意的有两点:
- translate是 以自身为基准移动,translate()方法,根据左(X轴)和顶部(Y轴)位置给定的参数,从当前元素位置移动
- 定位不一样,translate里面虽然还是50%,但是正负情况不一样
margin和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之后auto就无效了 */ margin-left: 150px; } </style>
</head>
<body>
<div class="wrapper">
<div class="content">
</div>
</div>
</body>
</html>
运行结果:
IE的盒模型和普通的盒模型?
看到box-sizing又记起来HR问的一个问题了,那就是盒模型,IE的盒模型和普通的盒模型?
我当时就很懵逼,这个不就是用box-sizing就可以设置的吗?主要是我当时也记不清到底是border-box对应的IE还是content-box对应的是IE了!(菜鸟搜了一下,border-box对应的IE)
更多见我的博客:
盒子模型(一):初识盒模型 、 边框 [第四天]
重学前端 样式(text-align)/ 详解表格table(重点:继承/ border-spacing/collapse/ empty-cells/ box-sizing/ 合并行列 )(第四天)
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>
运行结果:
总结
其实里面的元素浮动不浮动只对margin的auto使用有影响,对其他的没有什么影响!
- 设为Flex布局以后,子元素的float、clear和vertical-align属性将失效!
- 定位也是让子元素脱离文档流,所以float只是提前一步而已!
边栏推荐
- Event express | Apache Doris Performance Optimization Practice Series live broadcast course is open at the beginning. You are cordially invited to participate!
- 振弦采集模块测量振弦传感器的流程步骤?
- samba服务器如何配置
- 一次失败的破解经历
- String (3)
- Using SYSTEMd to manage services
- 编码器高速脉冲计数器Modbus RTU模块IBF150
- The advanced path of programmers
- Return the two subscripts of the array according to the input target.
- 0-75mv/0-100mv to rs485/232 communication interface Modbus RTU acquisition module ibf8
猜你喜欢

语音社交系统——完善有声系统产业链

射频模块无线收发RF63U芯片应用数据传输和基建网络

Summarize the knowledge points of the ten JVM modules. If you don't believe it, you still don't understand it

PXE network installation
![[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

Docker容器实现MySQL主从复制

Docker实现Redis Cluster(集群)模式 哈希槽分区进行亿级数据存储

Using SYSTEMd to manage services

软件架构与设计(六)-----层次结构体

虚拟机之NAT模式下设置静态IP
随机推荐
Data real-time feedback technology
记:数值向上取整十,整百,整千,整万
Software architecture and design (IX) -- component based architecture
A failed cracking experience
The price war of off screen fingerprints has resumed, and second-line manufacturers are expected to win 30% of the market this year?
How as makes intelligent prompts regardless of case
如何有效进行回顾会议(上)?
[channel attention mechanism] senet
js 链表 02
Return the two subscripts of the array according to the input target.
热敏电阻PT100,NTC转0-10V/4-20mA转换器
monkey压力测试
软件架构与设计(五)-----以数据为中心的架构
0-75mv/0-100mv to rs485/232 communication interface Modbus RTU acquisition module ibf8
Multifunctional mixed signal AI acquisition / switching value di/do acquisition to rs485/232/modbus module
玩死原型链
电压转电流/电流转电压模块
Docker容器实现MySQL主从复制
28.55亿元!青岛芯恩增资完成:兴橙集电成第一大股东,持股57.10%
Voice social system -- improve the audio system industry chain