水平重复图像(非背景图像)

时间:2015-05-25 10:12:49

标签: html css

我只是不能让这个道路图像水平重复,它不是背景图像,我坚持这个。

https://jsfiddle.net/gcetx8kh/

HTML:

<img id="rd" src="http://us.cdn3.123rf.com/168nwm/eriksvoboda/eriksvoboda1411/eriksvoboda141100036/33498305-asphalt-road-texture-with-white-and-yellow-stripes.jpg">

CSS:

#rd {
position: absolute;
height: 50px;
width: 50px;
top: 300px; 
background-repeat: repeat-x;

}

2 个答案:

答案 0 :(得分:6)

请尝试以下操作: Demo

<div id="rd"></div>

CSS:

#rd {
    position: absolute;
    height: 50px;
    width: 100%;
    top: 300px;
    background: url(http://us.cdn3.123rf.com/168nwm/eriksvoboda/eriksvoboda1411/eriksvoboda141100036/33498305-asphalt-road-texture-with-white-and-yellow-stripes.jpg) center repeat-x;

    background-size: auto 100%;
}

修改: Demo ,双方淡出

#rd {   
    height: 50px;
    width: 100%;
    top: 300px;
    background: url(http://us.cdn3.123rf.com/168nwm/eriksvoboda/eriksvoboda1411/eriksvoboda141100036/33498305-asphalt-road-texture-with-white-and-yellow-stripes.jpg) center repeat-x;    
    background-size: auto 100%;    
    position: relative;
   display: inline-block;
}

#rd:before{   
  content: "";
  top: 0;
  left: 0;
  position: absolute;
  height: 100%;
  width: 100%;
  background: -moz-linear-gradient(left, rgba(255, 255, 255, 1) 0%, rgba(255, 255, 255, 0) 49%, rgba(255, 255, 255, 1) 100%);      
  background: -webkit-gradient(linear, left top, right top, color-stop(0%, rgba(255, 255, 255, 1)), color-stop(49%, rgba(255, 255, 255, 0)), color-stop(100%, rgba(255, 255, 255, 1)));     
  background: -webkit-linear-gradient(left, rgba(255, 255, 255, 1) 0%, rgba(255, 255, 255, 0) 49%, rgba(255, 255, 255, 1) 100%);      
  background: -o-linear-gradient(left, rgba(255, 255, 255, 1) 0%, rgba(255, 255, 255, 0) 49%, rgba(255, 255, 255, 1) 100%);     
  background: -ms-linear-gradient(left, rgba(255, 255, 255, 1) 0%, rgba(255, 255, 255, 0) 49%, rgba(255, 255, 255, 1) 100%);    
  background: linear-gradient(to right, rgba(255, 255, 255, 1) 0%, rgba(255, 255, 255, 0) 49%, rgba(255, 255, 255, 1) 100%);     
  filter: progid: DXImageTransform.Microsoft.gradient(startColorstr='#ffffff', endColorstr='#ffffff', GradientType=1);   
}

答案 1 :(得分:1)

background-repeat: repeat-x;无法使用img标记。 添加新div并将图像应用为背景图像。