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

为什么我的CSS不再对HTML生效?文本无法居中问题求排查

问题排查与修复方案

  • 核心错误1:你的CSS代码末尾存在多余的}语法错误,会直接导致浏览器解析CSS中断,是CSS突然失效的主要原因。
  • 核心错误2:table仅设置了左右margin为auto,但未指定宽度,块级元素无明确宽度时margin: auto的居中逻辑无法生效。

修正后的完整CSS代码

* {
  margin: 0;
  padding: 0;
  font-family: 'Noto Sans', sans-serif;
  overflow-x: hidden;
}

.sub-header {
  height: 50vh;
  width: 100%;
  background-image: linear-gradient(rgba(4, 9, 30, 0.7), rgba(4, 9, 30, 0.7)), url(assets/contact-sub.jpg);
  background-position: center;
  background-size: cover;
  text-align: center;
  color: #fff;
}

.sub-header h1 {
  margin-top: 50px;
}

.contact {
  width: 80%;
  margin: auto;
  padding-top: 50px;
  padding-bottom: 50px;
}

.reachme {
  width: 80%;
  margin: auto;
  padding-top: 80px;
  text-align: center;
}

.center {
  padding-top: 25px;
  margin-left: auto;
  margin-right: auto;
  width: fit-content;
}

table {
  border-spacing: 10px;
}

td {
  width: 110px;
  text-align: center;
  vertical-align: middle;
}

.hours {
  color: #808080;
  font-size: 14px;
  text-align: center;
  width: 80%;
  margin: auto;
  padding-top: 30px;
}

@media(max-width: 700px) {
  .sub-header {
    height: 35vh!important;
  }
  .reachme {
    padding-top: 30px;
  }
}

操作说明

原有HTML代码无需修改,直接替换CSS即可生效,修改后请清空浏览器缓存再刷新页面,避免本地缓存的旧CSS影响效果。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.30 02:06:05