Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html css-如何使用部分图像作为背景_Html_Css - Fatal编程技术网

Html css-如何使用部分图像作为背景

Html css-如何使用部分图像作为背景,html,css,Html,Css,我试图使用图像的一部分作为div的背景 它适用于我的固定宽度屏幕 但当我调整屏幕宽度时,它会丢失正确的位置,显示图像的其他部分 有人能帮忙吗 HTML CSS 游戏{ 显示:块; 宽度:100%; .切片{ 显示:块; 宽度:100%; 背景图片:url('/assets/maps/tilemaps/mymap.png'); 背景重复:无重复; 背景尺寸:100%自动; &托普·埃斯特拉达{ 背景位置:0-125px;/*这应该可以解决问题,我已经更改了背景大小和背景位置属性,通过此属性

我试图使用图像的一部分作为div的背景

它适用于我的固定宽度屏幕

但当我调整屏幕宽度时,它会丢失正确的位置,显示图像的其他部分

有人能帮忙吗

HTML


CSS

游戏{
显示:块;
宽度:100%;
.切片{
显示:块;
宽度:100%;
背景图片:url('/assets/maps/tilemaps/mymap.png');
背景重复:无重复;
背景尺寸:100%自动;
&托普·埃斯特拉达{

背景位置:0-125px;/*这应该可以解决问题,我已经更改了背景大小和背景位置属性,通过此属性,您可以进行一些调整,以达到您想要的效果

  .game{
  display:block;
  width:100%;
  .slice{
    display:block;
    width:100%;
    background-image:url('https://i.imgur.com/rdx8FHt.png');
    background-repeat: no-repeat;
    background-size: 100%;
    &.top_estrada{
      background-position:0 60%;      // <========= HERE
      height:88px;                       // <========= AND HERE
    }
  }
}
游戏{
显示:块;
宽度:100%;
.切片{
显示:块;
宽度:100%;
背景图像:url('https://i.imgur.com/rdx8FHt.png');
背景重复:无重复;
背景大小:100%;
&托普·埃斯特拉达{

背景位置:0 60%;//不使用百分比。使用像素保持大小,启用重复,然后根据需要调整位置:

游戏{
显示:块;
宽度:100%;
}
.游戏.切片{
显示:块;
宽度:100%;
背景图像:url('https://i.imgur.com/rdx8FHt.png');
背景尺寸:自动350px;
}
.game.slice.top_estrada{
背景位置:0-155px;
高度:88px;
}

托普埃斯特拉达酒店

问题是什么还不清楚,你能不能用HTML和CSS创建一个片段来显示问题。你可以裁剪图像,然后作为背景应用。添加了jsfiddle示例我的目标是只显示道路,而不是图像的其他部分这是因为背景大小
.game{
  display:block;
  width:100%;
  .slice{
    display:block;
    width:100%;
    background-image:url('/assets/maps/tilemaps/mymap.png');
    background-repeat: no-repeat;
    background-size: 100% auto;
    &.top_estrada{
      background-position:0 -125px;      /* <========= HERE */
      height:88px;                       /* <========= AND HERE */
    }
  }
}
  .game{
  display:block;
  width:100%;
  .slice{
    display:block;
    width:100%;
    background-image:url('https://i.imgur.com/rdx8FHt.png');
    background-repeat: no-repeat;
    background-size: 100%;
    &.top_estrada{
      background-position:0 60%;      // <========= HERE
      height:88px;                       // <========= AND HERE
    }
  }
}