一、Float:left;
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>设置div不换行显示</title>
<style>
.one {
float: left;
}
.two{
float: left;
}
</style>
</head>
<body>
<div class="one">One</div>
<div class="two">Two</div>
</body>
</html>
二、Display:inline-block;
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>设置div不换行显示</title>
<style>
/* .one {
float: left;
}
.two{
float: left;
}*/
.one{
display: inline-block;
}
.two{
display: inline-block;
}
</style>
</head>
<body>
<div class="one">One</div>
<div class="two">Two</div>
</body>
</html>
三、Display:flex;
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>设置div不换行显示</title>
<style>
/* .one {
float: left;
}
.two{
float: left;
}*/
/* .one{
display: inline-block;
}
.two{
display: inline-block;
}*/
.parent{
display: flex;
}
</style>
</head>
<body>
<div class="parent">
<div class="one">One</div>
<div class="two">Two</div>
</div>
</body>
</html>