ฉันได้สร้าง ไฟล์ส่วนหัว แยกต่างหากใน php เพื่อให้สามารถนำมาใช้ซ้ำได้ในทุกหน้าโดยรวมไว้ใน ฟังก์ชัน php include แต่ใน หน้าส่วนหัว เมื่อฉันเขียนโค้ดของ navbar แบบง่าย มันแสดงในรายการและไม่ใช่แบบอินไลน์
(คำถามนี้ไม่เหมือนกันทุกประการกับคำถามอื่น ๆ ที่มีบางคนทำเครื่องหมายว่าซ้ำกัน ฉันได้ถามคำถามต่าง ๆ เพื่อค้นหาปัญหาของฉัน แต่ไม่พบเลย ฉันจึงถามคำถามนี้ด้วยตัวเอง)
นี่คือรหัสของฉัน:
index.php (หน้าดัชนีหลัก)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" href="/thimg/favicon.ico">
<link rel="stylesheet" href="/thcss/index.css">
<link rel="stylesheet" href="/thcss/bootstrap.min.css">
<link rel="stylesheet" href="/thcss/fontawesome-all.min.css">
</head>
<body>
<?php include 'header.php'; ?>
<div>
</div>
<?php include 'footer.php'; ?>
<script src="js/jquery-3.3.1.min.js"></script>
<script src="js/bootstrap.bundle.min.js"></script>
<script type="text/javascript" src="http://www.google-analytics.com/ga.js"></script>
</body>
</html>
header.php (หน้าส่วนหัวที่ฉันกำลังสร้าง bootstrap navbar)
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="/thindex.php">O.S.P</a>
</div>
<ul class="nav navbar-nav">
<li class="active"><a href="/thindex.php">Home</a></li>
<li><a href="/thservices.php">Services</a></li>
<li><a href="/thabout-us.php">About Us</a></li>
<li><a href="/thsign-in.php">Sign In</a></li>
<li><a href="/thsign-up.php">Sign Up</a></li>
</ul>
</div>
</nav>
และนี่คือ index.css (ไฟล์ CSS รอง)
.nav li{
display: inline;
}
ท้ายที่สุดเมื่อฉันเปิดเพจของฉันมันจะแสดงดังนี้:
รูปภาพเอาต์พุตของเบราว์เซอร์ของหน้าของฉัน: