代码之家  ›  专栏  ›  技术社区  ›  DixonD

如何在Sitecore中的图像上放置文本?

  •  0
  • DixonD  · 技术社区  · 15 年前

    我需要创建用户控件 <sc:text/> 元素应该显示在 <sc:image> .

    有什么提示吗?

    2 回复  |  直到 15 年前
        1
  •  0
  •   Bartłomiej Mucha    12 年前

    您可以使用 sc:fld sc:text 在标记中,添加类名或ID(如果必须的话,也可以添加内联样式!)。

    <img src="{sc:fld( 'graphic', $sc_currentitem, 'src’ )}" class="head" />
    <span class="txt"><sc:text field="txtField" /></span>
    

    然后可以将这些样式设置为普通样式

    img.head {}
    span.txt {}
    
        2
  •  0
  •   Bartłomiej Mucha    12 年前

    我不明白这个问题。这看起来更像是一个前端问题,而不是Sitecore问题。CSS可以很好的工作。下面是一个粗略的例子(没有经过测试,但能让你明白这一点):

    示例HTML:

    <div class="my-container">
      <div class="img">
        <sc:image Field="Bar" runat="server" />
      </div>
      <div class="txt">
        <sc:text Field="Foo" runat="server" />
      </div>
    </div>
    

    CSS示例:

    .my-container {
      position: relative;
    }
    
      .my-container .txt {
        position: absolute;
        z-index: 50;
        top: 0px;
      }
    
      .my-container .img {
        z-index: 10;
      }
    
    推荐文章