header.php:
<div class="div1">
<!-- Header content -->
</div>
<style>
.div1 {
/* Styles for div1 in the header */
}
</style>
footer.php:
<div class="div1">
<!-- Footer content -->
</div>
<style>
.div1 {
/* Styles for div1 in the footer */
}
</style>
index.php:
<?php include 'header.php'; ?>
<?php include 'footer.php'; ?>
当我将PHP代码段放在index.php中时,因为它们具有相同的类名,所以样式会相互影响。我想保持相同的名称,但没有风格相互影响。有什么方法可以实现这一点或唯一的方法,它改变的名称?
- 请我想要完全相同的类名不. header-div 1和. footer-div 1. OR .header. div 1和.footer. div 1 *
1条答案
按热度按时间ijxebb2r1#
在使用相同类名的同时应用不同样式的唯一方法是增加选择器的特异性。这可以通过使用包含元素类型的选择器或包含元素上的两个类的选择器来完成。