Html 当屏幕尺寸较小时,使两个div堆叠
当屏幕大小为div时,相邻的两个div应该堆叠在一起{ 显示:内联块; 宽度:49%; }Html 当屏幕尺寸较小时,使两个div堆叠,html,css,Html,Css,当屏幕大小为div时,相邻的两个div应该堆叠在一起{ 显示:内联块; 宽度:49%; } 名字 姓 使用FlexBox,然后更改所述媒体查询的弹性方向: <!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <meta name="viewport" cont
名字
姓
使用FlexBox,然后更改所述媒体查询的弹性方向
:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<style>
.container {
display: flex;
}
.box {
margin: 1%;
padding: 1%;
flex-basis: 46%;
}
@media screen and (max-width: 769px) {
.container {
flex-direction: column;
}
}
</style>
<body>
<main class="container">
<div class="box" style="background: red">
<p>hello</p>
</div>
<div class="box" style="background: blue">
<p>world</p>
</div>
</main>
</body>
</html>
.集装箱{
显示器:flex;
}
.盒子{
利润率:1%;
填充:1%;
弹性基准:46%;
}
@媒体屏幕和屏幕(最大宽度:769px){
.集装箱{
弯曲方向:立柱;
}
}
你好
世界
使用FlexBox,然后更改所述媒体查询的弹性方向
:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<style>
.container {
display: flex;
}
.box {
margin: 1%;
padding: 1%;
flex-basis: 46%;
}
@media screen and (max-width: 769px) {
.container {
flex-direction: column;
}
}
</style>
<body>
<main class="container">
<div class="box" style="background: red">
<p>hello</p>
</div>
<div class="box" style="background: blue">
<p>world</p>
</div>
</main>
</body>
</html>
.集装箱{
显示器:flex;
}
.盒子{
利润率:1%;
填充:1%;
弹性基准:46%;
}
@媒体屏幕和屏幕(最大宽度:769px){
.集装箱{
弯曲方向:立柱;
}
}
你好
世界
您选择了错误的元素
您可以使用最小宽度的媒体查询来减少CSS
@媒体屏幕和(最小宽度:768px){
#名称>分区{
浮动:左;
宽度:50%
}
}
名字
姓
您选择了错误的元素
您可以使用最小宽度的媒体查询来减少CSS
@媒体屏幕和(最小宽度:768px){
#名称>分区{
浮动:左;
宽度:50%
}
}
名字
姓
这里有一个替代设置,利用显示:内联块和更改宽度:
CSS
#name > div {
display:inline-block;
width:49%;
}
@media screen and (max-width: 768px) {
#name > div {
width: 100%;
}
}
HMTL
<div id="name">
<div>
<div class="input">
<label for="first-name">First name</label>
<input autocomplete="on" class='inp_cont' id="first-name" name="last-name" placeholder="Enter your first name" required="" type="text">
</div>
</div><div>
<div class="input">
<label for="last-name">Last name</label>
<input autocomplete="on" class='inp_cont' id="last-name" name="last-name" placeholder="Enter your last name" required="" type="text">
</div>
</div>
</div>
名字
姓
请注意,在这个HTML的第7行,一个div的结束标记直接位于另一个div的开始标记旁边。这不是一个错误,display:inline block
必须正常工作,否则空格将导致元素不能并排显示 这里有一个替代设置,利用显示:内联块
和更改宽度:
CSS
#name > div {
display:inline-block;
width:49%;
}
@media screen and (max-width: 768px) {
#name > div {
width: 100%;
}
}
HMTL
<div id="name">
<div>
<div class="input">
<label for="first-name">First name</label>
<input autocomplete="on" class='inp_cont' id="first-name" name="last-name" placeholder="Enter your first name" required="" type="text">
</div>
</div><div>
<div class="input">
<label for="last-name">Last name</label>
<input autocomplete="on" class='inp_cont' id="last-name" name="last-name" placeholder="Enter your last name" required="" type="text">
</div>
</div>
</div>
名字
姓
请注意,在这个HTML的第7行,一个div的结束标记直接位于另一个div的开始标记旁边。这不是一个错误,display:inline block
必须正常工作,否则空格将导致元素不能并排显示