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

如何正确对齐布局中LI内文本与DIV容器内的图片

问题修复方案

核心问题原因

  • 通配符*全局设置width: 890px,强制所有元素宽度为890px,直接破坏子元素的排列逻辑
  • 两列布局属性使用错误:column-span: 2是多列布局下子元素跨列的属性,不能给父容器设置实现两列效果
  • 子元素宽度不匹配:.price设置宽度550px,远大于父级li的400px宽度,导致文本溢出截断
  • 缺少文本换行规则,长文本无法自动折行
  • 浮动布局缺少配套规则,.descript1只设置左浮动,没有定义宽度和清除浮动逻辑,导致排列错位

修复后代码

CSS部分

a {
  text-decoration: none;
}
header{
  margin: 0; padding: 2em 5em 4em; color: #efefef;
  overflow:hidden;
  position: relative;
}
header::after{
  content:"";
  position:absolute;
  top:0;
  left:0;
  height: 100%;
  width:100%;
  transform: skewY(-3deg);
  background: red;
  transform-origin: bottom left;
  z-index: -1;
}
div.content {
  font-family: sans-serif;
  font-size: 16px;
  width: 460px;
}
ul.vehicleinfo {
  display: flex;
  flex-wrap: wrap;
  width: 760px;
  list-style: none;
  padding: 0;
  margin: 0 0 20px 0;
  justify-content: space-between;
}
ul.vehicleinfo li { 
  font-family: sans-serif;
  font-size: 88%;
  color: #333;
  background-color: yellow;
  width: 48%;
  margin: 0 0 20px 0;
  word-wrap: break-word;
  word-break: break-all;
}
ul.vehicleinfo li * {
  display: block;
}
ul.vehicleinfo li h3 {
  font-size: 1.2em;
  margin: 0;
  padding: 8px;
}
div.autocontent {
  width: 760px;
  margin: 0 auto;
}
.price {
  text-align: center;
}
.contentbox1 {
  display: flex;
  gap: 30px;
  align-items: flex-start;
}
.autoimg img {
  width: 340px;
  display: block;
}
.descript1 {
  font-size: 14px;
  flex: 1;
}

HTML部分和原有代码一致,无需修改

实现效果

  • 车辆标题和价格自动在一行左右对齐排列,长文本自动换行不会溢出
  • 图片和描述文本自动并排显示,适配容器宽度
  • 所有元素在autocontent容器内均匀对齐,没有错位和截断问题

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.03 04:54:05