使用 css 定位图层和文本渐变

发布于 2024-08-20 10:23:04 字数 1242 浏览 8 评论 0原文

我是一名 CSS 新手,正在尝试实现一些文本渐变。我在此处尝试了此代码,但没有成功对我来说不起作用,很可能是因为 h1 对象嵌套在 #header div 中。我想这与我不知道的图层有关。要么我得到一个位于所有内容前面的渐变块,要么它根本不出现。

在这个特定的实例中,这段代码使一个大的渐变条出现在所有内容的前面:

    #header {
    clear:both;
    float:left;
    -moz-background-inline-policy:continuous;
    -moz-background-origin:padding;
    background:#080E73 url(../images/header-background.png) repeat-x left 0px;
    width:100%;
    max-height: 175px;
    color: #080E73;
}
#header h1 {
    margin-bottom: 0;
    color: #000;
    position: relative;
}
#header h1 span {
  background:url(../images/headline-text.png) repeat-x;
  display: block;
  width: 100%;
  height: 100%;
  position: absolute;
}

这是HTML(我在rails上使用ruby,因此是符号)

     <div id="header">
  <% unless flash[:notice].blank? %>
    <div id="notice"><%= flash[:notice] %></div>
  <% end %>
        <%= image_tag ("header-image.png") %>
        <h1><span></span>Headline</h1> <strong>Byline</strong>
... #navbar html...
</div>

我尝试使用z-index,但我无法想出任何好的方法结果。有什么想法吗?

I'm a CSS newbie trying to get some text gradients going on. I tried this code here but it didn't work for me, most likely because the h1 object is nested within a #header div. I imagine there's something to do with layers that I don't know about. Either I get a gradent block that is in front of everything or it's not appearing at all.

In this particular instance this code makes a big gradient bar appear in front of everything:

    #header {
    clear:both;
    float:left;
    -moz-background-inline-policy:continuous;
    -moz-background-origin:padding;
    background:#080E73 url(../images/header-background.png) repeat-x left 0px;
    width:100%;
    max-height: 175px;
    color: #080E73;
}
#header h1 {
    margin-bottom: 0;
    color: #000;
    position: relative;
}
#header h1 span {
  background:url(../images/headline-text.png) repeat-x;
  display: block;
  width: 100%;
  height: 100%;
  position: absolute;
}

Here is the HTML (I'm using ruby on rails hence the notation)

     <div id="header">
  <% unless flash[:notice].blank? %>
    <div id="notice"><%= flash[:notice] %></div>
  <% end %>
        <%= image_tag ("header-image.png") %>
        <h1><span></span>Headline</h1> <strong>Byline</strong>
... #navbar html...
</div>

I tried playing with z-index but I couldn't come up with any good results. Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

泼猴你往哪里跑 2024-08-27 10:23:05

当您说“此代码使一个大渐变条出现在所有内容前面”时,渐变应该出现在所有内容前面,但它应该是透明的并且颜色与背景颜色相同。

是否有可能您没有正确导出PNG?或者您应用透明度的颜色块不是正确的颜色?

When you say "this code makes a big gradient bar appear in front of everything", the gradient is supposed to appear in front of everything, but it's supposed to be transparent and the same colour as your background colour.

Is it possible that you've not exported the PNG correctly? or that the block of colour you've applied the transparency to isn't the correct colour?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文