Tips for centering a resized image within a container:

I adjusted the width and height to "max" for my images inside the container, and while wider images fit perfectly, taller ones seem to shift left of the container. I tried researching about adjusting using "max-width" but still facing issues. Here's the code snippet:

#top-bar{
                background-color: 54D954;
                width: 100%;
                height: 45px;
                margin: 0 auto;

            }
            body{
                padding:0;
                margin: 0;

            }
            h1{
                color:white;
                font-family: "Comic Sans MS", cursive, sans-serif;
                text-align: center;
            }
            #container{
                max-width: 1000px;
                max-height: 700px;
                margin: 0 auto;
                margin-top: 55px;

            }
            #bottom-bar{
                width: 700px;
                height: 75px;
                margin: 0 auto;
                margin-top: 45px;

            }
            #left{
                width: 100px;
                height: 100px;
                float:left;

            }
            #right{
                width: 100px;
                height: 100px;
                float:right;
            }
            #img{
                max-width: 1000px;
                max-height: 700px;

            }
        </style>
        <body>

            <div id="top-bar">
            <h1>KidsWow Pictures</h1>
            </div>

            <div id="container">
                <img id="img" src="todaypics/img1.jpg"> 


            </div>

            <div id="bottom-bar">
                <img id="left" onClick ="slides(-1)" src="Pictures/trans-left.png">
                <img id="right" onClick ="slides(1)" src="Pictures/trans-right.png">


            </div>



        <script type="text/javascript">
            var numbercounter = 1
            var total = 30

            function slides(x) {
                var Images = document.getElementById("img");
                numbercounter = numbercounter + x;
                if (numbercounter>total) {
                    numbercounter = 1;
                }
                if (numbercounter<1){
                    numbercounter = total;
                }
                Images.src = "todaypics/img"+numbercounter+".jpg";
            }   




            </script>
        </body>

Answer №1

Ensure that the image is centered within your designated container.

        #container{
          margin-top: 55px;
          text-align: center;
        }
        #container img {
          max-width: 1000px;
        }

var numbercounter = 1
var total = 30

function slides(x) {
  var Images = document.getElementById("img");
  numbercounter = numbercounter + x;
  if (numbercounter>total) {
    numbercounter = 1;
  }
  if (numbercounter<1){
    numbercounter = total;
  }
  Images.src = "todaypics/img"+numbercounter+".jpg";
}   
#top-bar{
                background-color: 54D954;
                width: 100%;
                height: 45px;
                margin: 0 auto;

            }
            body{
                padding:0;
                margin: 0;

            }
            h1{
                color:white;
                font-family: "Comic Sans MS", cursive, sans-serif;
                text-align: center;
            }
            #container{
              margin-top: 55px;
              text-align: center;
            }
            #container img {
              max-width: 1000px;
            }
            #bottom-bar{
                width: 700px;
                height: 75px;
                margin: 0 auto;
                margin-top: 45px;

            }
            #left{
                width: 100px;
                height: 100px;
                float:left;

            }
            #right{
                width: 100px;
                height: 100px;
                float:right;
            }
            #img{
                max-width: 1000px;
                max-height: 700px;

            }
<body>

            <div id="top-bar">
            <h1>KidsWow Pictures</h1>
            </div>

            <div id="container">
                <img id="img" src="todaypics/img1.jpg" /> 
            </div>

            <div id="bottom-bar">
                <img id="left" onClick ="slides(-1)" src="Pictures/trans-left.png" alt="left" />
                <img id="right" onClick ="slides(1)" src="Pictures/trans-right.png" alt="right" />
            </div>
</body>

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

Searching for a specific element in jQuery by querying a string

I have a situation where an ajax request is made to send text using the POST method to another PHP page. This PHP page then converts the text into markdown format and sends it back. Here's an example of what it looks like: "<p>Meep, meep, <e ...

A guide on calling a function from a different component in vuejs2

I am facing a situation where I need to trigger an event whenever my sidebar opens. This event should be called every time the sidebar is opened. For example, when I click on an element, it triggers the opening of my sidebar which then calls a function th ...

Submit a HTML form to a Telegram recipient

I am looking to send HTML form data, which includes input values and select options, to a telegram user. After some research, I discovered that I need to create a Telegram bot. I successfully created one using @botFather by following these steps: /newbot ...

The Reduce function is generating NaN when retrieving an object from an array in a MongoDB database and displaying it on a

The Schema I'm working with looks like this: const SubmitDebtSchema = new Schema ({ balance: [{ balanceDate: Date, newBalance: Number }], }); I'm currently trying to iterate through the database entries, extract the 'newBalance& ...

How can I show the unique phrase "Today" on a specific date (date=today) with the Angular-UI-Bootstrap Datepicker?

I'm currently integrating the Angular-UI datepicker directive into my project and I'm facing an issue. I want to have the datepicker display 'Today' instead of the actual date like 2015/04/27. Is there a way to achieve this without hav ...

Issues with routing in Node.js using Express

This is my first attempt at programming. I am currently in the process of setting up routing in the following way: var indexRouter = require('./routes/index'); var loginRouter = require('./routes/login'); app.use('/', indexRo ...

A guide on removing an element from a state array in a React functional component for a To-Do List application

I need help making a to-do list item disappear when clicked. The deleteHandler method is not working as expected. Can anyone provide logic on how to filter out the clicked item? import React, { useState } from 'react'; const ToDoList = () => ...

One way to change the cursor CSS property is by dynamically altering it based on scrolling behavior. This involves modifying the cursor property when scrolling

I'm attempting to adjust the cursor property within an Angular function. The issue I'm facing is that when I begin scrolling the webpage, the cursor changes to a pointer, but when I stop scrolling, it remains as a pointer. I've attempted to ...

What are the recommended techniques for utilizing prototypal and prototype-based inheritance in modern JavaScript (ES6) and TypeScript?

Some older discussions on Javascript prototypal inheritance & delegation can be found below: Benefits of prototypal inheritance over classical? classical inheritance vs prototypal inheritance in javascript I am curious about the current (2018) recom ...

Could there be an issue with the couch-nano changesReader batching, or am I overlooking something important?

This particular issue is related to the changesReader API within the couchdb-nano library. Expected Outcome In theory, the code below should wait for 10 seconds before returning a batch of messages from the most recent position in the changes feed. For in ...

Type of result from a function that returns a linked promise

In my class, I have a method that returns a chained promise. The first promise's type is angular.IPromise<Foo>, and the second promise resolves with type angular.IPromise<Bar>. I am perplexed as to why the return type of doSomething is an ...

I require assistance in obtaining the float value for the CSS property of 'font-size'

Can someone help me with retrieving the float value of the CSS 'font-size'? It works perfectly in Firefox, but I'm facing issues in Chrome, Safari, and IE. When trying to get this CSS value, it keeps converting to an integer instead of a flo ...

adjust bootstrap column width to fill the container

https://i.stack.imgur.com/tCuL6.png I am hoping that this image will provide a visual aid for what I am trying to convey. My goal is to have the arrow and the boxes aligned in a row without any empty space on the right side. As you can see, the leftmost b ...

Node replication including a drop-down menu

Is there a way to clone a dropdown menu and text box with their values, then append them to the next line when clicking a button? Check out my HTML code snippet: <div class="container"> <div class="mynode"> <span class=& ...

Changing the background color of UILabel in iOS with a rounded rectangle design

I am looking to create a design similar to this concept. https://i.sstatic.net/7ZQi3.png One approach is to achieve this by inserting an image (for "PDF"). NSTextAttachment *attachment = [[NSTextAttachment alloc] init]; attachment.image = [UIImage image ...

Personalized Bootstrap grid rows and columns

https://i.sstatic.net/R0yFY.png As a beginner in Bootstrap, I am having trouble achieving this specific layout in Bootstrap 4 grid. The areas marked in red are not appearing as expected. Here is what I have attempted so far: <div class="row"> ...

Update the button text after it has been clicked

https://i.sstatic.net/QJALK.png In my code, I have a function that generates bootstrap rows, each containing an input field, textarea, and a remove button. As I call this function multiple times, I end up with several bootstrap rows. When clicking on the ...

Importing JWT in ES6SyntaxCreating ES6 imports

I'm currently developing a nodeJS web application and utilizing JWT for authentication. My code is all written in ES6 modules, so I wanted to import JWT the same way. However, it seems that the package does not fully support this method yet. Since I&a ...

Unexpected error occurs when modifying HTML5 video source using JQuery on Internet Explorer

Currently, I am working on developing a web application using asp.net, Bootstrap, and JQuery. While testing it on LocalHost, I encountered an issue that needs debugging. The navigation bar of my application has a dropdown menu with links to tutorial video ...

Expanding declaration files in TypeScript to include third-party libraries

Is there a way to customize third-party declaration files? For instance, I am looking to enhance Context from @types/koa by adding a new field (resource) to it. I attempted the following: // global.d.ts declare namespace koa { interface Context { ...