2016-12-06 3 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; } 

Markup

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

Рубин на 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%; } } 

С заголовка и сноске находятся в пределах тела Я предполагаю, что моя проблема с шириной градиента. Я видел много сообщений, связанных с линейными градиентами и ширинами, но я не мог найти ничего, что объясняло бы точно, как мне нужно изменить мой CSS, чтобы заставить это работать.

+1

You нужно также предоставить 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"> и затем удалите класс 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); 
} 
+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

Ну, я рад, что вы получили ответ, который помог. Это помогло бы узнать, что вы используете бутстрап. В этих ситуациях я обычно использую firebug, чтобы узнать, что вызывает проблему. Очень часто это заполнение контейнера или что-то в этом роде. –

+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-код, и это то, что я сделал, каждая строка, скопированная прямо из моего веб-приложения. Я использую Ruby on Rails (что не имеет значения). Я просто добавил свою разметку заголовка и часть файла application.html.erb, который показывает, что мой верхний и нижний колонтитулы находятся в одном контейнере-контейнере. Поскольку я заявил, что моя красная линия (id = «back-red») в заголовке проходит полностью через линию, но мой нижний колонтитул не сделал этого. –

Смежные вопросы