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

HTML页面中p标签CSS样式无法生效的问题排查与解决

CSS外部样式无法作用于p标签,仅内联样式生效的问题解决

我遇到一个问题:外部CSS无法修改页面中p标签的样式,但页面其他元素的CSS样式都能正常生效,且确认没有冲突代码。

相关代码

HTML代码

<body>
  <h1>Versioni Mago Dei Clienti</h1>
  <form class="form" method="post" action="">
        <label for="nome_cliente">Nome cliente:</label>
        <input type="text" id="nome_cliente" name="nome_cliente"><br><br>
        <label for="versione_mago">Versione Mago:</label>
        <input type="text" id="versione_mago" name="versione_mago"><br><br>
        <input type="submit" name="submit" value="Estrai dati">
  </form>
  <div>
    <table>
      <p style="color: red;">Per cercare una versione specifica, usare gli id sotto riportati</p>
      <tr><td>ID Mago</td><td>Versione</td></tr>
      <tr><td>1</td><td>3.3</td></tr>
      <tr><td>2</td><td>3.3.0.HF2</td></tr>
      <tr><td>3</td><td>3.4</td></tr>
      <tr><td>4</td><td>3.4.1</td></tr>
      <tr><td>5</td><td>3.5</td></tr>
      <tr><td>6</td><td>3.5.1</td></tr>
      <tr><td>7</td><td>3.6</td></tr>
      <tr><td>8</td><td>3.6.1</td></tr>
      <tr><td>9</td><td>4.0</td></tr>
      <tr><td>10</td><td>4.0.0.HF2</td></tr>
      <tr><td>11</td><td>4.0.1</td></tr>
      <tr><td>12</td><td>4.1</td></tr>
    </table>
  </div>
    <hr>
      <?php
        // includi il file data.php
        include '../assets/codice.php';
      ?>
</body>
</html>

CSS代码(style.css)

table, th, td {
  border: 1px solid black;
  border-collapse: collapse;
  padding: 10px;
  text-align: center;
  margin: auto;
  margin-top: 20px;
}

th {
  background-color: lightgrey;
}
h1{
  text-align: center;
  font-style: italic;
  color: darkgoldenrod;
}
.form{
  margin: 0 auto;
  width: fit-content;
  height: 100px;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #f8f8f8;
  border-radius: 10px;
  box-shadow: 0px 2px 2px rgba(0, 0, 0, 0.3);
  padding: 20px;
}

label {
  display: block;
  margin-bottom: 8px;
}

input[type="text"],
textarea {
  border-radius: 5px;
  border: none;
  box-shadow: inset 0px 2px 2px rgba(0, 0, 0, 0.1);
  padding: 10px;
  width: 100%;
  margin-bottom: 20px;
}

input[type="submit"] {
  background-color: #4CAF50;
  border: none;
  border-radius: 5px;
  color: white;
  padding: 10px 20px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
  margin-bottom: 20px;
  cursor: pointer;
}

input[type="submit"]:hover {
  background-color: #3e8e41;
}

body{
  background-color: rgba(229, 209, 234, 0.585);
}
p{
  color: red;
}

已尝试的操作

  • 将p{color: red;}代码移至CSS文件顶部,无变化;
  • 为p标签添加class并设置对应CSS样式,仍无效果;
  • 仅当使用内联style="color: red;"时,p标签样式才生效。

问题解决

清理浏览器缓存后,p标签的外部CSS样式正常生效。

内容的提问来源于stack exchange,提问作者Alessandro-Techtion

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.23 06:35:10