Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/84.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_Image_Background Position - Fatal编程技术网

Html 如何在CSS中使用背景位置和背景大小,同时在某一点上锚定图像

Html 如何在CSS中使用背景位置和背景大小,同时在某一点上锚定图像,html,css,image,background-position,Html,Css,Image,Background Position,我有一个这样的布局,通过使用背景位置:中心和背景大小:封面: 原始图像来自: 我希望第一个例子看起来更像这样: 为此,我设想在图像上放置一个锚定点,并以某种方式告诉CSS使用这个锚定点 background-position: x y; div.relative { background: url(mountain.jpg); background-repeat: no-repeat; background-size: auto; position: relati

我有一个这样的布局,通过使用
背景位置:中心
背景大小:封面

原始图像来自:

我希望第一个例子看起来更像这样:

为此,我设想在图像上放置一个锚定点,并以某种方式告诉CSS使用这个锚定点

background-position: x y;
div.relative {
   background: url(mountain.jpg);
   background-repeat: no-repeat;
   background-size: auto;
   position: relative
   top: //what you want  e.g. 20px
   left: //e.g. 40px;
   bottom: //e.g. 80px;
   right: //e.g. 0px;
}
想知道我如何才能做到这一点


我不想裁剪图像,因为当屏幕调整大小时,或者在手机上,它会显示更多的图像。我希望图像保持原样。我也不希望图像被压扁,我希望它像
background size:cover
一样工作,但有一个自定义的定位点。

应该获得背景图像的元素的尺寸是什么?尺寸是任意的,在这种情况下可能是
flex:1
。是粗略的布局。寻求帮助的问题必须包含在问题本身中重现它所需的最短代码。请参阅:如何创建。添加
背景位置:顶部居中
background-position: x y;
div.relative {
   background: url(mountain.jpg);
   background-repeat: no-repeat;
   background-size: auto;
   position: relative
   top: //what you want  e.g. 20px
   left: //e.g. 40px;
   bottom: //e.g. 80px;
   right: //e.g. 0px;
}