An issue has arisen regarding the width of the second image

Can you assist me in resolving an issue related to the width of the second image? I have included a link for your reference if you wish to examine the problem.

<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">

  <head>
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Happy+Monkey&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="style.css">
  </head>

<body>
  <div id="header">
    <h1>It's Violeta's birthday today 🎉</h1>
    <img id="bff-img" src="Violeta.jpg">
    <h2 id="bday-age">She is turning 38 years old</h2>
    <h4 id="bday-date">Date: 05.07.2022</h4>
  </div>

  <div class="gift-section">
  <h2 class="gift-title">Celebrating the joy on this special day 🥳</h2>
  <h3 class="gift-hint">(Move your mouse over the gift)</h3>
  <div class="gift-img" id="gift-img-happy"></div>
  </div>

  <div class="gift-section">
    <h2 class="gift-title">A toast to your friendship 🥂</h2>
    <div class="gift-img" id="gift-img-cheers"></div>
  </div>

  <div class="gift-section">
    <h2 class="gift-title">Witness the magic as you walk in 😍</h2>
    <div class="gift-img" id="gift-img-hot"></div>
  </div>
  <footer>Copyright &copy; 2022 </footer>
</body>

</html>

Additionally, here is the corresponding CSS:

body {
    text-align: center;
    font-family: 'Happy Monkey', cursive;
    background: #a2d2ff;
    color: #ffffff;
}

h1, h2, h3, h4, p {
    text-shadow: 0 0 1px black;
}

#bff-img {
    width: 150px;
    border-radius: 50%;
    border: 6px solid #EFB0C9;
    margin-bottom: 10px;
}

#bday-age {
    background: #EFB0C9;
    padding: 5px 10px;
    border-radius: 5px;
    margin: 5px 0 10px 0;
}

#bday-date {
    margin: 0;
    background: #EFB0C9;
    padding: 5px 10px;
    border-radius: 5px;
}

#header {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.gift-section {
    margin-top: 50px;
}

.gift-title {
    margin-bottom: 10px;
}

.gift-hint {
    margin-top: 0;
}

#gift-img-cheers {
    height: 200px;
}

.gift-img {
    margin: 20px auto;
    max-width: 400px;
    height: 400px;
    border: 6px solid white;
    border-radius: 10px;
    background-image: url("9k=(1).jpg");
    background-size: cover;
}

#gift-img-happy:hover {
    background-image: url("https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQTMuMQnX7isJCCrCZbeh_JBp-ACk2KvmB1H7NBLp0V_Ty2988B&s");
}

#gift-img-hot:hover {
    background-image: url("9k=.jpg");
}

#gift-img-cheers:hover {
    background-image: url("birthday-beerthday.gif");
    height: 400px;
    width: 400px;
}

In case you'd like to view my replit version, here is the link:

Feel free to provide feedback on the code and suggest improvements if needed.

Answer №1

If you're facing an issue with the height of your element, a simple solution is to include "!important" after the height: 400px; property declaration. Here's how you can do it:

.gift-img {
    margin: 20px auto;
    max-width: 400px;
    height: 400px !important;
    border: 6px solid white;
    border-radius: 10px;
    background-image: url("9k=(1).jpg");
    background-size: cover;
}

The reason for this problem is that the height attribute is being overridden by the following code:

#gift-img-cheers {
    height: 200px;
}

Answer №2

It seems like you're asking about the height of the second image. In that situation, all you need to do is delete this specific style;

#gift-img-cheers{
    height: 200px;
}

This style is unnecessary and is actually conflicting with the predetermined height of 400px set by the gift-img class. It's best to avoid using the !important rule, especially for beginners.

Answer №3

Are you referring to the height of the second image? If so, it may be because the image already has a specific height set in the CSS. Try removing the height rule from the #gift-img-cheers selector.

#gift-img-cheers {
    height: 200px; /* <-- try deleting this line */
}

I hope that resolves your issue.

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 method to customize the behavior of an element with a subclass when the :hover event is triggered?

How can I apply different styling properties when hovering over a selected option with the class ".form-option-card" and ".form-option-selected"? By default, unselected options only have the class form-option-card, while the selected option includes the fo ...

The functionality of the angularjs class seems to be malfunctioning

I'm a new learner of angularjs and I've created a simple page below. I have a style called "item" that I'm trying to apply to a div, but it's not working. However, if I use inline style, then it works fine. Can someone please help me f ...

Achieving perfect centering in PrestaShop using CSS for both horizontal

Hello there, I require assistance with aligning some images in the center of my Prestashop webpage. I am specifically struggling with aligning 3 circular images at the bottom of the page (not social icons). I cannot figure out how to properly center these ...

Using JavaScript to interact with elements inside an iframe on a webpage

In a simple scenario, I am experiencing incorrect results. Code snippet from MyFrame.HTML: <!DOCTYPE html> <html> <head> <title>My Frame</title> </head> <body> <a href="https://www.google.com& ...

Unable to achieve horizontal alignment with DIV element set as inline-block

Currently, I have five columns that are aligned using the display:inline-block. Everything seems to be working fine, but there's a peculiar issue that arises when I refresh the page multiple times. Occasionally, while the first column remains at the t ...

What is the process for retrieving the width value from an input field using jQuery?

This example demonstrates an alert trigger when the input value width or cursor crosses the input width. How can we retrieve the width of the input value without just getting the length of the value in jQuery? $('.value_width').text($('.i ...

In a responsive layout, a floating div refuses to adhere to the left alignment

I am working on a dynamic list using ASP:REPEATER with floating divs aligned to the left. The current layout is as follows: +---------------------+ +---------------------+ +---------------------+ | | | | | ...

Creating a versatile PHP script capable of managing multiple forms

Each time I develop a website for a client, I find myself in the same cycle of writing form HTML and then creating a PHP script to manage the data. Dealing with lengthy forms or multiple forms can make the process messy. Before diving into crafting a dyna ...

Tips for maintaining a fixed height for a div while its content is being updated

<div id='wrapT'>some content here</div> <div id='btnsT'> <img id='prev' src='btns/prev_01.png' alt='prev'> <img id='next' src='btns/next_01.png' alt='next ...

Choose the content in the second column

Can anyone help me with CSS selectors? I've been trying to target the second .col_content element in my code to apply a specific background image, but I haven't had any luck so far. Adding a second class would be an easy fix, but I'm curious ...

Enumerate the data URLs present on a webpage

To automatically download all the files from a webpage (where data urls are different from the webpage url), I need to extract those data urls from the html code. Here's how I go about it: library(XML) url <- "http://www.data.gouv.fr/fr/dataset/re ...

jQuery Ajax allows scripts to be contained within a page, even if the page itself is empty

Utilizing jQuery ajax to display an HTML page that includes javascript functions, here is my code: function ChartBook() { $.ajax({ url: '/Charts/ChartBook', dataType: 'html', id: 1, ...

Passing the final element of a POST array to a different page

I am having trouble retrieving the correct array values from the form. In my code, I am invoking the form option value 3 times, which is defined in the database. Here is an example of what is currently in the database: https://i.sstatic.net/G4JQx.png Wh ...

The mysterious result of the <em> tag in a WordPress theme

My new WordPress theme is unexpectedly outputting an <em> tag, even though I haven't used any <em> tags in my theme. This is causing issues and affecting the design. Below is the content of my index.php file: <?php get_header(); ?> ...

Transform a dynamic Maya model into JSON format for seamless integration with Three.js

After creating a Maya model in Maya 2008, I need to convert it to a JSON format for use with three.js. I have experimented with different methods including: 1) Utilizing the threeJsFileTranslator.py Maya plugin provided in the threejs package. 2) Trying ...

Display all elements on a webpage using Javascript without the need for scrolling

I'm looking for a way to ensure all items on a webpage load immediately, without having to scroll down multiple times before running a script to find a specific item. Is there a method to have all items load at once without the need to manually scroll ...

Diagram with Cascading Style Sheets and Hypertext Markup Language

As I work on creating a flowchart, here is the code that I have developed: #flowchart { width: 580px; text-align: center; font-family: sans-serif; font-size: .8em; margin: auto; } #flowchart a { ...

api for enhancing images in Laravel app through preview, enlarge, and zoom functionalities

As I work on my website, I aim to display images in a compact space, such as within a 300x300 <div>. What I envision is the ability for users to preview or enlarge these images upon clicking, allowing for a closer and more detailed view. For exampl ...

The left border is failing to appear on the Td element

When attempting to add border styling to td elements, the left border is not displaying correctly. This issue seems to vary across different browsers. Here is the HTML code: <table class="table-bordered"> <thead> <tr> ...

How can I customize a CSS media class?

In my project, I am using a CSS library that includes the following class: @media only screen and (max-width: 480px) { .nav-tabs>li { margin-bottom:3px; } .nav-tabs>li, .nav-tabs>li>a { display:block !important; ...