html - Bootstrap 中的响应列,主列位于中心
问题描述
我想使用 Bootstrap 进行此配置
这需要像图像显示的那样响应。我尝试了此代码,但块 2 未在页面中居中
<div class="row" style="margin: 0 auto; width: 800px; margin-top: 20px; max-width:800px;position:relative" >
<div class="col" style="top:420px;background: white; z-index:100;position:fixed; width: 194px;">
block 1
</div>
<div class="col">
block 2
</div>
</div>
当我向上和向下滚动页面时,我还需要左侧的块 1 跟随
有什么建议么?
解决方案
您可以使用媒体查询来实现这一点,而无需任何引导程序。这是代码:
<html>
<head>
<style>
@media (max-width:850px){
.mycontainer{
display: flex;
flex-direction: column-reverse;
}
.myleft{
order: 1;
width: 97%;
margin-right: 1.5%;
margin-left: 1.5%;
background-color: white;
}
.mymain{
order: 2;
width: 97%;
margin-right: 1.5%;
margin-left: 1.5%;
background-color: white;
}
}
@media (min-width:850px){
.mycontainer{
display: flex;
flex-direction: row;
}
.myleft{
order: 1;
width: 30%;
margin-right: 2%;
margin-left: 2%;
background-color: white;
}
.mymain{
order: 2;
width: 60%;
margin-right: 2%;
padding-left: 2%;
background-color: white;
border-left: 1px solid #e9ecef;
}
}
</style>
</head>
<body>
<div class="mycontainer">
<div class="myleft">left column content</div>
<div class="mymain">my main content</div>
</div>
</body>
</html>
要使主列内容居中,您可以使用 css 对其进行样式设置。
推荐阅读
- salesforce - 当列中存在重复值时添加唯一索引
- python-3.x - 如何防止 QTableWidget 中没有选择?
- java - Ormlite 保存错误的日期,具体取决于一天中的时间
- python - 将xml转json结构后增加json中某个节点的值
- spring - DelegatingFilterProxy 如何知道调用哪个过滤器来委托 doFilter 调用?
- android - 如何根据用户是否发送消息来对齐 RecyclerView 中的消息
- kubernetes - 无法在 Mac 上启动 kubectl 仪表板
- angular - Angular 7- 自定义 Toastr - 找到合成属性 @flyInOut。在你的应用中包含 BrowserAnimationsModule
- android - Recyclerview 没有显示在 Fragment 中
- python - 设置 TensorBoard 以在 Google Colab 中为 TensorFlow 对象检测模型运行 eval.py 作业