css - Dynamic height with static content - css

I have found a good solution for Swiper with the gallery and it works great but there is a problem with height on mobile devices:
I have tried to replace this height: 500px to any dynamic but every time it's hiding without status height. Is there any solution to make it scalable without media queries?
https://jsfiddle.net/vertisan/j8a46vcg/1/

What about this https://jsfiddle.net/q1vr473z/ if u want just give max height
html,body,.container{
height:100%;
width:100%;
}
#slider {
height: 80%;
max-height:500px;
}

Change the background-size
.swiper-slide {
background-size: auto 100%;
background-position: center center;
background-repeat: no-repeat;
}

Related

What I'm doing wrong? "responsive page"

I have a container and wallpaper inside a page.
What I'm trying to do is to resize the container and the wallpaper to mach any device screen size.
I have managed to make the wallpaper working, but the container doesnt work for me.
What I'm doing wrong?
This is my code:
html,body{height:100%}
#left-link {
position: fixed;
top:0;
bottom:0;
left:0;
right:0;
z-index:99;
width:auto;
height:auto;
}
#container {
width:500px;
margin:0 auto;
margin-top:10px;
position:relative;
z-index:100;
}
body {
margin: 30px 0 0 0;
background: url(https://example.com/.jpg) no-repeat center center fixed;
background-repeat: no-repeat;
background-position: center center;
background-attachment: fixed;
background-size: cover;
}
The container is set at 500px, which is a set size. If you want it to be responsive, set it to a percentage such as 50%, which would be half of the page.
You seem to have hard-coded the container to remain 500px at every viewport width.
This can be solved by the more general solution of never using absolute units for anything.
Anything like "px", "in", "cm" are absolute units and should be avoided.
Instead use relative units: "em" (or if you must, "rem") when legibility is the main concern (e.g. reading some lettering in an image); and "%" (or "vh" and "vw") when overall layout is the main concern.
Your example has "500px", "10px", and "30px".
It would be more "responsive" if instead it had, say "90%", ".5em", and "4%".
And to make things fit into containers the way you would expect them to:
* { box-sizing: border-box; }

"Background-image: cover" broken on mobile

I'm trying to make the image on my site to display 100% height but crop width as needed. On PC the site works as intented as can be seen below:
However when I check the site with my phone it displays the whole image distorting it.
HTML:
<header class="wide">
</header>
CSS:
body, html {
height: 100%;
}
.wide {
width: 100%;
height: 100%;
background-image: url('sebastian-unrau-42537-unsplash.jpg');
background-size: cover;
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
}
#media (max-width: 1199.98px) {
.wide {
background-attachment: scroll;
background-position: initial;
}
}
The media query is mandatory as the image doesn't work at all if the background-image is fixed and centered.
Now if I remove "background-size: cover":
It's kind of closer what I'm after but not quite. Am i missing something?
My PC is running Chrome 66.0.3359.117 and my phone 65.0.3325.109
Ok I figured it out by accident. I was using an image from Unsplash.com and the the original resolution is 6000x4000. As I was making a Codepen project to post here I resized the image and wondered why it worked on codepen but not on my pc. Well it seems the resolution needs to be about 5500x3667 or smaller to work.
Maybe there is a limitation I did not know of but anyway got it working now. I didn't change anything else.
You could use this property :
background-size: x% y%;
The first value is the horizontal position and the second value is the vertical.
So you can try :
background-size: auto 100%;

CSS: Make image height of viewport while keeping width 100% and cropping edges if wider than viewport

I want to create a responsive image that takes up the entire height off the viewport and scales as the viewport changes.
I know that I can set the height with this:
height: 100vmax;
However, I cannot understand how to get the image width to change and effectively crop it's edges off so that the image stays centred horizontally.
A great example of is Big Green Egg's website although they use a video and I want to use an image.
It's worth mentioning that I need to enter this code into a CMS page (Magento 2) so it will sit within a set of other DIVs.
Try to use "vh" and use text-align on the outer container to center the image:
body {
text-align: center;
}
img {
height: 100vh;
}
<img src="http://kingofwallpapers.com/sexy-girl-wallpapers/sexy-girl-wallpapers-002.jpg">
But I would recommend to use background-image instead, since it's a part of design, not a content:
* {
margin: 0;
}
.image {
position: absolute;
top: 50px;
bottom: 0;
left: 0;
right: 0;
background: #e0eaec url(http://eskipaper.com/images/mikako-zhang-5.jpg) no-repeat center center / auto 100%;
}
h1 {
line-height: 50px;
text-align: center;
}
<h1><header> goes here</h1>
<div class="image"></div>
I'd go very simple here, with a css solution based on adding only object-fit and an optional object-position, very useful when the main point for adjustment is not the center of the picture
html
<img src="https://images.unsplash.com/photo-1518453850752-056b15f0a4ea?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1950&q=80">
css
img {
float: left;
width: 100%;
height: 100vh;
object-fit: cover;
object-position: 75% 75%;
}
Try to reduce the width of the picture in this JSFiddle: you will see that the focus will keep always around the dome. I suggest also to read this gem
By default, object-position: 50% 50% [i.e. the center of the picture] so in this case you don't need to specify it
NOTE - you can check their support on different browsers here

Responsive height for Background-Size Image CSS

I have a responsive background image with the following properties
background: url( '#{sitePath}/main_banner.png') center no-repeat;
max-width: 100%;
z-index: -10;
height: 475px;
background-size: contain;
The image needs to be able to scale down (as it does currently) but without a massive height (475px) for smaller devices. 100% min & standard height do not work and I want to avoid specifying individual heights for different media queries if I can help it.
Does anyone know how I can make this effectively responsive?
Thanks
You have put static height: 475px; If you want to have smaller height on smaller device try using media queries:
#media (max-width: size-that-you-want){
.class-name{
width: some-number;
}
}
This should work.

How to make the image not to crop?

How do I make my background image in the body not to crop when it resizes the window? The site it responsive and the image dosen't resize it juts crops off bits of it. I tried using position:fixed but it didn't work. What code do you need to help me?
This it the code for that wrapper:
.body-wrapper {
background-image: url('http://promegaekonomi.se/wp-content/uploads/2014/09/82.png') !important;
background-repeat: no-repeat;
background-size:100% auto;
}
http://jsfiddle.net/yg17acL0/
Try to use the img tag inside the div.
.responsive {
max-width: 100%;
height: auto;
}
Try this CSS: background-size:contain
Working LINK
(Updated)

Resources