gpt4 book ai didi

php - html 元素变得奇怪。 (当包含在索引文件中时,按钮元素的尺寸会更改为原始 Bootstrap 组件)

转载 作者:太空宇宙 更新时间:2023-11-04 06:33:58 25 4
gpt4 key购买 nike

我正在制作一些 php 页面:file_header.php、file_footer.php、file_index.php,我将它们一一加载到浏览器中,结果很好(如我所愿)。但是,当我在 file_index.php 中组合 file_header.php 和 file_footer.php 时,问题就出现了。

这是问题所在:页面 file_header.php 中有两个按钮(这些是 Bootstrap 按钮),我为它们提供了自定义样式,我希望按钮看起来很 slim ,所以我在 css 中提供了 margin 和 padding 属性样式,最后我在浏览器中正常加载 file_header.php(结果很好/如我所愿)。但是,当我在 file_index.php 中组合 file_header.php 和 file_footer.php 时,这两个按钮变成了原始的 Bootstrap 按钮(按钮看起来很胖)。

为什么会这样?

            <!-- This is file_header.php -->
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">

<title>Hello, world!</title>

<style>
.navbar{
background-color: #563d7c
}

.btn{
margin: 5px;
padding: 2px 50px;
}
</style>

</head>
<body>

<nav class="navbar navbar-expand-lg navbar-dark">
<div class="container">
<div class="collapse navbar-collapse" id="navbarNav">
<div class="navbar-nav ml-auto">
<button href="#" class="btn btn-outline-light">Login</button>
<button href="#" class="btn btn-outline-light active">Sign Up</button>
</div>
</div>
</div>
</nav>

</body>
</html>


<!-- This is file_footer.php -->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">

<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">

<title>Page Title</title>

<style>
footer{
background-color: #f4f4f4;
}
.container{
padding: 20px;
}
</style>

</head>
<body>

<footer>
<div class="container">
<div class="row">
<div class="col d-flex justify-content-center">
<div class="row">
<div class="col">
<h5 class="text-muted">Service</h5>
<div class="row">
<div class="col">
<p><a href="#" class="text-muted">About Us</a></p>
</div>
</div>
</div>
</div>
</div>
<div class="col d-flex justify-content-center">
<div class="row">
<div class="col">
<h5 class="text-muted">Success Story</h5>
<div class="row">
<div class="col">
<p><a href="#" class="text-muted">Let Me See</a></p>
</div>
</div>
</div>
</div>
</div>
<div class="col d-flex justify-content-center">
<div class="row">
<div class="col">
<h5 class="text-muted">Help</h5>
<div class="row">
<div class="col">
<p><a href="#" class="text-muted">Terms and Condition</a></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</footer>

</body>
</html>


<!-- This is file_index.php -->
<!DOCTYPE html>
<html>
<head>

<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">

</head>
<body>

<?php include 'file_header.php' ?>
<div>
<h2>My main content is here</h2>
<h2>My main content is here</h2>
<h2>My main content is here</h2>
<h2>My main content is here</h2>
<h2>My main content is here</h2>
<h2>My main content is here</h2>
</div>
<?php include 'file_footer.php' ?>

</body>
</html>

我希望页面 file_index.php 中每个按钮元素的样式都很好(按钮看起来很 slim /如我所愿)。

我希望每个页面的样式(file_header、file_footer、file_index)都不会改变

最佳答案

当您在索引文件中组合页眉、主体和页脚时,您需要确保所有内容都只包含一次。含义、文档类型、样式、开始正文标签等。所以,我会稍微调整一下你的代码,你的“file_header”应该包含 <head> 中的所有内容。 ,我会在导航代码所在的位置创建一个单独的“file_nav.php”,从“file_footer”中删除所有包装内容,只留下页脚代码。有点像这样:

<!-- This is file_header.php -->
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">

<title>Hello, world!</title>

<style>
.navbar{
background-color: #563d7c
}

.btn{
margin: 5px;
padding: 2px 50px;
}

footer{
background-color: #f4f4f4;
}
.container{
padding: 20px;
}
</style>
</head>

<!-- This is file_nav.php -->
<nav class="navbar navbar-expand-lg navbar-dark">
<div class="container">
<div class="collapse navbar-collapse" id="navbarNav">
<div class="navbar-nav ml-auto">
<button href="#" class="btn btn-outline-light">Login</button>
<button href="#" class="btn btn-outline-light active">Sign Up</button>
</div>
</div>
</div>
</nav>

<!-- This is file_footer.php -->
<footer>
<div class="container">
<div class="row">
<div class="col d-flex justify-content-center">
<div class="row">
<div class="col">
<h5 class="text-muted">Service</h5>
<div class="row">
<div class="col">
<p><a href="#" class="text-muted">About Us</a></p>
</div>
</div>
</div>
</div>
</div>
<div class="col d-flex justify-content-center">
<div class="row">
<div class="col">
<h5 class="text-muted">Success Story</h5>
<div class="row">
<div class="col">
<p><a href="#" class="text-muted">Let Me See</a></p>
</div>
</div>
</div>
</div>
</div>
<div class="col d-flex justify-content-center">
<div class="row">
<div class="col">
<h5 class="text-muted">Help</h5>
<div class="row">
<div class="col">
<p><a href="#" class="text-muted">Terms and Condition</a></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</footer>

<!-- This is file_index.php -->
<!doctype html>
<html lang="en">
<?php include 'file_header.php' ?>
<body>
<?php include 'file_nav.php' ?>
<div>
<h2>My main content is here</h2>
<h2>My main content is here</h2>
<h2>My main content is here</h2>
<h2>My main content is here</h2>
<h2>My main content is here</h2>
<h2>My main content is here</h2>
</div>
<?php include 'file_footer.php' ?>
</body>
</html>

关于php - html 元素变得奇怪。 (当包含在索引文件中时,按钮元素的尺寸会更改为原始 Bootstrap 组件),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54396764/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com