CSS 应用到除一个页面之外的所有页面 - Ruby/Sinatra

CSS applied to all pages but one - Ruby/Sinatra

我正在使用 Sinatra 创建一个带有 Ruby 的简单 Web 应用程序,并且在修改视图时,CSS 应用于除一个文件之外的所有 .erb 文件。我不太确定是什么问题。我试过:

这是我的 layout.erb 文件

<br/>
<h2>Upload a Video</h2>
<br/>
<br/>
<form action="/create_video" method="POST">
  <div class="col-6">
    <label for="videoTitle">Video Title</label>
    <input type="text" class="form-control" aria-describedby="emailHelp" placeholder="Enter video title" name="title">
  </div>
  <br/>
  <div class="col-6">
    <label for="videoDescription">Video Description</label>
    <input type="text" class="form-control" placeholder="Enter video description" name="description">
  </div>
  <br/>
    <br/>
    <div class="col-6">
     <label for="videoURL">Video Link</label>
     <input type="text" class="form-control" placeholder="Enter link to video" name="l_url">
    </div>
    <br/>
    <div class="col-6">
     <label for="listingUrl">Company</label>
     <input type="text" class="form-control" placeholder="Enter company name" name="company">
    </div>
    <br/>
  &nbsp;&nbsp;<button type="submit" class="btn btn-primary">Submit</button>
</form>
<br/>
<br/>
</div>

我的 layout.erb 文件

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
    <link href="https://fonts.googleapis.com/css?family=Roboto:300|Niramit|Nunito" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="style.css">
    <link rel="stylesheet" type="text/css" href="animate.css">
</head>
<body>

    <%= erb :navigation %>

    <main role="main">

        <%= yield %>

    </main>


    <footer class="end">
         <div class="footer-grid">
      <div class="footer-one">
        <p> logo<p>
      </div>
        <div class="footer-two">
            <p>&copy; Copyright Ignite 2018. All rights reserved.</p>
            <p>Terms of use • Press Inquiries • General Inquiries • Investors</p>
        </div>
        <div class="footer-three">
        <img src="https://image.flaticon.com/icons/svg/185/185981.svg" width=40 height=40>
        &nbsp;&nbsp;&nbsp;&nbsp;
        <img src="https://image.flaticon.com/icons/svg/185/185961.svg" width=40 height=40>
        &nbsp;&nbsp;&nbsp;&nbsp;
        <img src="https://image.flaticon.com/icons/svg/185/185985.svg" width=40 height=40>
        </div>
    </footer>


    <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
</body>
</html>

最后,这是样式 sheet 起作用的小片段:

   <br/>
   <br/>
   <h2>Videos</h2>
   <br/>
   <br/>
   <% @videos.each do |v| %>
      <img src="<%= v.logo %>" width="110" height="110">
      <h3><%= v.title %></h3>
      <p><%= v.l_url %></p>
      <p><%= v.description %> </p>
   <br/>
   <% end %>
   <br/>
   <br/>
   <br/>
   <br/>
</div>

知道哪里出了问题吗?我感谢任何提示。

我认为这可能会解决您的问题,我认为您样式表的 link 可能已损坏。 如果页面不在顶部路径中,如果它看起来像这样:

http://localhost/namespace/ThisIsThePage

在您的 layout.erb 文件中,您使用的是样式表:

href="style.css"

在您的 CSS 导入中,我建议使用例如

来引用样式表
href="/style.css"

注意文件名前的斜线。斜杠告诉浏览器资源将从您的网络服务器的根路径加载。如果没有斜杠,浏览器将尝试从以下路径获取 style.css

http://localhost/namespace/style.css