html - 如何将线性渐变宽度修改为 100%?

标签 html css twitter-bootstrap-3 footer linear-gradients

我的页脚 CSS 中有一个线性渐变,顶部为红色,底部为白色。我希望渐变是显示器的宽度,左右两侧没有黑色边距。我的标题标记中有类似的代码,用于没有黑色边距的红色实线。

CSS

body { font-family: Arial; background-color: $black; width: 100%; font-size: 18px; margin:0 auto; }
footer, header { font-family: Eurostile; padding-top: 15px; margin:0 auto; .row { .row-col-img-padding { [class*="col-"] { padding-left: 0px !important; padding-right: 0px !important; } } } }
footer {
    color: $gray; font-weight: bold; font-style: italic; font-size: 90%; line-height: 100%; a { color: $bluedark; } 
    background: red; 
    background: linear-gradient($red, $white);
    background: -khtml-linear-gradient($red, $white); 
    background: -moz-linear-gradient($red, $white); 
    background: -ms-linear-gradient($red, $white); 
    background: -o-linear-gradient($red, $white); 
    background: -webkit-linear-gradient($red, $white); 
}
header { background-color: $black; p { color: $grayLight; font-weight: bold; font-size: 100%; line-height: 100%; } }

标题中实线的 CSS,其中红线无边距地填满屏幕。

#back-red { background-color: $red; padding-bottom: 15px; }

标记

<footer class="footer">
  <div class="row row-col-img-padding">
    <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12" align="center">
      <ul class="list-inline">
        <li><%= link_to image_tag("footer-facebook-#{I18n.locale}.jpg", class: "img-responsive aspect", alt: "Facebook"), "https://www.facebook.com/xxxxxxx", target: '_blank' %></li>
        <li><%= link_to image_tag("footer-twitter-#{I18n.locale}.jpg", class: "img-responsive aspect", alt: "Twitter"), "https://twitter.com/xxxxxxxx", target: '_blank' %></li>
        <li><%= link_to image_tag("footer-linkedin-#{I18n.locale}.jpg", class: "img-responsive aspect", alt: "LinkedIn"), "http://www.linkedin.com/company/xxxxxx", target: '_blank' %></li>
        <li><%= link_to image_tag("footer-linkedin-bernard-#{I18n.locale}.jpg", class: "img-responsive aspect", alt: "#{t :translation_hash1}"), "http://www.linkedin.com/in/xxxxxxx", target: '_blank' %></li>
        <li><%= link_to image_tag("footer-linkedin-pam-#{I18n.locale}.jpg", class: "img-responsive aspect", alt: "#{t :translation_hash2}"), "http://www.linkedin.com/in/xxxxxxx", target: '_blank' %></li>
      </ul>
    </div>
  </div>
  <div class="row row-col-img-padding">
    <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12" align="center">
      <%= link_to image_tag("footer-privacypolicy-#{I18n.locale}.jpg", class: "img-responsive aspect", alt: "#{t :privacy_head1}"), privacy_path %>
      <div class="footer-links">
        <%= link_to "#{t :footer_link1}", locale_root_path %>
        <%= link_to "#{t :footer_link3}", system_path %>
        <%= link_to "#{t :footer_link4}", manage_path %>
        <%= link_to "#{t :footer_link6}", clients_path %>
        <%= link_to "#{t :footer_link2}", about_path %>
        <%= link_to "#{t :footer_link5}", contact_path %>
        <%= link_to "#{t :footer_link7}", media_path %><br>
        <%= link_to "Facebook", "https://www.facebook.com/LightBeCorp", target: '_blank' %>
        <%= link_to "Twitter", "https://twitter.com/lightbecorp", target: '_blank' %>
        <%= link_to "LinkedIn", "http://www.linkedin.com/company/lightbe-corp", target: '_blank' %>
        <%= link_to "#{t :footer_link8} xxxxxxxxxx", "http://www.linkedin.com/in/bernarddreyer", target: '_blank' %>
        <%= link_to "#{t :footer_link8} xxxxxxxxxx", "http://www.linkedin.com/in/pamelacooktulsaok", target: '_blank' %><br>
        <%= link_to "#{t :footer_link9}", privacy_path %>
        <%= link_to_unless_current "#{t :english}", locale: "en" %>
        <%= link_to_unless_current "Français", locale: "fr" %>
      </div>
      <p class="text-red-pad-top-10"><%= "#{t :footer2}" %> <span class="text-red">Light</span><span class="text-bluedark">Be</span> ©2010-<%= Time.now.strftime("%Y") %> - <%= "#{t :footer3}" %></p>
    </div>
  </div>
</footer>

header 标记

<header class="header">
  <div class="row row-col-img-padding" id="pad-bottom-15">
    <p class="locale-line" align="center"><span class="english-link"><%= link_to_unless_current "#{t :english}", locale: "en" %></span><%= link_to_unless_current "#{t :french}", locale: "fr" %></p>
    <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12" align="center" id="header-images">
      <div class="page-class" align="center">
        <ul>
          <li><%= link_to image_tag("menu-home.jpg", class: "img-responsive aspect", alt: "#{t :footer_link1}"), locale_root_path %></li>
          <li><%= link_to image_tag("menu-manage-#{I18n.locale}.jpg", class: "img-responsive aspect", alt: "#{t :footer_link4}"), manage_path %></li>
          <li><%= link_to image_tag("menu-system-#{I18n.locale}.jpg", class: "img-responsive aspect", alt: "#{t :footer_link3}"), system_path %></li>
          <li><%= link_to image_tag("menu-media-#{I18n.locale}.jpg", class: "img-responsive aspect", alt: "#{t :footer_link7}"), media_path %></li>
          <li><%= link_to image_tag("menu-clients-#{I18n.locale}.jpg", class: "img-responsive aspect", alt: "#{t :footer_link6}"), clients_path %></li>
          <li><%= link_to image_tag("menu-about-#{I18n.locale}.jpg", class: "img-responsive aspect", alt: "#{t :footer_link2}"), about_path %></li>
          <li><%= link_to image_tag("menu-contact-#{I18n.locale}.jpg", class: "img-responsive aspect", alt: "#{t :footer_link5}"), contact_path %></li>
        </ul>
      </div>
    </div>
  </div>
  <div class="row row-col-img-padding" id="back-red">
    <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12" align="center">
      <h1><%= @page_title %></h1>
      <% if params[:action] == "system" && I18n.locale.to_s == "fr" %>
      <% else %>
        <p><%= @page_abstract1 %></p>
        <p><%= @page_abstract2 %></p>
        <p><%= @page_abstract3 %></p>
        <p><%= @page_abstract4 %></p>
        <p><%= @page_abstract5 %></p>
      <% end %>
      <p><%= @page_abstract6 %></p>
      <% if params[:action] == "system" && I18n.locale.to_s == "fr" %>
      <% else %>
        <p><%= @page_abstract7 %></p>
      <% end %>
    </div>
  </div>
</header>

Ruby on Rails application.html.erb

  <body>
    <div class="container-fluid"> 
      <%= render 'layouts/header' %> <!-- update app/views/layouts/_systemmessage.html.erb when you need to reboot the server -->
      <%= render 'layouts/systemmessage' %>
      <% flash.each do |key, value| %>
        <%= content_tag(:div, value, class: "alert alert-#{key}") %>
      <% end %>
      <%= yield %>
      <%= render 'layouts/contact_footer' %>
      <%= render 'layouts/footer' %>
    </div>
    <%= javascript_include_tag "application" %>
    <%= debug(params) if Rails.env.development? %>
  </body>

下图显示了我的 CSS 在 500 像素和 320 像素宽度下的工作方式。链接和图像使用 CSS .footer-links。它们扩散到屏幕边缘,但渐变没有。

enter image description here

enter image description here

下面的 CSS

.footer-links { width: 1024px; padding-top: 10px; a { padding-left: 5px; padding-right: 5px; } }

@media screen and (max-width: 1024px) { body, footer, header, .box-message, .footer-links, .page-class, .red-line-1px { max-width: 100%; } }

由于 headerfooterbody 内,我认为我的问题出在渐变宽度上。我看过许多与线性渐变和宽度相关的帖子,但我找不到任何内容来准确解释我需要如何更改我的 CSS 才能使其正常工作。

最佳答案

Bootstrap .container-fluid规则看起来像这样

{margin-right:auto;margin-left:auto;padding-left:15px;padding-right:15px}

所以对于你的 footer工作,你可以这样做,主要的变化是添加一个包装器 <div class="row">然后删除 row从类 <div class="row-col-img-padding"> , 然后在包装器上设置渐变

footer 的标记

  <footer class="footer">
    <div class="row">
      <div class="row-col-img-padding">
        <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12" align="center">
          <ul class="list-inline">
            <li><%= link_to image_tag("footer-facebook-#{I18n.locale}.jpg", class: "img-responsive aspect", alt: "Facebook"), "https://www.facebook.com/xxxxxxx", target: '_blank' %></li>
            <li><%= link_to image_tag("footer-twitter-#{I18n.locale}.jpg", class: "img-responsive aspect", alt: "Twitter"), "https://twitter.com/xxxxxxxx", target: '_blank' %></li>
            <li><%= link_to image_tag("footer-linkedin-#{I18n.locale}.jpg", class: "img-responsive aspect", alt: "LinkedIn"), "http://www.linkedin.com/company/xxxxxx", target: '_blank' %></li>
            <li><%= link_to image_tag("footer-linkedin-bernard-#{I18n.locale}.jpg", class: "img-responsive aspect", alt: "#{t :translation_hash1}"), "http://www.linkedin.com/in/xxxxxxx", target: '_blank' %></li>
            <li><%= link_to image_tag("footer-linkedin-pam-#{I18n.locale}.jpg", class: "img-responsive aspect", alt: "#{t :translation_hash2}"), "http://www.linkedin.com/in/xxxxxxx", target: '_blank' %></li>
          </ul>
        </div>
      </div>
      <div class="row-col-img-padding">
        <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12" align="center">
          <%= link_to image_tag("footer-privacypolicy-#{I18n.locale}.jpg", class: "img-responsive aspect", alt: "#{t :privacy_head1}"), privacy_path %>
          <div class="footer-links">
            <%= link_to "#{t :footer_link1}", locale_root_path %>
            <%= link_to "#{t :footer_link3}", system_path %>
            <%= link_to "#{t :footer_link4}", manage_path %>
            <%= link_to "#{t :footer_link6}", clients_path %>
            <%= link_to "#{t :footer_link2}", about_path %>
            <%= link_to "#{t :footer_link5}", contact_path %>
            <%= link_to "#{t :footer_link7}", media_path %><br>
            <%= link_to "Facebook", "https://www.facebook.com/LightBeCorp", target: '_blank' %>
            <%= link_to "Twitter", "https://twitter.com/lightbecorp", target: '_blank' %>
            <%= link_to "LinkedIn", "http://www.linkedin.com/company/lightbe-corp", target: '_blank' %>
            <%= link_to "#{t :footer_link8} xxxxxxxxxx", "http://www.linkedin.com/in/bernarddreyer", target: '_blank' %>
            <%= link_to "#{t :footer_link8} xxxxxxxxxx", "http://www.linkedin.com/in/pamelacooktulsaok", target: '_blank' %><br>
            <%= link_to "#{t :footer_link9}", privacy_path %>
            <%= link_to_unless_current "#{t :english}", locale: "en" %>
            <%= link_to_unless_current "Français", locale: "fr" %>
          </div>
          <p class="text-red-pad-top-10"><%= "#{t :footer2}" %> <span class="text-red">Light</span><span class="text-bluedark">Be</span> ©2010-<%= Time.now.strftime("%Y") %> - <%= "#{t :footer3}" %></p>
        </div>
      </div>
    </div>
  </footer>

更改您的 CSS footer对此的规定

footer {
    padding-top: 0
}

移动现有内容footer规则到新规则,footer > .row , 像这样

footer > .row {
    padding-top: 15px;     /*  added new property  */

    color: $gray; font-weight: bold; font-style: italic; font-size: 90%; line-height: 100%; a { color: $bluedark; } 
    background: red; 
    background: linear-gradient($red, $white);
    background: -khtml-linear-gradient($red, $white); 
    background: -moz-linear-gradient($red, $white); 
    background: -ms-linear-gradient($red, $white); 
    background: -o-linear-gradient($red, $white); 
    background: -webkit-linear-gradient($red, $white); 
}

关于html - 如何将线性渐变宽度修改为 100%?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41006945/

相关文章:

html - 需要在 header 之后修复 div 的位置

html - 全宽边框线和透明标志越过

html - Gmail:大于内联 css 样式中定义的大小的元素

javascript - 如何停止HTML5的audio标签播放的音频

css - 水平居中 zurb 基础顶部栏菜单,多行元素垂直居中

css - 在平板电脑或手机视口(viewport)中时在类之间进行 Bootstrap 切换

html - img-circle 类不对图像进行四舍五入

javascript - Tab.js 无法读取未定义的属性 'getSelectorFromElement'

html - 绝对垂直、水平 float 的 div 元素

html - 有没有办法在 Shadow-DOM 中访问 CSS 中的 HTML 标签属性?