How to avoid slider image what covers whole width of screen and certain height to stretch or crop? - html

I'm working on a website. There's one problem. The slider won't fit in the frame without stretching.
Slider Image is full width of screen and i have defined height for it.
In CSS part i have applied object-fit: cover but this crop my image
I hope you guys can help me out on this. I'd tried alot and also asked some other people but they can't help me with this.
Or Should i restrict my client to use image of that resolution only?

Yes Mostly you should restrict the client from using different ratios, or resolutions, because you are using the full width aaaaand defined height, defined height is very limiting in your case, what you can do is use
object-fit:cover;
object-fit:center;
but that doesn't stop the cropping it will just focus on the center of the image when cropping.

Related

How can I prevent stretching an image using html5 picture tag and a defined height?

I'm using HTML5's <picture> tags to create a responsive header that will stretch the entire width of the browser. The header uses an image as the background.
For larger screens I limited the height to a defined value. However, I noticed that a certain breakpoint the image starts to stretch and distort the image.
I'm familiar with using CSS's background-image: url(); to create a mask in order to prevent the distortion, but I don't know what best practices are with <picture>.
My code currently stretches and distorts the image. Is there a way to 'mask' the image?
First thing you should know is that if you will give height to any image then in some screens it will stretch.
So instead of giving the height you should take the image of exact size it will do the thing.
If you can share the code I can fix it and send it to you.
Hope it helps.
User zgood was able to lead me in the right direction. Adding object-fit: cover to the <picture>'s <img> tag got the job done.

How do I change the banner on Drupal 7.x Zen theme for different viewports?

I have a site that still uses Drupal 7.x. I have a top banner that works fine on a large screen with greater than 1100px. However, that same banner will not work on smaller screens, especially not on smartphone size displays. So, if I put the banner into a block with an image tag, how can I change the source image for different display widths?
I tried using a percent width and media queries for the different background images. I haven't found a way to style the background image so that it resizes as a percent of the viewport. It will change the background image based on the media queries but I cannot get the alignment or the percent width of the background image to change with the change in the width of the viewport.
Thanks in advance for any advice on how to manage this issue. Maybe there is a module that handles changing the content of a block based on the size of the viewport.
If the banner doesn't fit on your smaller screen, try using background-size: contain or background-size: cover.
It should be possible to archieve this using CSS only, without the need to have different images in all media queries.

How to adjust an image to a carousel (Bootstrap)?

so i have this simple problem with Bootstrap but i have not found a solution to it and it goes like this: i want to have a carousel in my web page and i took the code from Bootstrap's official web page and i want to display 1200 x 400 images but if an image i want to display is not that size, it could be smaller or it could be bigger, what should i do to make that image fit on the space if it's not the size i want... i have tried with html specifying a width and a height but it doesn't work. Maybe this question is a little bit silly but i have not found a way and also i have tried to change the size of the image but it was unsuccesfull.
Thanks for the answers!
It is often recommended for slider to keep all your images same dimension. But if there is no way left to do so, you can make CSS adjustments.
For an example:
You can give same dimensions (height and width) in CSS for all those images. and use object-fit: cover; so that image does not squeeze.

Best way to make a resizable background?

Before anything, I won't provide any of my code because I don't want to use it anymore, i'd rather start fresh with some new ideas
I have to make a div that has a navbar and a background-image in CSS, resize with every resolution, I tried using VW and VH, but whenever I tried resolutions like 1280x1024 and 1024x768, the image would keep it's ratio but would only fill the page width wise, as if there was some margin or padding on top and bottom...showing that the vw and vh were not working.
So my question is, what is the best way to resize a so that the background will always fill the page, even if some of the image is cutout.
Here's an example of a website I found that works exactly the way I had in mind.
http://bigdropinc.com/
Thank you in advance
In CSS use
background-size:cover;

How to make the background image responsive

I admit in the beginning that I am new to UI development and started learning recently. I am developing a website which i similar to InuitLabs.com. When I looked at the source code using view source I am totally lost. Particularly I am interested in knowing
How the slider image on the homepage is responsive? Is it through javascript or using pure css.
Also I want to know the text moves upwards on scrolling leaving behind the background image intact? How to achieve the same effect.
I know this might be the basic question but I found it hard to know through the source code as there are many javascript and css files.
Regards,
Pradeep
Take a look at the background-size property.
you can set background-size to any px or % value or use constants:
cover will adjust the image size to fill the entire container while contain try to fit the image inside the container without cropping it, most likely leaving some parts of the container without any background.
What you probably want is to set your background-size property to cover.
you just set the image to the percent you want in % through css for example:
.slider img {
width:100%;
}
edit: also you need to specify the height as auto, if you do not want to lose the image ratio. if you set width and height at 100% the image ratio will be messed up.
if you want to set responsive height also for longer device then use width:100%; and height:100%; other wise you can use height:auto; make div and keep it background-size property for it.