【问题标题】:How to set background image to the left side of division?如何将背景图像设置在分区的左侧?
【发布时间】:2015-12-25 08:48:33
【问题描述】:

下面的div 现在显示错误消息我想添加一个将出现在错误消息之前的图像。它只是一个小错误图像,我想出现在div 的左侧,以便它出现在错误文本之前。我试图用背景图像来做,现在文本与图像重叠,因为图像是文本的背景。有什么方法可以使错误消息而不是重叠跟随图像。

<div id='er'><?php echo $er; ?></div>
<style>
#er{font-size: 14px;color:blue; background: url(img_stop.gif);
background-size: 35px 35px;
background-repeat: no-repeat;}
</style>

【问题讨论】:

    标签: html css


    【解决方案1】:

    类似JS Fiddle

    #er{
      font-size: 14px;
      color:blue;
      min-height:45px; /* so that the image will always be shown even for short error messages */
      background: transparent url(http://www.willowsigns.com/images/products/reflective-stop-sign-circular-icon-600mm-dia-Ehwf.png) no-repeat;
      background-position: 5px center; /* image positioned 5px of the 0 left and centered top */
      background-size: 35px 35px;
      border:1px solid red;
      padding:5px 5px 5px 45px; /*giving left padding as 45, 35px for the image, and 5px on each side */
    }
    <div id='er'>
      Lorem ipsum dolor sit amet, consectetur adipisicing elit. Asperiores soluta accusamus dolorum ut odit voluptatem, autem sint!
    </div>

    【讨论】:

    • 谢谢,但我的错误信息很短,所以如何垂直居中文本。现在文本出现在图像顶部,如错误消息的第一行
    • 如果你确定你的错误信息总是一行,把这个min-height改成line-height,检查这个:jsfiddle.net/Mi_Creativity/kp5a4s7h/4
    猜你喜欢
    • 1970-01-01
    • 2020-01-30
    • 2013-12-03
    • 1970-01-01
    • 2014-06-23
    • 2022-12-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多