html - My margin for bottom right items inside flexbox doesn't work
问题描述
<!DOCTYPE html>
<html>
<header>
<title>Welcome to Meme facts website </title>
<h1 style="text-align: center"> MEMES MENU </h1>
</header>
<body>
<div class="container">
<div class="flex-box">
<div class="topleft"></div>
<div class="topright"></div>
</div> <br> <br> <br>
<div class="flex-box" style="background-color: white">
<div class="bottomleft"</div>
<div class="bottomright"</div>
</div>
</div>
</div>
</body>
</html>
CSS :
body {
background-repeat: no-repeat;
background-size: cover;
background-image: url("https://d2v9y0dukr6mq2.cloudfront.net/video/thumbnail/yRF5c-O/blue-side-bubbles-4k-and-full-hd_4p0cs3stx__F0000.png")
}
.container {
margin: auto;
padding: auto;
background-color: #666666 ;
width: 1200px;
height: 555px;
}
.flex-box {
margin: auto;
padding: auto;
width: 1000px;
height: 250px;
background-color: #ADADAD;
display: flex;
flex-warp: wrap;
}
.topleft {
flex: left;
background-color: white;
height: 250px;
width: 250px;
}
.topright {
background-color: black;
height: 250px;
width: 250px;
margin-left: auto;
text-align: right;
}
.bottomleft {
background-color: red;
height: 250px;
width: 250px;
}
.bottomright {
background-color: blue;
height: 250px;
width: 250px;
margin-left: auto;
text-align: right;
}
I tried with the other flexbox it worked fine, but with the 2nd one it doesn't work as the first box above, It seem like it being ignored, margin doesn't work either way.
it not moving to the right of the flexbox as it should on the upper flexbox, it stayed on the left and overlapping the other items.
解决方案
您的 HTML 不正确,您在课堂作业后忘记关闭第 17 行和第 18 行的 div 标签!
body {
background-repeat: no-repeat;
background-size: cover;
background-image: url("https://d2v9y0dukr6mq2.cloudfront.net/video/thumbnail/yRF5c-O/blue-side-bubbles-4k-and-full-hd_4p0cs3stx__F0000.png")
}
.container {
margin: auto;
padding: auto;
background-color: #666666 ;
width: 1200px;
height: 555px;
}
.flex-box {
margin: auto;
padding: auto;
width: 1000px;
height: 250px;
background-color: #ADADAD;
display: flex;
flex-warp: wrap;
}
.topleft {
background-color: white;
height: 250px;
width: 250px;
}
.topright {
background-color: black;
height: 250px;
width: 250px;
margin-left: auto;
text-align: right;
}
.bottomleft {
background-color: red;
height: 250px;
width: 250px;
}
.bottomright {
background-color: blue;
height: 250px;
width: 250px;
margin-left: auto;
text-align: right;
}
<!DOCTYPE html>
<html>
<header>
<title>Welcome to Meme facts website </title>
<h1 style="text-align: center"> MEMES MENU </h1>
</header>
<body>
<div class="container">
<div class="flex-box">
<div class="topleft"></div>
<div class="topright"></div>
</div> <br> <br> <br>
<div class="flex-box" style="background-color: white">
<div class="bottomleft"></div>
<div class="bottomright"></div>
</div>
</div>
</div>
</body>
</html>
推荐阅读
- apache-kafka - Avro 模式的 Quarkus 类自动生成机制不起作用
- google-cloud-platform - 在 Web 服务器上压缩图像并返回 url
- spring - Spring Boot Batch - 从数据库读取数据但不想将元数据写入数据库
- wpf - 如何获取 TreeViewItem 的 ContextMenu,将 TreeView 作为 DataTemplate
- r - 打破ggplot2连续尺度中唯一值的一般方法
- javascript - 关于转换的简单问题(新编码器)
- nunjucks - 检查 Nunjucks 中的字符串是否为空?
- javascript - React 无法读取未定义的属性“”
- amazon-web-services - AWS DMS 服务出现问题,您能帮我解决此错误“测试端点失败:应用程序状态:1020912...”吗?
- python - 使用 SQLAlchemy 对单个表进行多个 group_by 计数