【问题标题】:CSS3 multiple backgrounds, one repeating in ulCSS3多背景,一个在ul中重复
【发布时间】:2012-11-08 04:52:21
【问题描述】:

我正在开发一个 Wordpress 模板。我正在尝试为导航菜单中的每个 <li> 实现 3 个背景图像,这是动态生成的。看看这两个例子。

http://preahkumpii.com/misc/test01/hi.html
http://preahkumpii.com/misc/test02/hi.html

第一个示例 CSS:

.menu-item li {
  background-image: url(images/menu-left.png), url(images/menu-right.png), url(images/menu-center.png);
  background-position: left, right, center;
  background-repeat: no-repeat, no-repeat, no-repeat;
}

第二个 CSS 示例:

.menu-item li {
  background-image: url(images/menu-left.png), url(images/menu-right.png), url(images/menu-center.png);
  background-position: left, right, center;
  background-repeat: no-repeat, no-repeat, repeat-x;
}

HTML:

<ul class="menu-item">
  <li>ItemNumber1</li>
  <li>ItemNumber2</li>
  <li>ItemNumber3</li>
</ul>

我希望两个外部背景图像保持在没有重复的位置。但是,我希望中间的背景图像沿 x 轴重复,但只延伸到其他背景图像。正如您在第二个示例中看到的,当给定中间图像repeat-x 时,它会延伸到整个&lt;li&gt;。据我所知,我不能使用&lt;div&gt; 来实现这一点,因为菜单的文本是动态生成的。所以,我假设我必须只有一个&lt;ul&gt;,而没有一堆&lt;div&gt;s 闲逛。有什么帮助吗?

【问题讨论】:

    标签: html css wordpress html-lists background-image


    【解决方案1】:

    嘿,您可以使用after-before 伪类来获得您想要的结果。

    查看 CSS 我是如何做到的:-

    CSS

    .menu-item li:after {
        background: url("images/menu-center.png") repeat-x scroll 0 0 transparent;
        bottom: 0;
        content: " ";
        left: 20px;
        position: absolute;
        right: 20px;
        top: 0;
        z-index: -1;
    }
    .menu-item li {
        background-image: url("images/menu-left.png"), url("images/menu-right.png");
        background-position: left center, right center;
        background-repeat: no-repeat, no-repeat;
        display: inline-block;
        height: 56px;
        line-height: 56px;
        min-width: 60px;
        padding: 0 20px;
        position: relative;
        text-align: center;
        z-index: 1;
    }
    

    查看输出我是如何做到的

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-10-09
      • 1970-01-01
      • 2013-11-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多