Php 为什么不同的HTML ID具有相同的样式?
我有两个具有不同ID的表,它们位于不同的页面中。单独来说,它们很好,但是当我将它们包含在一个页面中时,样式是重叠的,尽管HTML元素的ID是不同的。下面是我的代码:Php 为什么不同的HTML ID具有相同的样式?,php,html,css,Php,Html,Css,我有两个具有不同ID的表,它们位于不同的页面中。单独来说,它们很好,但是当我将它们包含在一个页面中时,样式是重叠的,尽管HTML元素的ID是不同的。下面是我的代码: <head> <rel="Stylesheet" href="CSS/styles.css"> </head> <body> <table id="logo" style="width:100%"> <th><img src="Image/v
<head>
<rel="Stylesheet" href="CSS/styles.css">
</head>
<body>
<table id="logo" style="width:100%">
<th><img src="Image/vg_logo.png" style="width:150px;height:100px"></th>
</table>
</body>
另一个元素代码是:
$query="select * from users order by id";
$result=mysqli_query($con,$query);
echo '<table id="userTable"><tr><th>User ID</th><th>Full Name</th><th>User Name</th><th>User Role</th></tr>';
while ($row=mysqli_fetch_array($result))
{
echo '<tr><td>'.$row['id'].'</td><td>'.$row['userFullName'].'</td><td>'.$row['userName'].'</td><td>'.$row['type'].'</td></tr>';
}
echo '</table>';
现在的问题是,每当我将第一页和第二页合并在一起时,第一个表就会有一个边框。我在这里设置了
边框:none
,为什么会发生这种情况?更改css中的这一行:
#userTable, th, td{
到
因为您已为所有
和td
元素指定了全局样式,所以请使用选择器指定特定样式。。它还为th
元素添加了边框,这就是为什么您的#logo表似乎有边框,因为其中有一个th
元素 @标记是正确的。只是为了一个提示
th{
background-color: #a1aec4;
}
同时使用选择器,否则所有th将获得相同的颜色 您是否仔细检查了输出HTML的有效性?这通常是一个好的开始。您可能在未意识到的情况下重复使用了ID。请不要使用答案来留下评论
#userTable, th, td{
#userTable, #userTable th, #userTable td{
th{
background-color: #a1aec4;
}