How to make this banner slider to fit the browser height? - javascript

I googled for 2 days trying to understand how the auto height fit works, I think I understand in how to make a background fits the browser, but with this banner slider, I don't have a clue.
Could someone please enlighten me on where should I look for/start? Should it be a CSS or JS?
I'm very new to HTML5/CSS3, Wordpress gave me a very easy environment to start a website, but I just barely know how to modify a website other than a plugin.
It would be very cool if the slider section to fit like this one below
Thanks in advance!

This should set the image/album you have on the homepage to be the height and width of the browser, tweak some of the CSS and it should line up with the Sidebar perfectly like you wanted.
img {
max-width: 100%;
height: auto;
width: auto\9;
}

If you are looking for the image that fits the browser height regardless of any display then you can use 'vh' unit from this css units page.
vh means viewport height[viewport = the browser window size.], and 1vh = 1% of the height of viewport, so in your case you can use 100vh for image like this:
img{
height: 100vh;
}
Check this jsfiddle for the same.
Remember that you need high-resolution images and those images will not look good on mobile devices.

Related

(total html novice) How to keep webpage from having a scroll bar and instead resize the site to fit within the browser window?

My main issue is that when you click a button on my site (www.typo.video) it takes you to a different page of the site but it jumps back to the top when I'd like for the view not to change relative to the background. The obvious solution to me is to not allow the page to overflow and instead have the whole site scale to the size of the window (similar to using ctr +/- in the browser to zoom), but I cannot figure out how.
I've tried a few solutions, but it's possible I didn't implement them correctly because I am not coding the site from scratch. I am using a website builder through NameCheap and I don't always know what folders/files I should be editing the code in to affect certain aspects of the site. I am a fast learner and have some limited coding experience but I only started messing with html/css in the past few days.
I think this solution could work from the sounds of it, but if I'm not mistaken I would need to essentially put the whole site into a container and I am not sure where amongst the files I would implement that.
If anyone has a solution it would be helpful to know what I am looking for in terms of where to put the code/what phrases I should be looking for. (See image of relevant folder structure).
You need to edit this id, replace the values with the commented ones.
#wb_main_11 {
width: 1920px; /* 100% or 100vh */
height: 1080px; /* 100vh */
/* once you change the above, you probably don't need the ones bellow */
min-width: 1920px; /* 100vh or 100% */
min-height: 1080px; /* 100vh or 100% */
max-width: 1920px;
max-height: 1080px;
flex: 1 1 auto;
}
Also the image your have a "max-width: 100%" rules, after doing that, the button are the last element making your page to overflow, so reposition them

Chrome stretches website images, Edge, IE, Firefox not

I find it hard to figure out why the images on the home page of https://www.kerkradio.za/index.php show up stretched. I am no boffin at CSS or so, but in IE, FF, and Edge they are all showing the images fine. I found one reference to a solution here (Chrome is stretching my images vertically, however everything works fine in Firefox/Edge), but it did not help really.
I have had a look at instances where the image height and width are set to auto and changed it to 100% instead. No luck. I am sure I am missing something in the css-es.
Please refer to the code of https://www.kerkradio.co.za/index.php. Scroll down to where all the church image cards are displayed.
I have been at it for more than 3 hours now.
I guess you need remove height from this selectors:
.card-img img
Look like some different behavior flexbox and image calculation size. So img contains:
width: 100%;
height: 100%;
chrome expands image to 100% original height, while firefox image resize to 100% container height

Make an image responsive by height AND width

I am working on a site for a client, using a purchased Wordpress theme (so all the code is not necessarily mine, but I can pull something if needed).
The landing page has a responsive background image. On top of that, I need to use images to show the relevant logos (the fields where I input this were intended for text, but they allow images with no problem). The image has a border wrap around it also, and then people can scroll down from there to see the rest of the content.
My problem: on desktop, the logos will rescale with the WIDTH fine. But one of my clients is viewing in a very widescale-oriented browser window (which I figure is unusual across all users, but it's the client!), and the logos do not rescale with HEIGHT changes, so they get cut off by the border wrap.
I've tried things like
.home-section img {
max-height: 50%;
}
Which is what the theme's developer provided initially, and also changed 50% to 50vh (just trying some things I came across online, not a code expert by any means), and also a variation of this solution HERE
with no luck.
My (again, partial) understanding is that since the height of the div with the background image isn't set explicitly, I can't use a percentage height for the logo/child element, but is there a way to solve this?
I'm currently using srcset to get the logos the right size for mobile, but that's not a perfect solution. I figured there may be a javascript solution too, but I'm only about 75% with HTML & CSS and not much with JS/PHP without explicit directions. (Call it capable, but inexperienced).
You can view the issue HERE.
Thank you!
=================================================
EDIT:
A coworker came across this solution, which improves things greatly. The issue still happens at a short enough browser (IE landscape phone viewing, etc), but works on a greater range of viewport sizes:
div.home-section-image {
min-width: 600px;
max-width: 1080px;
min-height: calc(690px * (90/150));
height: 100vh;
width: 100vh;
}
The logos now scale vertically to a point, though the viewport height can still catch them and cut them off, but at a better threshold (at ~550px high, where it happened at ~720px high previously - now well beyond a normal person's minimum browser size, my understanding is ~760px is average).
I tried to combine this with #kburgie's code suggestions to keep the logos completely above the green border, but my results ended up pushing the logos off the TOP of the page instead, which is worse (for me, on a horizontal Galaxy S3, I can at least get the main square of the top logo to display, which is enough for me at that size).
Thanks to everyone who helped - I think this may be the best solution I can pull for now!
Seems like you should be able to combine width and height media queries to catch that edge case:
#media (min-width: 1200px) and (max-height: 500px) {
.home-section img {
height: 200px;
width: auto;
}
}
I don't have enough rep to comment or I would. I think isherwood's media query is too specific.
Responsive images should already be responsive by height AND width, and the best way to handle that is by working with the image width.
This is a dangerous selector and you should get rid of it:
img {
height: 100%;
width: auto;
}
It will affect ALL images on your site. You should use a class instead. Beyond that, your images are already set to max-width: 100%, which is all you need.
Focus on your positioning instead
Step 1: Remove your margin top and bottom
.home-section .container { margin: 0 auto; }
Step 2: Absolutely position the image container at the bottom of it's parent. Then it will always stay above the green border. Stick it in a media query if you'd only like this positioning above a certain screen size.
.home-section-image {
position: absolute;
bottom: 10px;
}

Resizing images to fit smaller browsers

I've been searching the questions here for weeks and haven't found an answer to this, so here it goes:
I created a fairly large image (800x1000px) to be displayed in the center of my site. I made it so large with large screen resolutions in mind but I've been using the CSS max-width: 100%;
max-height: 100%;
to have it resize proportionally to fit on computers with smaller screen resolutions as well. (keep in mind this is not a "background" image)
However, what I'd really like, is for the image to resize only when keeping it at the current size would create a horizontal scrolling bar in the user's browser. However, if it will only make a vertical scrolling bar, I'd like it to not resize the image, that way it can be as large as possible (the reason being that I feel a horizontal scroll is less professional looking than a vertical scroll as most sites have a vertical scroll anyway).
Is there a way to accomplish this with CSS or will I need Javascript? And if I'll need javascript please spell out the code as I have absolutely no experience with javascript, thanks!
Just remove max-height: 100%, leaving only the max-width: 100%.
Demo
img {
max-width: 100%;
height: auto;
}

Better way to auto resize images mantaning aspect ratio?

I am using this code to auto resize images to the window size on a mobile page:
img {
width:100%;
max-height : auto;
max-width : 480px;
}
My intention is to show the image in the right size of the window on small screens and max 480px on bigger screens maintaining the ratio.
But for some reason i dont know when i use that code the text around the image goes behind it.
Theres a way to achieve this result using another method like Java or Jquery and avoid this problem?
If you do this for mobile devices I would recomend server resize to save download size.
Regarding the text that goes behind, do you have a more comprehensive testcase showing the actual document this CSS applies to?
You'll end up with squished images if you do that. I think this gives the best result you can achieve with CSS:
#content img {
width: 100%;
height: auto;
max-width: 480px;
}
I added this code in my page and it's working:
img {
width:100%;
max-height : auto;
max-width : 480px;
}
Have you tried using different style sheets for different screen sizes? Then you would just need to write the code for each situation and then load the needed style. It would also come in handy if you have other styles that need to change based on size. Very helpful on mobile sites.
<meta content="width=device-width, initial-scale=1.0" name="viewport">
helps to make sure it scales right. Not sure how helpful it will be, but hope this link helps.
CSS trick for specific style sheet
I've also played around a little, and it seems to work if you set the image as a percentage. I floated one to the left of text and at 50% of the screen and it re-sized text and all. If you need me to post an example, just ask.
use #media to do manual change by the mobile, tablet or desktop size.
by the way mobile and tablet will have landscape and portrait. if you using google chrome to check you can determine it better. sample of website : Media Queries: How to target desktop, tablet and mobile?

Categories