The width percentages of an image and a button are identical, yet they appear to have

In my HTML document, I noticed that the image tag and button tag both have a width of 40% in the style attribute.

<!DOCTYPE html>
<html>
  <head>
  </head>
  <body>
    <div style="display: flex; flex-direction: column;">
        <img src="Assets/Blimp VB.png" alt="Preview of my second attempt to create a game" width="40%" style="
        border: 2px solid black;
        border-bottom: none;
        border-top-left-radius: 20px;
        border-top-right-radius: 20px;">
                
        <button type="button" style="
          height: 100px;
          width: 40%;
          border: 2px solid black;
          border-top: none;
          border-bottom-left-radius: 20px;
          border-bottom-right-radius: 20px;"
        >Second attempt at creating a game</button>
    </div>
  </body>
</html>

Upon running the file, the div appeared like this:

https://i.sstatic.net/C2CiF.png

I observed that the image is still wider than the button. It seems that the width setting does not consider the border. How can I resolve this issue?

Just to clarify, the reference to Blimp is simply a placeholder for the project preview and not meant as promotion.

Answer №1

Perhaps this approach could work

<!DOCTYPE html>
<html>
  <head>
  </head>
  <body>
    <div style="display: flex; 
                flex-direction: column;
                border:2px solid black;
                border-radius:20px;
                overflow:overlay;
                max-width:400px;">
        <img src="https://i.guim.co.uk/img/media/26392d05302e02f7bf4eb143bb84c8097d09144b/446_167_3683_2210/master/3683.jpg?width=1200&height=1200&quality=85&auto=format&fit=crop&s=49ed3252c0b2ffb49cf8b508892e452d" alt="Preview of my second attempt to make a game" width="100%" >
                
        <button type="button" 
           style="height:100px;
                  width:100%;
                  outline:0px solid;">My Second Game Creation Try</button>
    </div>
  </body>
</html>

Answer №2

<div style="display: flex; flex-direction: column; width:400px;">
        <img src="Assets/Airship VB.png" alt="Showing off my latest game development project" width="100%" style="
        border: 2px solid black;
        border-bottom: none;
        border-top-left-radius: 20px;
        border-top-right-radius: 20px;">
                
        <button type="button" style="
          height: 100px;
          width: 100%;
          border: 2px solid black;
          border-top: none;
          border-bottom-left-radius: 20px;
          border-bottom-right-radius: 20px;"
        >Latest game project showcase</button>
</div>

give this code a shot :)

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

The styling of divIcons in React Leaflet Material UI is not applied as expected

When using divIcon in React Leaflet to render a custom Material UI marker with a background color prop, I noticed that the background style is not being applied correctly when the marker is displayed in Leaflet. Below you can find the code for the project ...

Choosing a specific child element using jQuery

When hovering over a parent element, I want to display an image within that specific parent only. Here is my current code snippet: jQuery(".job_col").hover(function() { var current = jQuery(this); jQuery(current > ".plus").addClass("hi"); }, func ...

CSS Background color only applies to the lower section of the page

I'm attempting to create a social media button using an anchor tag and a fontawesome icon. My goal is to have the entire background colored black with CSS, but my previous attempts only resulted in the bottom half turning black. https://i.sstatic.net ...

What could be causing the sporadic functionality of my jQuery image resizing code?

Seeking help for an issue I am facing with my jQuery code. I have been trying to scale a group of images proportionally within an image carousel using jCarousel Lite plugin. However, the resizing code seems to work randomly and I can't figure out why. ...

Steps to create a stylish opacity gradient effect on div borders without using any colors

Currently facing a dilemma without a clear solution in sight. The issue at hand involves creating an opacity gradient on the borders of a div that is not dependent on color. To elaborate, there is an "overflow:hidden" div (referred to as MainDiv) housing ...

Tips for displaying content in a stacked format when hovering, similar to a list item (<li>), using jquery/javascript

I am attempting to display different content on hover over text, specifically listing various HTTP error codes. My setup includes 3 icons and text that will reveal specific content based on the text hovered over: success error blocked Below is the JS cod ...

Dynamic Filtering with jQuery List

I'm attempting to create a dynamic filter list on keypress event. For example, if I type "It" into the input field, the elements that do not match this value will be hidden. I'm unsure if the code structure I have implemented below effectively ac ...

"Efficiently handle online submissions: Use Django to submit a form and instantly display the outcome

I have an urgent task to develop a web page where users can input data, and the backend will perform calculations and display the result below the input field on the same page (similar to checking online air ticket prices). I am new to Django and HTML. Be ...

Using CSS: Leveraging the power of CSS selectors for styling child elements

I attempted to implement a CSS style that targets a child element of the body based on the active state of another div class. Here is the HTML structure: <body class="restrict-body-scroll"> <div class="main-wrapper"> <div class ...

What could be causing this issue where the input button displays perfectly centered in Chrome, but not in IE and Firefox?

Have you noticed that this input button appears perfectly centered in Chrome, but in IE or Firefox it seems to be off to the right? You can see it as the second button on the right side of this page: Site : HTML : <div style="float:center;text-align: ...

Trouble with scrolling child panel to top of screen in Angular 8

I am facing an issue with a parent component that contains four child components. Each child component is a primeNg panel with a form embedded in it. While the first three panels are always expanded, the fourth one is collapsed initially. Inside this fourt ...

What is the best way to create a number input field that also accepts text input?

The goal I have in mind is to create an input field that will contain text like "100%", "54vh", or "32px". I am attempting to utilize the number input's up and down arrows, while still allowing the user to edit the text. However, it should only allow ...

Creating custom modals for individual elements using PHP

Currently, I am working on a project that involves allowing users to select an item from a list retrieved from a MySQL database. The goal is to have buttons generated based on the selected item, shown below: https://i.sstatic.net/Oi5CG.png Here is a trim ...

What are the steps to creating a popup form on a website?

I am implementing LDAP bind authentication to password protect my page. The process and script are working fine. I have a form that submits to the script for user authentication. If the user lacks authentication, they are redirected. I want to turn the ex ...

Retrieving the values from text fields on the current page

Imagine that there are numerous text fields scattered on a page. When I input a fresh value into one of them and click a button, how can I efficiently update the database with only that specific new value? Alternatively, what is the best way to update all ...

What is the method to retrieve the selected value from a drop-down menu that is connected to JSON keys?

I am just starting to learn AngularJS and I need help with binding column names (keys from key-value pairs) to a select list. I want to be able to retrieve the key name when the selection in the select list is changed. The select list displays: name, snip ...

How can I show tab objects in a Chrome extension?

I'm currently working on developing a new Google Chrome extension that focuses on tab organization. Despite the abundance of similar extensions already available, I am determined to create my own unique solution. One idea I have is to create a popup w ...

Passing data between forms using jQuery

Is it possible to determine the current form using JavaScript? Here's my situation: I have a form named form1 which contains a table. When a user clicks on a row in the table, another form (form2) appears. If the user successfully saves data on form2 ...

The appearance of the logo varies across various web pages on the site

Isn't it strange that my logo appears pixelated only on the home page, even though I used the same HTML and CSS code for all pages? The Html: <a href="Home.html"><img id="logo" src="../CONTENT/Images/Logo/1Sr2l8а.png" alt="logo"/></ ...

Is there a way to assess the height of a container and adjust the CSS accordingly?

Imagine you have a container that fills 100% of the page with a footer positioned at the bottom left within that container. The footer is set to be at left:0px and bottom:0px. Using JQuery, is it possible to detect the height of the container and, if it f ...