简体   繁体   English

如何设置完整的图像作为背景<div>

[英]How to set complete image as a background of <div>

Below is my image_url 下面是我的image_url

https://s3-ap-southeast-1.amazonaws.com/nearfox-other-images/imagebeautiful_hair_model_salon_124591669_large__20160501120024380271.jpg https://s3-ap-southeast-1.amazonaws.com/nearfox-other-images/imagebeautiful_hair_model_salon_124591669_large__20160501120024380271.jpg

I want to set this image as the cover picture on the below page 我想将此图像设置为下页的封面图片

https://nearfox.com/mumbai/p/aura-thai-spa-borivali-west https://nearfox.com/mumbai/p/aura-thai-spa-borivali-west

But this image is getting cropped automatically. 但是这张图片会自动裁剪。 I don't want to generate separate size for this. 我不想为此生成单独的大小。 So, how can I crop the custom part of the image and maintain the aspect ratio at the same time. 那么,我如何裁剪图像的自定义部分并同时保持纵横比。

You can use the below module to generate custom size images with various cropping techniques on frontend. 您可以使用以下模块在前端生成具有各种裁剪技术的自定义尺寸图像。 Also it supports S3 as you are using S3 for your images. 此外,它还支持S3,因为您正在为图像使用S3。

https://github.com/mariocesar/sorl-thumbnail https://github.com/mariocesar/sorl-thumbnail

use this css on your banner image css 在您的横幅图片css上使用此css


background-size: cover; 背景尺寸:封面;

element.style {
    width: 100%;
    height: 100%;
    background: url('https://s3-ap-southeast-1.amazonaws.com/nearfox-other-images/imagebeautiful_hair_model_salon_124591669_large__20160501120024380271.jpg') center;
    background-size: 100% auto;
} 

You need the background size to be changed like so, or tweak it to your liking. 您需要像这样更改背景大小,或根据自己的喜好进行调整。

background-size: cover 

Will simply crop it automatically and will probably lose the ratio and look deranged, however, when you put it 100% auto, it makes the width perfect and crops the top and bottom if needed, or you can switch it, do as you like! 将简单地自动裁剪它并且可能会失去比例并且看起来很疯狂,但是,当你把它100%自动时,它会使宽度完美并在需要时裁剪顶部和底部,或者你可以切换它,按你的喜好做! :D :d

you can also use this module Easy thumbnails module. 您也可以使用此模块轻松缩略图模块。 Also, it was vew more options plus it will serve your purpose smoothly. 此外,它有更多的选择加上它将顺利地为您的目的服务。 It has both the options of backend and frontend and it is easy to migrate if you want to , later at some point of time. 它有后端和前端的选项,如果你愿意,可以在以后的某个时间点轻松迁移。

insted of background, you can replace it by django template inside that div and apply easy-thumbnail module there 在背景中,你可以用div里面的django模板替换它,并在那里应用easy-thumbnail模块

https://github.com/SmileyChris/easy-thumbnails https://github.com/SmileyChris/easy-thumbnails

Use a combination of css background-position and background-size to position the image. 使用css background-positionbackground-size来定位图像。

 header { height: 180px; width: 500px; background: url('http://i.stack.imgur.com/t5h38.jpg'); background-position: 70% 40%; background-size: 150% auto; } 
 <header /> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM