2016-12-06 224 views
0

我有一个线性渐变,顶部的红色会在我的页脚CSS底部显示为白色。我希望渐变是显示器的宽度,而不会在左侧和右侧留下黑色边距。我的标题标记中有类似的代码,它没有黑色页边空白。如何修改我的线性渐变宽度为100%?

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 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是如何工作的宽度500px和320px。链接和图像使用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%; } } 

由于页脚内我假设我的问题是与梯度宽度。我已经看到很多与线性渐变和宽度相关的帖子,但我找不到任何解释我需要如何更改我的CSS才能使其工作的任何内容。

+1

你的这个

footer { padding-top: 0 } 

移动内容还需要提供HTML,而不仅仅是CSS。 – junkfoodjunkie

+0

我刚添加它。 –

+0

请发布渲染html/css的最小代码片段,这实际上会产生问题 – LGSon

回答

0

白手起家.container-fluid规则看起来像这样

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

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

标记为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规则,新规则,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); 
} 
+0

完美运作。所有宽度的梯度均为100%。这是我需要的。非常感谢! –

0

你可以尝试

background-size: 100% 100%; 

您可能不需要在水平和垂直方向均为100%,但不妨一试。

没有你的html很难看,但我希望这有助于。 而且你可能需要浏览器特定的CSS还例如

-o-background-size: 100% 100%; 
-moz-background-size: 100% 100%; 
-webkit-background-size: 100% 100%; 
+0

我曾试过背景大小:100%;对于我编码的所有浏览器,但它不起作用。我只是尝试了背景大小:100%100%;适用于所有浏览器。它仍然不起作用。我在问题中添加了我的HTML。 –

+0

好吧,我很高兴你得到了一个有帮助的答案。这会帮助你知道你在使用bootstrap。在这些情况下,我通常使用萤火虫来查看造成问题的原因。很多时候它是容器填充或类似的东西。 –

+0

我的CSS和标记在我认为会被识别为Bootstrap 3的人的代码中。我最初忘记标记它,但纠正了那一个。 –

0

好吧。复制你的代码,删除一些CSS,并且正如我想的那样,页脚的行为与它所在的块级元素相同。这意味着页脚的边距是由于您提供的代码以外的东西,或者是我从您的css中取出的代码(尽管它不应该是这样)。

而且,如果您提到您正在使用某种框架,并且实际上发布了CSS,而不是您拥有的任何非构建的* CSS,则会更容易。另外,如果你把它变成小提琴,你会发现它的宽度是100%。所以,问题可能是因为页脚被其他东西包裹(另一个div?),或者因为您的示例或代码不是实际的代码。在示例中停止使用特定于框架的代码。至少当你没有提到你使用的是什么框架的时候。

body { font-family: Arial; background-color: black; width: 100%; font-size: 18px; margin:0 auto; } 
 

 
footer { 
 
    color: gray; font-weight: bold; font-style: italic; font-size: 90%; line-height: 100%; 
 
    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); 
 
} 
 

 
#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>

+1

这是迄今为止我见过的最大的评论...我看不出它是如何真正回答问题的。请编辑或删除 – LGSon

+0

它确实回答了问题 - 代码是否显示100%宽度渐变?是或否? – junkfoodjunkie

+0

@junkfoodjunkie,我被你和另一个人问及提供我的CSS和HTML代码,这就是我所做的,每一行都直接从我的Web应用程序中复制。我使用Ruby on Rails(这应该不重要)。我只是添加了我的标题标记和application.html.erb文件的一部分,它显示我的页眉和页脚位于同一个容器流体div中。正如我在标题中说明我的红线(id =“back-red”)一直在线上,但我的页脚没有。 –