The image does not resize properly even when placed directly within the .col element

Currently, I am working with Bootstrap 4.1.3 and having an issue where my image does not scale up to the height of the row. Can anyone point out what I might be doing wrong in the following code?

<div class="container">
    <div class="row top-logo">
        <div class="col text-center"><img src="logo.png" class="img-fluid"></div>
    </div>
</div>

The CSS used is as follows:

.top-logo {
height: 200px;
}

It's worth noting that my logo image is a 100x100 png file.

Answer №1

I may not be an expert in CSS, so please excuse me if I'm unable to provide the most comprehensive explanation. The img-fluid class normally includes a height: auto property, but for some reason it's not working as expected in this case. However, setting height: 100% seems to do the job. In Bootstrap, you can use the h-100 class to achieve this effect. Give it a try by adding this class to your image.

<img src="logo.png" class="img-fluid h-100">

Answer №2

.img-fluid has a height of "auto". To scale the image by its height, you need to specify a width for the image

.top-logo img{
  height: auto;
  width:100%;
  max-width:200px;
}

or

.top-logo img{
  height: 100%;
  width:auto;
  /*max-width:200px;*/
}

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

Loading screen featuring symbol percentage

https://i.sstatic.net/Ksogp.jpg How can I create a loading panel that includes a percentage symbol? I have searched for solutions but most of them suggest using a spinner. However, I specifically need a panel with the % symbol included. Is it possible to ...

I came across a small piece of CSS code that isn't functioning properly when tested on jsfiddle

I'm on the hunt for a cool "typing animation" with three dots. Stumbled upon this gem online -> https://codepen.io/mattonit/pen/vLoddq The issue is, it doesn't seem to work for me. I even tried it on jsfiddle and it just stops working. I att ...

Changing the class name in HTML depending on the size of the screen

I'm attempting to dynamically change the class tag's name when a user visits the page based on the screen size. Below is the code snippet I've used: <!DOCTYPE html> <html> <body onload="changeClass()"> <section class=" ...

What is the best way to make the child Div float to the bottom of the parent Div?

Screenshot I attempted various CSS techniques in an effort to make the .booknetic_appointment_container_footer float to the bottom of #booknetic_theme_5, but unfortunately, I was unsuccessful. The closest solution I found involved hardcoding padding, but ...

What is the technique for moving a slider-like checkbox slider to one of its labels when they are clicked on?

Is there a way to make the switch slider move to the word the user clicked on (medium or large)? I'm not sure if I can track the movement of the switch slider with JavaScript or if it's possible to do with CSS. Right now, I have only created a si ...

What is the best way to send a JavaScript variable to PHP for storage in a WordPress database?

I am currently in the process of developing a star rating system within Wordpress and am looking to store the rating data in the Wordpress database. To achieve this, I have saved the star rating PHP code as a template within my Wordpress theme folder. Belo ...

How to display placeholder text in Bootstrap's date picker field

Is it possible to display text instead of a date as a placeholder for a Form Control? <Form.Control type="date" placeholder="Select date" /> This code will yield the following output: h ...

Developing a sliding menu with AngularJS

Currently, I am developing an AngularJS application. One of the features I am working on involves having a menu at the top of my page that, when an item is selected, will slide down to reveal content specific to that selection in the same area as the menu. ...

Combining both responsive and nonresponsive code on a single webpage

The project I am currently working on is a massive website that we cannot tackle all at once. As a result, we are developing it in phases. The challenge we are facing is transitioning from a 1990s table-based structure to a modern Bootstrap-divs responsive ...

Bind event listener exclusively for click event handlers

I have a scenario where I am using 'addEventListener' to handle the opening of a menu (genres-container) only after the transition on another menu (mobile-nav) has completed. The issue I am facing is that even after closing everything and trying ...

How to create ::after pseudo-element with identical width as its preceding sibling

My HTML code includes a <div> container with an <img> and an ::after pseudo-element. Check it out: <div class="container" data-caption="The caption should match the width of the image and wrap accordingly"> <img> </div> . ...

CSS form not aligning properly within wrapper div and appears to be floating outside of it

I am in the process of creating a website that includes a wrapper div containing a: -Header -Content -Footer The issue I am encountering is when I insert regular text into the content section, everything displays properly and the background stretches s ...

Encountering the "node:internal/modules/cjs/loader:1050" error while attempting to execute a folder using the "npm run dev" command

I am encountering an issue while attempting to execute a folder using npm run dev, consistently resulting in the same error message. PS C:\Users\My Name\Desktop\My Folder> npm run dev Debugger attached. > <a href="/cdn-cgi/l/e ...

Automatically showcase images from a directory upon webpage loading

Is there a way to modify my code so that the images from the first directory are displayed on the page when it loads, instead of waiting for a menu option to be clicked? The page looks empty until a menu option is selected, and I would like the images to s ...

Ways to avoid margin overflow in CSS

I am facing an issue with the code below where the last row overflows the parent container. I have tried using overflow: auto; to fix it, but that just adds scrollbars. Any suggestions on how to prevent the overflow? <link rel="stylesheet" href="http ...

Eliminate embellishments upon hovering over hyperlinks

Is there a method to prevent my links from becoming underlined or changing color when hovered over? ...

Persistent Footer - Attemping to keep footer anchored to the bottom of the page

Today, I am facing a sticky footer issue that is rather frustrating for me. Despite trying various resources and conducting thorough searches, I am unable to identify what is causing the problem with my footer. I would greatly appreciate any help in resolv ...

Is it possible to link a css file from an ascx control during registration?

Is there a specific way to register a css code block within an ascx control? Do I simply place <head id="head" runat="server"> <style type="text/css"> .customClass { background-color: Lime; } < ...

Utilize buttons to sort through and refine card displays in Bootstrap 4

On my landing page, I have 40 cards belonging to different categories or groups. There are a total of 5 categories. I am looking to add 5 buttons that, when clicked, will display only the cards from specific category or categories. I do not want to use a s ...

What is the best way to implement a modal that can toggle dark mode using the Konami code, with the added functionality of a close button?

Recently, I attempted to create a Modal window that would activate when the Konami code (↑↑↓↓←→←→BA) is typed. As someone new to JavaScript, I'm still learning and open to feedback. While I have the coding part figured out, I need assi ...