Create unique image designs using CSS with full height and variable width

I've put a lot of effort into this website, but I'm still facing challenges with a few aspects. Here's the current setup:

  • Top navigation bar: 68px in height, full-width, fixed at the top.
  • Bottom navigation bar: 42px in height, full-width, fixed at the bottom.
  • Content: images of varying widths that are full-height and floated to the left.

The content is navigated through horizontal scrolling only. It's crucial that the images span from the bottom of the top nav bar to the top of the bottom nav bar without any cropping or obstruction. Additionally, it's essential that resizing the browser window or rotating a mobile device doesn't disrupt this layout. Currently, my code works flawlessly in Chrome and Safari (with one exception), but encounters issues in Firefox and Opera. I haven't tested it in IE yet. Here's what I have:

#header {
  width: 100%;
  height: 68px;
}

#content {
  position: absolute;
  top: 68px;
  left: 0;
  right: 0;
  bottom: 42px;
  z-index: -10;
  width: auto;
  height: auto;
  overflow: scroll;
  -webkit-overflow-scrolling: touch;
}

#content #frame {
  max-width: 80000px; /* (To ensure sufficient horizontal space for images) */
}

#content #frame img {
  height: 100%;
  width: auto;
  float: left;
  margin-right: 5px;
  position: relative;
  z-index: 100;
}

#footer {
  width: 100%;
  height: 42px;
  position: absolute;
  bottom: 0;
}

Essentially, I am creating a window within a window and then scrolling within that window, which causes the issue in Safari mentioned earlier. Aside from that, it functions perfectly in Chrome and Safari. However, in Firefox and Opera, the images don't scale to fit the window height.

To view the site yourself, visit: . The password is "letitrain".

I'm considering eliminating the "window within a window" approach altogether (simple and solves the Safari problem), but I can't seem to find a solution that works consistently across all browsers. Any assistance would be greatly appreciated.

Answer №1

Improved fiddle, now reflecting the latest changes: http://jsfiddle.net/XkrQg/7/

To ensure full height, include height: 100%; in #content #frame

#content #frame {
    height: 100%;
}

In the JavaScript section:
Insert this at the start of loadImages()

var frameWidth = 0;

Then insert this within loadImage()

    img.onload = function () {
        frameWidth += img.width + 5; // Consider margin-right:5px; on img as well
        $('#frame').css('width', frameWidth);
    }

This approach dynamically computes the width of #frame as images are loaded.

Add this to recalculate the new width upon window resize:

$(window).resize(function () {
    var frameNewWidth = 0;
    $('#frame img').each(function () {
        frameNewWidth += $(this).width() + 5;
    });
    $('#frame').css('width', frameNewWidth);
})
    .resize();

If needed, you can hide the vertical scroll bar during image loading by using overflow-x:hidden;.

Answer №2

Love the sleek design! Have you ever tried setting #content's top and bottom values to 0? Next, apply position: absolute to #frame with top: 68px; and bottom: 42px;. Would that produce the desired result?

Answer №3

#container #window img {

    max-height: 100%;  // making adjustments for IE

}
  • I concur with Arbel's suggestion to extend the height of #container #window, and I also suggest incorporating a clearfix for #container #window.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Determine the dimensions of child components within Svelte templates

I am currently in the process of transitioning a VanillaJS website to Svelte, and I need to have divs randomly positioned on the webpage. It's important to note that each div's size can vary depending on its content, so they cannot have a fixed s ...

Issues with the functionality of the login page's HTML and JavaScript

Recently, I attempted to create a login page with the following code: const loginForm = document.getElementById("login-form"); const loginButton = document.getElementById("login-form-submit"); const loginErrorMsg = document.getElementById("login-error-m ...

What causes the excess spacing in flexbox containers?

Is there a way to remove the padding around the container and between the two columns? I attempted setting margin and padding to 0, but it was not successful. https://i.sstatic.net/i5XJJ.jpg body, html { width: 100%; height: 100%; } main { disp ...

When using JavaScript, I have noticed that my incremental pattern is 1, 3, 6, and 10

I am currently using a file upload script known as Simple Photo Manager. Whenever I upload multiple images and wish to delete some of them, I find myself in need of creating a variable called numDeleted (which basically represents the number of images dele ...

Angular 1.4.8 Issue: [$injector:modulerr]

I can't seem to identify the main cause of this error. I consistently see a green underline below the word angular in my javascript file. I'm not sure why. (Using Visual Studio Code) HTML <html ng-app="myapp"> <head> ...

Trigger a fixed bottom bar animation upon hover

I have a bar fixed to the bottom of the browser that I want to hide by default. When a user hovers over it, I want the bar to be displayed until they move their cursor away. <!doctype html> <html> <head> <meta charset="utf-8"> &l ...

Conditional rendering of a component in ReactJS while maintaining the "empty" space

Is there a way to conditionally render a component without affecting the layout of other components? I'm trying to avoid unwanted shifts caused by this div https://i.sstatic.net/g1eUd.gif Do you have any suggestions? Here is a snippet of my code: ...

Selenium fails to recognize text

I recently embarked on the journey of learning selenium. I wrote a small snippet of code where I attempted to fetch the price of an item on Amazon. driver = webdriver.Chrome() link = "https://www.amazon.it/AMD-Ryzen-5-3600-Processori/dp/B07STGGQ18 ...

Display or conceal buttons based on the overflow height of another div

I want to dynamically show or hide buttons based on the overflow of a navigation list. If the list height overflows, display the buttons; if not, hide them. Using JQuery // This code snippet did not work for me! if($('#nav-list').prop(&apo ...

Unable to access and extract data from a dynamic website by scrolling down

I'm currently attempting to extract news from the Skynews website, which features a dynamic scrolling page. (You can access the website I'm trying to scrape through this link: https://www.skynewsarabia.com/live-story/134583... ). I am utilizing ...

Issue with Bootstrap navbar failing to collapse on iOS devices

I have been working on a website using Bootstrap and everything seems to be running smoothly. However, I've encountered an issue where the navbar doesn't collapse when viewing the site on my iPhone. It works perfectly fine when viewed on my Windo ...

Is my code error caused by floating elements to the left, right, and adding a clearfix?

Trying to align the navigation menus image with the social icons has proven to be quite challenging. As a student looking to develop a WordPress theme, I would appreciate some assistance as I am currently stuck. Any help is greatly appreciated, thank you. ...

Creating a customizable navigation bar using only CSS

I'm currently working on creating a navigation bar using only HTML and CSS, without the need for JavaScript to open and close it. However, I've encountered an issue where the navigation bar remains open even after setting display: none or visibi ...

How can I align 2 images side by side at the top and 1 beside them at the

I'm attempting to recreate an image using Bootstrap to minimize the need for additional CSS. The image I'm trying to replicate can be viewed https://i.sstatic.net/gBaVo.png. I've been struggling with the code and haven't been able to ge ...

Scroll function not functioning properly in Internet Explorer

When attempting to use scroll(x,y) in Internet Explorer 10 with JavaScript, I encountered an issue when trying to run the script on a website. Is there an alternative method that works for IE? This is part of a Java Selenium test where I need to scroll wit ...

How can you modify the color of a FontAwesome icon?

I am currently utilizing BigCommerce and my code looks like this: .icon-cart { color: #4ca3c0 !important; } .icon-cart a{ color: #4ca3c0 !important; } Despite the above, it seems that the icon's color remains unchanged. Any suggestions or i ...

Discovering uncategorized elements using javascript

Let's say I have a piece of HTML with some content that is not wrapped in any tags, like this: <html> <body> <p>text in a tag</p> other text outside any tag </body> </html> Is there a way to access the untagged el ...

How can I change it so that clicking on the YouTube icon directs me to www.google.com?

I have a YouTube icon on my website and I want it to redirect me to Google.com when clicked. However, it is not working as intended. I am trying to implement this functionality using JavaScript. HTML <div class="yt" > <i class=" ...

Getting rid of the arrow icons in a Material UI TextField

I am facing a challenge with removing the up and down arrow icons from a Material UI TextField that I adjusted using the Material UI documentation (https://material-ui.com/components/autocomplete/#autocomplete) Highlights section. After trying various sol ...

Extracting Job Titles from LinkedIn Profiles

Currently, my code is designed to search for job titles on LinkedIn (e.g. Cyber Analyst) and gather all the links related to these job postings/pages. The goal of the code is to compile these links into a list and then iterate through them to print out th ...