Automatically resizing an image in CSS according to its dimensions and ensuring a similar div fills any remaining space

Seeking guidance on CSS and HTML, specifically relating to an article template I'm developing. The challenge lies in incorporating a picture on one side and a text box of equal height on the opposite side, both enclosed within div tags as shown below.

<!--begin article-->        
<div id="article">
    <div id="article_header">           
        Title goes here     
    </div>      
    <div id="article_body">
        <!-- begin text. used for actual text of article-->
        <div id="text">
            Text Goes here              
        </div>          
        <!-- end text-->            
        <!-- begin article media. used for pictures -->
        <div id="article_media">
            <img src="source_goes_here" alt="This is an image!">
        </div>
    </div>
</div>

The provided CSS...

#article{
    border:1px solid gold;
    margin-bottom:20px;
}    
#article_header{
    padding:5px;
    font-family:arial;
    font-size:36px;
    font-style:bold;
    color:white;
    background:url('orangegradiant.png');
}
#article_body{
    padding:5px;
    display:inline-block;
    width:auto;
}
#article_media{
    border: 1px solid pink;
    text-align:center;
    display:block;
    width:48%;
    height:48%;
}
#text{
    display:block;
    width:51%;
    float:right;
}

After experimenting with different approaches, I've hit a roadblock. While using the float property seems to have set the layout, I'm struggling to make the image div dynamically adjust its size while causing the text div to adapt accordingly. Is there a way to limit the image size so it doesn't exceed 50% of the div, preventing any distortion due to oversized images?

Your assistance is highly valued!

P.S. Please excuse any formatting errors in the code. Still ironing out the kinks on my end.

Answer №1

Include in your CSS style sheet

#article_content img { max-height:50%; }

If you prefer to target the parent div

#article_content { max-height:50%; }

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

What is the best way to format the JQGrid table for better

Is there a way to indent the table in this example and create white space on the side of the rows and header? I want a white margin on the left of everything below "Stackoverflow example". I'm hoping to achieve this using only CSS. Below is the code ...

How can I reset an ng-model value of a range input in AngularJS?

Utilizing a filter with two inputs that share the same ng-model concurrently: <!-- Number input --> <input type="number" maxlength="5" step="0.25" min="-10" max="10" placeholder="0.00" ng-model="sphere"> <!-- Range Input --> <input ...

When attempting to run this straightforward PHP code that is meant to display an image selected from a specific directory, I am encountering an issue where the image appears torn and does not accurately display the intended

When I try to run this simple PHP code that displays an image chosen from a directory, the output is showing a torn image instead of the actual image. I have tested this on multiple browsers, but the issue persists. Here is a snippet of the code: <html ...

Reveal concealed content when a responsive table becomes scrollable on a mobile device

I recently completed a project that was overloaded with tables. I made all the tables responsive, but they still take vertical scroll if they don't fit on certain devices due to their varying widths. For instance, Table A requires vertical scroll o ...

Utilize a combination of min-height percentages and pixels on a single div element

Currently searching for a method to explain min-height: 500px; min-height: 100%; the reason behind my decision to utilize this? The div must be either 100% in size or larger to allow for overflow. The height should only be set to 500px when the screen i ...

Handling the scope object within an Angular directive

Presently, here is my element directive: app.directive("ngArticle", [function(){ return { restrict: "E", replace: true, templateUrl: "/partials/article.html", scope: { article: "=article" } } }]); It is utilized as follows: <ng-ar ...

Deciding Between Two Columns or One Column for Your JQuery Accordion

I am currently working on customizing an Accordion that is too large in height for my liking. My goal is to convert the single column layout into a two-column display, side by side. Having multiple items in one column results in excessive height, hence t ...

The color of the last clicked DIV is supposed to stay permanent, but for some unknown reason

I'm attempting to replicate this design in my project: http://jsfiddle.net/AYRh6/26/ However, I am facing issues with it and cannot pinpoint the exact problem in the code. I am using code for a toggle effect. Any assistance would be greatly appreciat ...

What are the steps to transform an HTML select element into a sub-menu user interface?

Can the native HTML element select be used to add submenus? Processes lack of process failure to follow process HTML <!DOCTYPE html> <html> <body> <select> <optgroup label="Swedish Cars"> <option value="volvo"&g ...

Adaptable fix for lengthy website links (that surpass the screen size)

When I work on creating responsive websites, I often encounter a problem with long URLs breaking my fluid grid and causing horizontal scrolling on smaller devices. These lengthy URLs don't wrap, which means they widen the container beyond the device w ...

Is there a way to drop a pin on the Google Maps app?

Is there a way to pinpoint the specific location on Google Maps? <google-map id="map-container" width="100%" height="100%" class="maps"></google-map> ...

A guide on Extracting Values from Nested Objects

Although I am not well-versed in JavaScript, I have a small project where I need to use JavaScript. I am attempting to retrieve values from an object nested within another object. However, my code is throwing errors. Below is the snippet of my code with d ...

Is there a way to include text beneath the navigation bar and other elements on the page?

I am stuck trying to add some text below my header and navigation bar. Here is the code I've been working with: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta htt ...

Validation using Javascript and HTML

I'm having trouble displaying the "required" span text when a user fails to meet the field requirements in my code. It's not functioning correctly. Any idea what could be causing this issue? function validate() { var spans = document.getElem ...

I am having trouble with my custom-button class not successfully overriding the btn background color property. Can anyone provide insight

Utilizing the bootstrap5 variant-button mixin, I aim to create a custom-colored button. While I have successfully altered the default hover effect color, I am encountering difficulty in setting the background color of the button itself. Upon inspecting the ...

Is it possible to have a variable number of dynamic CSS Grid columns with the option of including a header or footer

Implementing a dynamic number of columns with CSS Grid is a breeze. .grid { grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); } // These .cells are beautifully aligned <div class="grid"> <div class="cell"></div> ...

Listening for an event or using a CSS pseudo-class to detect when the scrollbar becomes

Are there any JavaScript event listeners or CSS pseudo classes that can detect when a scrollbar appears and disappears? For example, on Mac OS and Windows Internet Explorer 10 or newer, the scrollbars are hidden by default but appear when scrolling begins. ...

A step-by-step guide on implementing an if-else statement to remove an item from Angular

I am currently working on implementing a feature that allows me to delete an item only if the quantity of that item is 0. If the quantity is not equal to 0, I need to prevent deletion and send an error message back to the front end. Below is my implementa ...

Utilizing Bootstrap 4 for creating full-width inputs with input-group-prepend functionality

Below is the code snippet: <div class="col-md-8 content-row-top-spacer"> <div class="input-group"> <div class="input-group-prepend"><span class="input-group-text">Name</span></div> <%= f.text_field :name, ...

The stylesheet's URL reference to the image is not functioning properly

I'm attempting to showcase images inside a table cell using CSS. Here's what I currently have: HTML: <td class="activity-status status_not_started">Not Started</td> CSS: td.activity-status { font: 0/0 a !important; color: transpar ...