【问题标题】:How to place background-image on right side of content如何将背景图像放在内容的右侧
【发布时间】:2015-09-18 18:21:37
【问题描述】:

我无法让背景图像显示在某些文本的右侧。

见页面http://bit.ly/1FR0Tw3

“右箭头”背景图像精灵需要位于“下一个”一词的右侧。

上一个链接的图像背景的精灵很好。这只是我无法弄清楚的下一个链接。

这是我的 CSS

div#maincontentcontainer div#inner-page-content div.entry-content div.post-nav-previous {
    background: url('/wp-content/themes/investorcom-2015/images/post-nav-arrows.png') no-repeat left top;
    background-position: 0 0;
    float: left;
    font-size: 0.8em;
    line-height: 1.4em;
    padding-left: 20px;
}
div#maincontentcontainer div#inner-page-content div.entry-content div.post-nav-next {
    background: url('/wp-content/themes/investorcom-2015/images/post-nav-arrows.png') no-repeat right top;
    background-position: 0 -15px;
    float: right;
    font-size: 0.8em;
    padding-right: 20px;
}

【问题讨论】:

  • 你为什么把你的网站隐藏在 URL 缩短器后面?

标签: css background-image sprite css-position


【解决方案1】:
background-position: right -15px;

像这样?

【讨论】:

  • 之所以选择这个作为答案,是因为它排在第一位——@FirebladeDan 的答案也很有效
【解决方案2】:
background-position: 30px -15px;

【讨论】:

    【解决方案3】:

    将 Next 一词包装在另一个 div 中,并将新 div 的 css 设置为 margin-left:20px

    <div class="post-nav-next">
        <div style="margin-left: 20px;">
          Next
        </div>
    </div>
    

    【讨论】:

    • ok @AndyLewis -- 但我更喜欢通过控制 sprite 在我的 css 样式表中进行操作
    • 啊,是的,当然你可以在包含 div 的类中添加一个新类并将其放入你的 css 文件中。无论如何,其他答案都比我的好;更少的标记。
    • 感谢您抽出宝贵时间回复。我对你的一些建议投了赞成票……谢谢
    猜你喜欢
    • 2010-10-04
    • 2012-11-28
    • 1970-01-01
    • 2021-11-19
    • 1970-01-01
    • 2011-03-12
    • 1970-01-01
    • 2021-05-12
    • 2023-03-27
    相关资源
    最近更新 更多