inline-block:表现为行内样式,但是可以设置宽高
<!DOCTYPE html>
<html>
<title>CSS inline-block</title>
<style>
body {
text-align: center;
font-size: 28px;
}
h1 {
color: green;
}
</style>
<body>
A Online
<div style="display:inline-block; background-color:yellow; width:auto; height:auto">
<div style="display:inline; background-color:purple;">Computer</div>
<div style="display:inline; background-color:orange;">Science</div>
<div style="display:inline; background-color:cyan;">Portal</div>
</div>
for Geeks</body>
</html>
inline-flex: 令设置了flex的container display为 inline,而不是设置里面的item为inline
The main difference between display: flex and display: inline-flex is that display: inline-flex will make the flex container an inline element while its content maintains its flexbox properties.
<!DOCTYPE html>
<html>
<title>CSS inline-block</title>
<style>
body {
text-align: center;
font-size: 28px;
}
h1 {
color: green;
}
</style>
<body>
A Online
<div style="display:inline-flex; background-color:yellow; width:auto; height:auto">
<div style="display:inline; background-color:purple;">Computer</div>
<div style="display:inline; background-color:orange;">Science</div>
<div style="display:inline; background-color:cyan;">Portal</div>
</div>
for Geeks</body>
</html>
There is only one main difference between the inline-block and inline-flex:
inline-block: Create specific block for each element under its section maintain the structure of each element. (item之间有间隙)
inline-flex: Does not reserved any specific space in normal form. (item之间无间隙)