You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

关于实现两列居中布局及多屏幕响应式适配的技术求助

解决布局居中与响应式适配问题

我看了你的代码和需求,发现当前布局的核心问题在于没有充分利用Flex布局实现真正的居中,以及缺少针对小屏幕的响应式规则。下面是调整后的完整代码,同时我会拆解关键改动点:

关键改动说明

  • 重构了列表容器的布局,使用Flex实现水平居中+自动换行,适配不同屏幕宽度
  • 优化了每个图标项的内部结构,确保图标和文字垂直对齐
  • 调整Bootstrap列的响应式规则,小屏幕下单栏显示,中等及以上屏幕双栏
  • 优化了文字区域的样式,确保小屏幕下文字不会溢出,自动调整布局

修改后的CSS

.content-wrapper { min-height: 926px; background-color: #d9dde2; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { -webkit-box-shadow: inset 0 0 4px rgba(0, 0, 0, 0.3); background: #fff; }
::-webkit-scrollbar-thumb { background: #f89b0f; -webkit-box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.5); }
::-webkit-scrollbar-thumb:window-inactive { background: #f89b0f; }
a { color: #f39c12; }
.content-header>.breadcrumb { background: #f89b0f; right: 25px; border-radius: 25px; color: #fff; padding: 10px; }
.modal-dialog { z-index: 1200; }
.solid-header-default { background: #f0f0f0; }
.solid-header-success { background: #00a65a; }
h2 { font-size: 18px; }
.gcircle { height: 50px; width: 50px; background-color: #938005; border-radius: 50%; display: inline-block; }
.circle-block { text-align: center; vertical-align: middle; }
.circle { 
  background: red; 
  border-radius: 50%; 
  color: white; 
  display: inline-flex; /* 用flex实现内部图标居中 */
  align-items: center; 
  justify-content: center;
  height: 50px; 
  font-weight: bold; 
  font-size: 1.2em; 
  width: 50px; 
  margin: 10px; 
}
.circle.circle-navy { background: #938005 !important; }
.circle.circle-blue { background: #01205F !important; }
.circle.circle-red { background: #C00000 !important; }
.circle.circle-pink { background: #7030A1 !important; }
.circle.circle-green { background: #44AA20 !important; }
.circle.circle-yellow { background: #FFC100 !important; }
.circle.circle-light-blue { background: #0F70D7 !important; }
.circle.circle-black { background: #151515 !important; }
.cchart { 
  text-align: center; 
  padding: 5px; 
  min-width: 100px; /* 确保文字区域有最小宽度 */
  font-size: 0.9rem; /* 小屏幕下字体缩小 */ 
}
.brandlogo-image { float: left; line-height: .8; margin-left: .8rem; margin-right: .5rem; margin-top: -6px; max-height: 34px; width: auto; }
/* 重构列表容器布局 */
.center-me { 
  display: flex; 
  flex-wrap: wrap; 
  justify-content: center; 
  align-items: center;
  padding-left: 0; /* 移除默认ul内边距 */
  margin: 0 auto;
}
.circle-li { 
  list-style-type: none; 
  display: flex;
  flex-direction: column; /* 图标在上,文字在下 */
  align-items: center;
  margin: 15px 10px; /* 增加项之间的间距 */
}

修改后的HTML

<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row">
  <!-- 调整响应式列:小屏幕占满宽度,中等屏幕分栏 -->
  <div class="col-12 col-md-6" style="background: #fff; min-height:926px; display: flex; align-items: center;">
    <div class="w-100"> <!-- 确保内容容器占满宽度 -->
      <ul class="center-me">
        <li class="circle-li">
          <span class="circle circle-navy"><i class="fa fa-video-camera"></i></span>
          <div class="cchart">
            <b>WEBCAMS</b>
            <div>Hold Visual Meetings</div>
          </div>
        </li>
        <li class="circle-li">
          <span class="circle circle-blue"><i class="fa fa-video-camera"></i></span>
          <div class="cchart">
            <b>WEBCAMS</b>
            <div>Hold Visual Meetings</div>
          </div>
        </li>
        <li class="circle-li">
          <span class="circle circle-navy"><i class="fa fa-video-camera"></i></span>
          <div class="cchart">
            <b>WEBCAMS</b>
            <div>Hold Visual Meetings</div>
          </div>
        </li>
        <li class="circle-li">
          <span class="circle circle-blue"><i class="fa fa-video-camera"></i></span>
          <div class="cchart">
            <b>WEBCAMS</b>
            <div>Hold Visual Meetings</div>
          </div>
        </li>
        <li class="circle-li">
          <span class="circle circle-navy"><i class="fa fa-video-camera"></i></span>
          <div class="cchart">
            <b>WEBCAMS</b>
            <div>Hold Visual Meetings</div>
          </div>
        </li>
        <li class="circle-li">
          <span class="circle circle-blue"><i class="fa fa-video-camera"></i></span>
          <div class="cchart">
            <b>WEBCAMS</b>
            <div>Hold Visual Meetings</div>
          </div>
        </li>
        <li class="circle-li">
          <span class="circle circle-navy"><i class="fa fa-video-camera"></i></span>
          <div class="cchart">
            <b>WEBCAMS</b>
            <div>Hold Visual Meetings</div>
          </div>
        </li>
        <li class="circle-li">
          <span class="circle circle-blue"><i class="fa fa-video-camera"></i></span>
          <div class="cchart">
            <b>WEBCAMS</b>
            <div>Hold Visual Meetings</div>
          </div>
        </li>
      </ul>
    </div>
  </div>
  <!-- 右侧列同样调整响应式 -->
  <div class="col-12 col-md-6" style="background: #F99B10; min-height:926px">
  </div>
</div>

这样调整后,布局会在所有屏幕尺寸下保持居中,小屏幕时图标项会自动换行,不会出现挤在一起的情况,同时每个图标和文字的对齐也更加规整。

内容的提问来源于stack exchange,提问作者vishal panchal

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.07 18:22:53