2016-12-06 77 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」)一直在線上,但我的頁腳沒有。 –