我有一个名为 NEW 的页面,上面有一个 from,在它的顶部我包括一个包含我的样式的外部页面。我链接到这个页面上的样式的方式与我在另一个页面上做的一样,但是由于某种原因,即使我在不同的页面上使用完全相同的路由,这个页面上的样式也没有应用。这里会发生什么?
样式正常工作的页面:
<% layout('partials/layout') -%>
<h1 class="heading">Pet Gallery!</h1>
<div class="blog-home2 spacer">
<div class="container gallery-container">
<div class="row m-t-40">
<% posts.forEach(function(post) { %>
<div class="col-md-4">
<div class="card" data-aos="flip-left" data-aos-duration="1200">
<!-- spot where image should go -->
<h1><%=post.name %></h1>
<span><%=post.fee %></span>
<span><%=post.description %></span>
<span><%= post.location%></span>
<div><a href="/gallery/pet/<%=post.id %>">View More</a></div>
</div>
</div>
<% }) %>
</div>
</div>
</div>
未应用样式的页面:
<% layout('partials/layout') -%>
<h1>New Pet</h1>
<form action="/gallery" method="POST" enctype="multipart/form-data">
<div>
<input type="text" name="post[name]" placeholder="Name">
</div>
<div>
<input type="text" name="post[fee]" placeholder="Rehoming Fee">
</div>
<div>
<textarea name="post[description]" placeholder="Description"></textarea>
</div>
<div>
<input type="text" name="post[location]"placeholder="Location">
</div>
<input type="file" accept='images/*' name="images" multiple>
</div>
<div>
<input type="submit">
</div>
[1]: /image/zjj7C.png
包含导航栏和样式链接的代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title><%= title %>></title>
<link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<script src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.47.0/mapbox-gl.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.47.0/mapbox-gl.css' rel='stylesheet' />
<link rel="stylesheet" href="stylesheets/post-show.css">
</head>
<body>
<% include ../partials/navbar %>
<% include ../partials/flash-message %>
<%-body -%>
</body>
</html>
最佳答案
<% layout('/partials/layout') -%>
有一个前导的正斜杠。这意味着浏览器将在域的顶级开始搜索。因此,如果您当前的目录是 http://example.com/pages/
:
/partials/layout
将在 http://example.com/partials/layout
中搜索
同时
partials/layout
将在 http://example.com/pages/partials/layout
中搜索
关于html - CSS 样式不适用于页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56999107/