What is the process for adjusting the background to fit the image properly?

Before (On my display with a resolution of 1024px)

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

After (On a different resolution - for example, screen width:1500px)

https://i.sstatic.net/9dGTF.png

#quotes_div img{
    width: 100vh;
    margin-left: 3%;
    margin-top: 3%;
}
#quotes_div{
    position: relative;
}
#quotes_div #img{
    width: 82.5%;
    height: 38.5vh;
    background: red;
}
<div id="quotes_div">
    <h3>My favorite quotes that inspire me</h3>
    <i class="fa fa-quote-left fa-2x fa-inverse" aria-hidden="true"></i>
    <i class="fa fa-quote-right fa-2x fa-inverse" aria-hidden="true"></i>
    <p>Even an impossible dream can lead to action</p>
    <div id="img">
    <img src="assets/fielding.jpg" alt="Field">
    </div>
</div>

I want picture Nr.1 and its "border" to have the same resolution. + I apologize for the text formatting on stackoverflow)

Answer №1

To ensure your image adjusts responsively and stays within the confines of the red border, avoid specifying a fixed height. Instead, set both the container and image width to 100% and include padding around the image to reveal the red background.

Take a look at this demonstration where the adjustments have been made; feel free to tweak the padding accordingly:

#quotes_div img{
width: 100%;
}
#quotes_div{
position: relative;
}
#quotes_div #img{
width: 100%;
background: red;
padding: 1em;
}
<div id="quotes_div">
<h3>My favorite quotes that inspire me</h3>
<i class="fa fa-quote-left fa-2x fa-inverse" aria-hidden="true"></i>
<i class="fa fa-quote-right fa-2x fa-inverse" aria-hidden="true"></i>
<p>Even the most impossible dream can ignite action</p>
<div id="img">
<img src="http://placehold.it/1000x350" alt="Field">
</div>
</div>

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

Two hyperlinks are not visible

I've added 2 links in my header component, but for some reason, they are not displaying. It's strange because everything appears to be correct. These 2 links are part of a list within a ul element. <nav class="navbar navbar-expand-lg navbar-d ...

Issue with CSS rendering in Internet Explorer

Although my website appears perfectly in Firefox, the entire style sheet doesn't seem to load properly in IE 7. It's only displaying certain styles. Any assistance on this issue would be greatly appreciated! ...

Displaying duration of time through JQuery along with present day and time

I'm working on a web application where I display the date and time of a posted request in the user interface. Now, I want to enhance this by showing how long ago that request was posted relative to the current Date and time. Is there a simple way to ...

obtain the string representation of the decimal HTML entity value

Similar Question: how to create iphone apps similar to ibeer, imilk, ibug, ibeer Using javascript to obtain raw html code Imagine having an html section like this: <div id="post_content"> <span>&#9654;<span> </div> ...

divs adjusting to available height

Here is an example code snippet: <div id="parent"> <div id="top"> </div> <div id="mid"> </div> </div> Link to Example I am looking to position the green div below the yellow one, with its height always ...

Can the current website navigation be integrated into the blog script?

People might see me as a spoil sport for not using Wordpress, but I prefer a flatfile blog system for my small site. Currently, I am using the ozjournals-3.2 blog system. I need assistance in installing a header and site navigation on top of the blog page ...

"Efficiently fetch data with an Express GET request without the

My goal is to send the client the HTML page (create.html) in response to a GET request triggered by a button click using fetch. I am intentionally avoiding the use of a form due to formatting and potential scalability issues. The code acknowledges that the ...

Ensure that the <aside> elements span the entire width of their containing parent element

I am currently designing a website and I am aiming for a specific layout. Any advice on how to achieve this would be greatly appreciated. The header of the page consists of: a logo aligned to the left within an <a> tag 2 widgets placed in <asid ...

What are the steps for implementing JWT authentication with static content hosting?

My website consists of a frontend (built with Vue) and a backend (developed using node). The api relies on jwt authentication, allowing only logged-in users to interact with the backend. The jwt is included in the Authorization: Bearer xxx header. An iss ...

Is there a way to shift this structure to the right without relying on the float property?

Here's the HTML and CSS I have - .font-size-add-class { background-color: #2f2f2f; color: #f9f7f1; } .font-sizes { text-align: right; display: table; margin-top: 15px; cursor: pointer; } .font-sizes > .small { font-size: 12px; } .font ...

The placement of the div only shifts in Firefox

Looking to place a small 25px - 25px image at the end of a line of text? Using a DIV (re1DOC) to position the element can make it easier. However, the issue arises when the element displays correctly in IE & Chrome, but not in Firefox. The text shifts slig ...

Creating a multi-column dropdown menu: options for two, three, or multiple columns

Is there a way to implement multiple columns in a dropdown menu using the grid system in Bootstrap 4? Here is the code I have tried so far, but it's not working as expected (please note that the snippet is mobile-responsive) <!DOCTYPE html> ...

Angular.js' Element.prop('scrollHeight') consistently gives identical values for various list items

I have been attempting to determine the heights and widths of the items in my list. Despite exploring various methods for obtaining the height and width of an item, none of them seemed to provide the scrollHeight directly from the element. Upon inspecting ...

How to add a line break within the :after pseudo-element using CSS

I've been struggling to split text inside an :after pseudo-element of a label that receives its content from a data- attribute. I've attempted using word-break, as well as playing around with width, max-width, and position:relative, but nothing s ...

Conceal the bottom HTML/widget and eliminate the Drag & Drop functionality from the Streamlit file_uploader() feature

I have developed an application using Streamlit that requires the ability to read multiple files simultaneously. To achieve this, I am utilizing the file_uploader() component with the parameter accept_multiple_files=True. I have two queries: Firstly, is ...

The data insertion query in MYSQL seems to be malfunctioning

I am facing an issue with inserting data from a form into a database table named "sumation". Despite using PhpStorm IDE, I am getting errors indicating that no data sources are configured to run the SQL and the SQL dialect is not set up. Can anyone help ...

What is the syntax for indenting text inside an inline-block element?

Essentially, the checkboxes displayed here are in a graphical format to avoid using checkbox elements for accessibility reasons (only the link should be interactive). However, aligning a span next to an href and indenting the text to line up with the star ...

What is the best way to incorporate font-awesome icons into a Rails view?

I'm struggling to incorporate font-awesome icons in my Rails view. I had a static standalone HTML code snippet that I added into the Rails view: <span class="icon-white"> <a href="https://twitter.com/xyz"> <i class="icon icon-tw ...

Text loaded dynamically is not remaining within the div

I am experiencing an issue with dynamically loaded content where Images work fine, but Links and Text are not displaying properly. For reference, you can view the problem in this JSFiddle: http://jsfiddle.net/HRs3u/1/ I suspect that it might be related t ...

Curious about the method of refining a list based on another list?

As a beginner in coding, I am facing a challenge in my code.org assignment. I need to filter songs by a specific artist from a dataset. Currently, I have code that randomly selects an artist, but I am struggling to filter out songs by that artist from the ...