【问题标题】:How to debug HTML5/CSS for background video in RoR app如何在 RoR 应用程序中为背景视频调试 HTML5/CSS
【发布时间】:2015-09-26 06:42:37
【问题描述】:

我正在尝试为我的 RoR 应用的主页实现响应式全背景视频。

目前,该视频只是显示为一个正在开发的黑色大空白屏幕。我决定将视频仅以一种格式 (mp4) 放入 vid.me,而不是通过 S3 或 AWS。

我的代码有什么问题还是我遗漏了什么?

谢谢!

 app/assets/stylesheets/custom.css.scss

      @import "bootstrap-sprockets";
      @import "bootstrap";

     /* mixins, variables, etc. */

     $gray-medium-light: #eaeaea;

     /* universal */

    body {
        padding-top: 60px;
   }

     section {
       overflow: auto;
    }

    textarea {
       resize: vertical;
    }

    .center {
       text-align: center;
       h1 {
           margin-bottom: 10px;
       }
   }

    /* typography */

    h1, h2, h3, h4, h5, h6 {    
       line-height: 1;
   }

   @gray-light: #777;

   h1 {
       font-size: 3em;
       letter-spacing: -2px;
       margin-bottom: 30px;
       text-align: center;
     }

    h2 {
        font-size: 1.5em;
        letter-spacing: -1px;
        margin-bottom: 30px;
        text-align: center;
        font-weight: normal;
        color: $gray-light
    }

    p {
        font-size: 1.1em;
        line-height: 1.7em;
    }

    /* header */


    #logo {
       float: left;
       margin-right: 10px;
       font-size: 1.7em;
       color: #F0F8FF;
       text-transform: uppercase;
       letter-spacing: -1px;
       padding-top: 9px;
       font-weight: bold;
          &:hover {
            color: white;
            text-decoration: none;
        }
     }


     video {
        min-width: 100%;
        min-height: 100%;
        width: auto;
        height: auto;
        background: url(https://vid.me/e/4UIS);
        background-size: cover;
     }


    /* footer */

    footer {
        margin-top: 45px;
        padding-top: 5px;
        border-top: 1px solid $gray-medium-light;
        color:  $gray-light;
        a {
         color: $gray;
        &:hover {
        color: $gray-darker;
          }
      }


       small {
       float: left;
     }

       ul {
           float: right;
           list-style: none;
           li {
              float: left;
              margin-left: 15px;
          }
       }
   }


     app

视频文件的代码当前在应用程序文件夹中,而不是 static_pages/home.html.erb 文件,因为由于某种原因不在 applicaiton.thml.erb 中时它会缩小:

app/views/application.html.erb

<!DOCTYPE html>
<html>
    <head>
          <title><%= full_title(yield(:title)) %></title>
          <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true %>
          <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
          <%= csrf_meta_tags %>

          <%= render 'layouts/shim' %>
    </head>
    <body>

      <video>
        <source src ="https://vid.me/e/4UIS" type="video/mp4"/>
     </video>

            <%= render 'layouts/shim' %>

            <div class="container">
                 <%= yield %>
                 <%= render 'layouts/footer' %>
            </div>
    </body>
</html>

【问题讨论】:

    标签: css ruby-on-rails html video


    【解决方案1】:

    如果您使用的是.scss,那么您最好多走一步并使用sass

      #app/assets/stylesheets/custom.css.sass
    
      /* Dependencies */
      @import "bootstrap-sprockets"
      @import "bootstrap"
    
      /* Vars */
      $gray-light: #777
      $gray-medium-light: #eaeaea
    
    
     /* Universal */
     body
       padding:
         top: 60px
    
     section
       overflow: auto
    
     textarea
       resize: vertical
    
     center
       text:
         align: center
       h1
           margin:
             bottom: 10px
    
    
     /* Type */
     h1, h2, h3, h4, h5, h6  
       line:
        height: 1;
    
     h1
       font:
          size: 3em
       letter:
          spacing: -2px
       margin:
          bottom: 30px
       text:
          align: center
    
      h2 
        font:
           size: 1.5em
           weight: normal
        letter:
           spacing: -1px
        margin:
           bottom: 30px
        text:
           align: center
        color: $gray-light
    
      p
        font:
          size: 1.1em
        line:
          height: 1.7em
    
    
      /* Header */
      #logo 
        float: left;
        margin:
          right: 10px
       font:
          size: 1.7em
          weight: bold
       color: #F0F8FF
       text:
          transform: uppercase
       letter:
          spacing: -1px
       padding:
          top: 9px;
       &:hover
          color: white
          text:
             decoration: none
    
    
     video
        min:
          width: 100%
          height: 100%
        width: auto
        height: auto
        background:
           image: url(https://vid.me/e/4UIS)
           size: cover
    
    
    /* Footer */
    
    footer
        margin:
          top: 45px
        padding:
          top: 5px
        border:
          top: 1px solid $gray-medium-light
        color:  $gray-light;
        a
         color: $gray
        &:hover
           color: $gray-darker
    
    
       small
         float: left
    
       ul
           float: right;
           list:
             style: none
           li
              float: left
              margin:
                left: 15px
    

    关于您的实际问题,我必须阅读此内容以了解它是如何工作的。似乎除了调用视频的 CSS 背景之外,还有更多功能。 HTML 需要知道它是否是视频...

    这里有一些资源:

    看来底线是你必须在 HTML 中调用 video 元素,使用 CSS 来设置它的全屏特性:

    #source - http://codepen.io/mattgrosswork/pen/jrdwK
    <video autoplay loop id="video-background" muted>
      <source src="http://beta.mattgrossdesign.com/sites/default/files/wood%20autumn-HD.mp4" type="video/mp4">
    </video>
    
    #video-background {
    /*  making the video fullscreen  */
      position: fixed;
      right: 0; 
      bottom: 0;
      min-width: 100%; 
      min-height: 100%;
      width: auto; 
      height: auto;
      z-index: -100;
    }
    

    --

    所以对你来说,也许是这样的:

    #app/views/layouts/application.html.erb
    <%= video_tag "https://vid.me/e/4UIS", id:"video-background"%>
    
    #app/assets/stylesheets/application.js.erb
    #video-background {
    /*  making the video fullscreen  */
      position: fixed;
      right: 0; 
      bottom: 0;
      min-width: 100%; 
      min-height: 100%;
      width: auto; 
      height: auto;
      z-index: -100;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-03-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-10
      • 1970-01-01
      相关资源
      最近更新 更多