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

表单添加PHP代码后CSS样式失效问题求助

表单添加PHP代码后样式异常问题

未添加PHP代码时,表单样式显示正常;添加以下代码后,表单样式出现异常,部分CSS逻辑虽仍生效,但样式问题依旧存在。

添加的代码如下:

<div class="col-lg-4 col-md-6 col-sm-12">
    <label for="">Distributor Price</label>
    <input type="text" name="DisPrice" placeholder="Distributor Price" class="form-control" required>
</div>
<div class="col-lg-4 col-md-12 col-sm-12">
    <label for="">Brand Name</label>
    <select name="car_id" id="car_id" class="form-control-label" >
    <?php
    $list = mysqli_query($conn, "SELECT * FROM `vehicle_registration` where `status`='0'");
    while ($row_ah = mysqli_fetch_assoc($list)) {
    ?>
        <option value="<?php echo $row_ah['id']; ?>"><?php echo $row_ah['car_no']; ?></option>
    <?php } ?>
    </select>
</div>
<div class="col-lg-6 col-md-6 col-sm-12">
    <label for="">Description (use for ||| new Line)</label>
    <textarea name="Description" class="form-control" id="" cols="30" rows="10"></textarea>
</div>

可能的解决方向

  • 修正select的样式类:代码中下拉框select用了form-control-label类,这个类是给<label>标签用的,表单控件应该匹配输入框、文本域的form-control类,把select的class改成form-control即可。
  • 调整栅格列宽总和:Bootstrap栅格每行总宽度为12,当前前两列是col-lg-4 + col-lg-4 = 8,第三列是col-lg-6,总和14超出限制,会导致布局错乱。可以改成前两列col-lg-3、第三列col-lg-6,或者前两列col-lg-4、第三列col-lg-4,保证总和为12。
  • 排查PHP输出异常:如果数据库查询出错,mysqli可能输出错误信息破坏HTML结构。可以在查询后加错误检查:
    $list = mysqli_query($conn, "SELECT * FROM `vehicle_registration` where `status`='0'");
    if (!$list) {
        die('数据库查询错误: ' . mysqli_error($conn));
    }
    
    确认是否有额外输出影响页面结构。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.08 11:01:36