【问题标题】:Restrict size of radial gradient on an element限制元素上径向渐变的大小
【发布时间】:2015-02-08 09:18:54
【问题描述】:

我有一个部分占用 100% 宽度和 100% 高度。我需要一个100%宽度和100px高度的径向渐变(中心#5E88B2和#06305A外部)。因此,顶部 100px 上应该有径向渐变,并且在默认颜色(白色)之后应该继续。 我知道如何使用线性渐变来实现它。但是,径向渐变怎么做呢?

.Content {
  border-top: 10px solid #666666;
  background-size: 100%;
  background: #5E88B2;
  background: -moz-radial-gradient(center, ellipse cover, #5E88B2 0%, #06305a 100%);
  background: -webkit-gradient(radial, center center, 0px, center center, 100%, color-stop(0%, #5E88B2));
  background: -webkit-radial-gradient(center, ellipse cover, #5E88B2 0%, #06305a 100%);
  background: -o-radial-gradient(center, ellipse cover, #5E88B2 0%, #06305a 100%);
  background: -ms-radial-gradient(center, ellipse cover, #5E88B2 0%, #06305a 100%);
  background: radial-gradient(ellipse at center, #5E88B2 0%, #06305a 100%);
}
.MainContent{ background-color: #ffffff; border-radius: 5px; margin-top: 3%;margin-left: auto;
margin-right: auto; padding-left: 15px; padding-right: 15px;clear: both;display: table; width:300px;}
<section style="background-color:#fff;">This is header</section>
<section id="OuterSection" class="container-fluid Content">
  <section class="container MainContent">
    <!-- Main Markup -->
    Content<br>Content<br>Content<br>Content<br>Content<br> Content<br>Content<br>
    Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>
  </section>
</section>
<section style="background-color:#eee;">This is footer</section>

目前它正在全高度。但是,我需要从“OuterSection”顶部开始 100px 高度的径向渐变

【问题讨论】:

  • 发布 HTML/CSS 标记。

标签: html css


【解决方案1】:

您可以使用background-sizebackground-repeat 属性来限制背景图片的大小。

.Content {
  border-top: 10px solid #666666;
  background: #5E88B2;
  background: -moz-radial-gradient(center, ellipse cover, #5E88B2 0%, #06305a 100%);
  background: -webkit-gradient(radial, center center, 0px, center center, 100%, color-stop(0%, #5E88B2));
  background: -webkit-radial-gradient(center, ellipse cover, #5E88B2 0%, #06305a 100%);
  background: -o-radial-gradient(center, ellipse cover, #5E88B2 0%, #06305a 100%);
  background: -ms-radial-gradient(center, ellipse cover, #5E88B2 0%, #06305a 100%);
  background: radial-gradient(ellipse at center, #5E88B2 0%, #06305a 100%);
  background-size: 100% 100px;
  background-repeat: no-repeat;
}
.MainContent {
  background-color: #ffffff;
  border-radius: 5px;
  margin-top: 3%;
  margin-left: auto;
  margin-right: auto;
  padding-left: 15px;
  padding-right: 15px;
  clear: both;
  display: table;
  width: 300px;
}
<section style="background-color: #ffffff;">This is header</section>
<section id="OuterSection" class="container-fluid Content">
  <section class="container MainContent">
    <!-- Main Markup -->
    Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>
    Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>
  </section>
</section>
<section style="background-color: #eeeeee;">This is footer</section>

【讨论】:

  • 谢谢。但我不需要这个。请再次检查问题,我已对其进行了代码编辑
  • 我认为您要求将背景大小限制为 100 像素。查看修改后的答案(或解释或添加所需输出的图片)。
  • 很抱歉造成沟通障碍。我上传了一张图片和改进的代码,您现在可以查看
猜你喜欢
  • 1970-01-01
  • 2018-02-05
  • 2021-03-30
  • 1970-01-01
  • 1970-01-01
  • 2015-12-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多