Utilizing CSS for Full Screen Image Clipping

While I may not be a CSS expert, I've almost got this code working the way I want it to. My goal is to create a simple page that cycles through a PowerPoint deck exported as .jpgs with just two buttons for navigation and fullscreen display of the images.

The main issue I'm facing is that the top portion of the image keeps getting cropped, even after adjusting the padding. It displays correctly at times but gets clipped when switching between images. Any suggestions on how to fix this would be greatly appreciated!

<html>
<head>

    <style>

        body, html {
            height: 100%;
        }

        .bg {
            /* The image used */
            background-image: url("Slide1.JPG");
            /* Full height */
            height: 90%;
            /* Center and scale the image nicely */
            background-position: center;
            background-repeat: no-repeat;
            background-size: cover;
        }

        .center {
            position: relative;
            vertical-align: middle;
            top: 100%;
        }

        .button {
            background-color: #0033ff; /* Blue */
            border: solid;
            border-width: medium;
            border-color: black;
            color: white;
            padding: 2px 2px;
            text-align: center;
            text-decoration: none;
            display: inline-block;
            font-size: 16px;
            vertical-align: text-top;
            height: 5%;
            width: 40%;
            font-size: 100%;
        } 

    </style>
    <script src="jquery-3.2.1.min.js"></script>
    <script type="text/javascript">
        var refreshIntervalId = setInterval(autoNextSlide, 8000);
        var clicks = 1;
        var isPaused = false;
        var time = 0;

        function pictureBack() {
            clicks -= 1;

            checkImage("Slide" + clicks + ".JPG", function () { }, function () { clicks = 1; });
            // alert("slides/Slide" + clicks + ".JPG");
            var str_image = 'background-image: url("Slide' + clicks + '.JPG");';
            document.getElementById('bkground').style.cssText = str_image
            isPaused = true;
            time = 0;
        }

        function pictureNext() {

            clicks += 1;

            checkImage("Slide" + clicks + ".JPG", function () { }, function () { clicks = 1; });
            //alert("slides/Slide" + clicks + ".JPG");
                var str_image = 'background-image: url("Slide' + clicks + '.JPG");';
                document.getElementById('bkground').style.cssText = str_image
                isPaused = true;
                time = 0;
        }
        function checkImage(imageSrc, good, bad) {
            var img = new Image();
            img.onload = good;
            img.onerror = bad;
            img.src = imageSrc;
        }
        function autoNextSlide() {
            if (isPaused) {
                time++;
                if (time > 4) {
                    isPaused = false
                };
                //isPaused = true
                //alert("is paused")
            } else {
                pictureNext();
                time = 0;
                isPaused = false;
            };

        }
    </script>
</head>
<body>


    <div class="bg" id="bkground">
        <div class="center">
            <p><input type="button" class="button" id="theButton" value="Previous" onclick="pictureBack()" style='float:left;' padding="10%"></p>

            <p><input type="button" class="button" id="theButton2" value="Next" onclick="pictureNext()" style='float:right;'></p>
        </div>
     </div>

</body>
</html>

Answer №1

Utilize:

.bg {
    /* The image being used */
    background-image: url("Slide1.JPG");
    /* Full height */
    height: 90%;
    /* Center and scale the image nicely */
    background-position: center;
    background-repeat: no-repeat;
    background-size: 100% 100%;
}

Instead of:

.bg {
    /* The image being used */
    background-image: url("Slide1.JPG");
    /* Full height */
    height: 90%;
    /* Center and scale the image nicely */
    background-position: center;
    background-repeat: no-repeat;
    background-size: cover;
}

Cover makes the image cover the entire element but it cuts off the image. Using 100% 100% ensures the image fits fully regardless of the device. It may slightly distort the image on some devices, but if mobile compatibility is not a concern, this approach should suffice.

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

Is there a way to navigate to an external website by clicking a button in Next.js?

<button type="button" className = {styles.googleButton}> <img className = {styles.image} src = "assets/pictures/google.jpg"></img> <p className = {styles.buttonText}> Go To Google</p> <img ...

The for loop encountered an uncaught type error when trying to access the .length property

Currently, I am working on a school project where the task is to create a basic social network posting application using Django and JavaScript. The purpose of using JavaScript is to dynamically load posts onto the webpage and update HTML components. I have ...

The mysterious button that reveals its text only when graced by the presence of a

The text on the button (Remove in this case) will only show up when the mouse is hovered over it. This issue is occurring in an angular project and despite trying to apply CSS for .btn, it does not get overridden. background-color: blue; Button's ...

What is the best way to connect CSS properties to an image using JavaScript?

I recently used JavaScript to insert an image into a webpage, but I'm unsure of how to make changes to it or position it properly. Is there a way to connect CSS styles to the image, or is there another method to modify it without relying on CSS? < ...

Leveraging JQuery for activating an event with Bootstrap Scrollspy

I'm facing a challenge in capturing the Scrollspy event to execute a specific function. The Scrollspy feature is functioning correctly in terms of updating the active link on the navbar. However, I am struggling to capture the event for use in other p ...

Creating geometric designs on an image and storing them using PHP

I am attempting to retrieve an image from a specific location on my server, draw lines on it, and then save the modified image back to the same location. Below is the code I am using: function drawShapes($src_path, $json) { echo "---inside dra ...

Shift attention to the subsequent division after a correct radio option or text input has been submitted

I need to enhance the user experience on my form. When a user interacts with specific elements like hitting enter in a text input or clicking a radio button, I want to automatically focus on the next "formItem" division. My form structure is organized as ...

Bootstrap CDN causing modals to fail to appear

Here are the stylesheets I am currently using: script(src="/js/application.js") script(src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js") script(src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js") link(rel="styl ...

When CSS width:auto expands beyond its intended length

I'm experiencing an issue when I set the width to auto, the div expands to full length rather than adjusting to the width of the inner divs. Here is the HTML code: <div class="vidswraper"> <div> <div class="videoimage"> <img src ...

Exploring the process of retrieving outcomes from Node.js within a Knockout ObservableArray

Below is the Node.js code snippet I have: var http = require('http'); var port = process.env.port || 1337; var MovieDB = require('moviedb')('API KEY'); MovieDB.searchMovie({ query: 'Alien' }, function (err, res) { ...

Retrieve webpage using HTML stored in web storage

I am exploring a new idea for an application that utilizes local storage, and I am seeking guidance on the most effective way to load content after it has been stored. The basic concept of the app involves pre-fetching content, storing it locally, and the ...

The HTML table is not displaying properly due to colspan being used incorrectly

A table has been created with all headers having colspan=2 and some body cells having colspan=N. In certain instances, the display is not rendering correctly: https://i.sstatic.net/xARV6.png td, th { border: solid #aaa 1px } <table> <thea ...

Adjusting the height of a table cell in HTML: td without making it

Here's the issue I'm facing: I have an HTML <table> with a fixed height of 100px and no border. Inside this table, there is one row (with a 100% height) containing 5 td elements (each also with a height of 100%). Within each td, there is a ...

What is the best way to insert a hyperlink into a specific piece of text?

Here is a list of elements: <ul> <li> <a href="#link1">Text link 1</a> <span>My text contains text: Text link 1, that's it.</span> </li> <li> <a href="#link2">Text link 2</a ...

Modify the appearance of an image by hovering over the ::after element for image styling

My design involves a main image with a smaller arrow image overlaid on top, achieved using a pseudo after-element. Currently, when I hover over the main image, the opacity changes as intended. However, the issue arises when hovering over the arrow image o ...

Tips for implementing secure password validation and confirmation in HTML 5 forms

I am utilizing a script that mandates users to input a password with a capital letter, lowercase letter, and number. <input title="Password must contain at least 6 characters, including UPPER/lowercase and numbers" type="password" required pattern="( ...

The art of maintaining session persistence in hybrid applications

Currently, I'm working on mobile development for Android and have a functionality in my app where clicking on an item opens up a browser window redirecting to a specific link. While this feature is functioning properly, the issue arises when returning ...

how to change class on vue function result

I need a way to display the content stored in requestData as li elements. Each list item should have an onclick function that, when clicked (selected), adds a specific value from a reference to an array. If clicked again (unselected), it should remove the ...

Creating a form element in JavaScript and submitting it - step by step tutorial

Is there a way to redirect to a different page once a JavaScript process running on the current page is finished? The issue here is that only JavaScript knows when it's complete, and I'm using Python (Flask) as my web framework. One solution I th ...

Employing ng-style for establishing background when the value does not align

Greetings all! I am using ng-repeat to create a list of items within a ul element. Within the json data, there is a specific value that I want to highlight if it does not match a predefined string. Here's what I have so far: ng-style="{'backgro ...