The min-width of 100vh is functioning properly on mobile devices, however, it is not working as expected on PCs when set to 100

When using 100vh, it only works on mobile or if you narrow the width of your web browser on a PC. If the window/width is set at 100%, the image may appear too tall and cause the div class "mars" to overflow the viewport.

Unfortunately, screenshots cannot be posted at this time.

Below is the code snippet:

<div class="mars">
                <img  class="mars" src="img/marshero.jpg">
                <div class="greet">
                    <a href="https://solarsystem.nasa.gov/planets/mars/overview/">
                        <p class="inf">Click here to learn more about Mars at solarsystem.nasa.gov</p>
                    </a>
                </div>
                <nav class="menu">
                    <ul class="inline">
                        <li class="inline"><a href="../index.html">▶About me</a></li>
                        <li class="inline"><a href="ProductDesign/index.html">Product design</a></li>
                        <li class="inline"><a href="Research/index.html">Research</a></li>
                        <li class="inline"><a href="ProductDevelopment/index.html">Product development</a></li>
                    </ul>
                </nav>
            </div>

div.mars {
    min-height: 100vh;
    overflow: auto;

    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

img.mars {
    flex: 1 0 auto;
    max-width: inherit;
    max-height: inherit;
    height: inherit;
    width: inherit;
    object-fit: cover;
}

/* nav */

nav.menu {
    background-color: #f9eae2;
    padding: 16px;
    @media only screen and (max-width: 1050px) {
        padding: 0px;
    }
    
}

ul.inline {
    text-align: center;
    @media only screen and (max-width: 1050px) {
        text-align: left;
    }
}

li.inline {
    display: inline;
    padding-left: 16px;
    @media only screen and (max-width: 1050px) {
        display:list-item;
        padding-top: 8px;
        padding-bottom: 8px;
    }
}

Answer №1

To address this issue and ensure that the image does not become too big, here is the revised CSS code snippet for your img.mars class:

 img.mars {
flex: 1 0 auto;
max-width: 100%; /* Set the maximum width to 100% of the container */
max-height: 100%; /* Set the maximum height to 100% of the container */
width: auto; /* Allow the image to adjust with the container width */
height: auto; /* Allow the image to adapt with the container height */
object-fit: cover;

}

Answer №2

If you are experiencing an issue with your image overflowing when the window width is set to 100%, here is a solution that you can implement by adjusting your CSS:

div.planet {
    min-height: 100vh;
    overflow: hidden; /* Modify from "auto" to "hidden" */

    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

/* Ensure the image covers the entire viewport */
img.planet {
    width: 100%; /* Utilize 100% width for optimal fit in viewport */
    height: auto; /* Maintain aspect ratio of the image */
    object-fit: cover;
}

/* Introduce a container for your content to prevent overflow */
.content-holder {
    padding: 16px; /* Adjust padding according to your requirements */
    box-sizing: border-box; /* Incorporate padding in the total width of the element */
}

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

Circular center button in the footer UI

Struggling with aligning a button in the footer perfectly? I have two icons on each side and while the UI is almost there, something seems off with the center icon's padding and shadow. I'm currently working with material-ui. Take a look at the i ...

What is the reason that when we assign `'initial'` as the value for `display` property, it does not function as intended for list elements?

To toggle the visibility of elements, I have created a unique function that accepts an object and a boolean. Depending on the boolean value, either 'none' or 'initial' is assigned to the 'display' property of the specified obj ...

Styling certain UL and LI elements with CSS properties

Greetings everyone! I constantly struggle when it comes to making my CSS cooperate. I have some code that involves using ul and li tags. However, I only want to apply that styling to specific sections of my HTML code rather than all instances of the ul and ...

Basic node.js server that responds with HTML and CSS

I have successfully created a basic http server to send an HTML file as a response. However, I'm struggling with how to also send a CSS file so that the client can view the HTML page styled with CSS in their browser. Here is my current code: var htt ...

Utilize jQuery and JSP (or PHP) to showcase detailed information about a specific item when a user clicks on it within an HTML page

For my upcoming college project, I am tasked with developing a movie library. The main page of the library will feature various movie posters. Upon clicking on a poster, users will be directed to a dedicated page displaying detailed information about the ...

Is it possible for the ".filter" function to verify if the target contains multiple attributes?

I'm currently working on a checkbox filter setup and using Jquery's .filter to sort through some divs. Below is the snippet of Jquery code that I am using: $(document).ready(function(){ var checkboxes = $('div.filter-groups').find(&ap ...

Ways to configure a select-multiple element to send data as an array

I am experiencing an issue with a form I have set up. Here is the current code: <form method="post" action="action.php"> <select id='select' multiple='multiple'> <option value="1"> Option1 <option> ...

Output text in Javascript (not to the console)

I'm on the lookout for a way to welcome a user by their name when they enter it into a JavaScript application. I have tried this code snippet: function getname() { var number = document.getElementById("fname").value; alert("Hello, " + fnam ...

What is preventing my boolean from being altered?

Creating a basic calculator that can handle single-digit arithmetic. The current code is incomplete and redundant, so please avoid commenting on that. <!doctype html> <html> <head> <title>JavaScript Learning Zone</title> ...

When hovering over an element, I must utilize a selector and reference a variable that was defined outside of the hover state in order to

Explaining this code may be a challenge, but I'll give it my best shot. Here's the code snippet: $('#navibar a').hover(function(){ var position = $(this).position(); var width = $(this).width(); $('#underliner'). ...

What is the best way to vertically align my image for perfect centering?

On one of my pages at , there is a section titled "FREE PICK UP AND RECYCLING OF LARGE QUANTITIES OF ELECTRONICS" with a picture of a truck. The image is perfectly centered vertically between the pictures on its left and right. Another page I have at fea ...

The nodejs https website is unable to render in Internet Explorer 11

Our secure website is not loading in IE11 (dnserror.html - page cannot be displayed). However, it works perfectly fine on all other browsers! The webserver we are using is a node.js app with default cipher settings. The SSL certificate is valid and enhan ...

Ways to remove all HTML elements from a string

Check out the code that I currently have: I am looking for a way to prevent users from entering any HTML tags in the "Add Responsibilities" field. For example, if a user enters the following: <div>Test</div> It should only display the text l ...

Initiating CSS animation from the start

Having an issue with the "Start button" that plays both animation and background sounds. When I pause it, the animation does not stop where it left off and starts from the beginning again. I tried using animation-play-state: pause and animation-fill-mode: ...

What is the best way to include a JavaScript variable in an HTML image src tag?

Even though I know the answer to this question is out there somewhere, I just can't seem to find it (or maybe I'm not recognizing it when I see it!). As a beginner in jquery, please be patient with me. Dilemma: I have a collection of 20 images, ...

What is the best way to implement a sub-menu using jQuery?

After successfully implementing a hover effect on my menu item using CSS, I am now struggling to make the sub-menu appear below the menu item upon hovering. Despite my efforts to search for jQuery solutions online, I have not been successful. Are there a ...

What is the best way to save a PDF from within a frame using JavaScript and an HTML5 <embed> tag?

I'm looking for assistance with a script for my website that dynamically generates a PDF after the user makes selections in one of the frames. The website uses the HTML5 tag to display the PDF file. Can anyone provide guidance on a script that can: ...

A step-by-step guide on serializing a model and sending it to an MVC controller through an Ajax

I need to transfer the model of my webpage to my controller for processing. Once the information has been processed, I want to update the div with the id "savedText" to show "Billing Information saved successfully." Here's what my view looks like: ...

Click to dynamically toggle classes with jQuery

I am trying to apply a class called 'select' when I click on a paragraph tag. However, the code I have written doesn't seem to be working. Can someone please provide some suggestions? Here is the code: <style type="text/css"> #el ...

Why does jQuery's each function struggle to retrieve the width of hidden elements?

Why is it difficult to obtain the width of hidden elements? Here is my code: .hidden { display: none; } <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script> <ul class="navbar-items"> <li> ...