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

如何使用jQuery修改模态框(Modal)主体内容的文字大小

问题描述

通过jQuery加载数据的模态框,无法修改.modal-body内的文字大小。当前CSS仅能改变文字颜色,字体大小设置无效:

.modal-body{
  font-family: Arial, Helvetica, sans-serif;
  color: red;
  font-size: 26px;
}

模态框结构:

<div class="modal" tabindex="-1" id="modal_feedback">
  <div class="modal-dialog modal-dialog-centered modal-lg">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title">IM Enhancement Request Form</h5>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
      <div class="modal-body">
        <?!= include('Index_Feedback') ?>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
        <input type="button" class="btn btn-success btn-send pt-2 btn-block" value="Submit Request" onclick="triggerSubmit()">
      </div>
    </div>
  </div>
</div>
解决方案

问题核心是.modal-body的样式优先级不足——引入的Index_Feedback文件内的元素(如<p>、<label>、表单控件等)自带Bootstrap或浏览器默认字体大小样式,优先级高于父容器的继承样式。可通过以下方式解决:

方法1:提升选择器优先级

给选择器添加模态框ID,增强样式权重:

#modal_feedback .modal-body{
  font-family: Arial, Helvetica, sans-serif;
  color: red;
  font-size: 26px;
}

方法2:覆盖所有子元素样式

直接给.modal-body下的所有子元素设置字体大小,确保覆盖内部所有元素的默认样式:

.modal-body{
  font-family: Arial, Helvetica, sans-serif;
  color: red;
}
.modal-body * {
  font-size: 26px;
}

若仍无效,可在font-size后添加!important强制生效(仅应急使用,不推荐长期依赖)。

方法3:精准指定目标元素

如果清楚Index_Feedback内的具体标签类型,可针对性设置:

.modal-body{
  font-family: Arial, Helvetica, sans-serif;
  color: red;
}
.modal-body p, .modal-body label, .modal-body input {
  font-size: 26px;
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.19 21:40:16