Adjust the size of an image instead of formatting text to fit around it when the browser window is resized

Is there a way to make an image scale down instead of having text wrap around it when the browser window is resized to be more narrow? Currently, the text wraps under the image before the image scales due to its max-width property.

The desired outcome is to have a horizontal logo next to a horizontal menu, where the logo scales on window resize while the menu remains fixed in place.

If possible, CSS should be used for this task. However, Javascript can be considered if CSS alone cannot achieve the desired result.

<style>
img { max-width: 100%; }
#textblock { display: inline}
</style>

<div id="container">
  <img src="https://www.google.com/images/srpr/logo11w.png">
  <div id="textblock">Some Random Text</div>
</div>

Fiddle: http://jsfiddle.net/uLc8dcsh/1/

Answer №1

Give this a shot :

<div id="wrapper">
    <div class="image-holder"> insert the image tag here </div>
    <div id="text-area">   </div>
</div>

Also add this CSS:

img {
    max-width: 100%;
    float:left;

}
.image-holder{width:80%; float:left;}
#text-area {
    display: inline;
    float:right;
    width:20%;
}
#wrapper{width:100%; float:left; }

Answer №2

Is something like this what you had in mind? http://jsfiddle.net/uLc8dcsh/3/ ?

  1. In this example, the logo grows to a maximum width of 300px when the window is maximized.
  2. The container's minimum width is set to 300px to prevent wrapping of text.
  3. The logo's width is set to 50% of the #container's width.
img {
    width:50%;
    max-width: 300px;
}
#textblock {
    display: inline
}

#container {
    min-width: 300px
}

Answer №3

This response may be more detailed than necessary:

What is this:

1. Position image with overflow hidden

To prevent text from overflowing beneath the image

2. Implement clear-fix to containing div

To ensure the image does not disrupt the surrounding element (article)

HTML

<article class="clearfix">
    <img src="some image"></img>
    <p>Some random text</p> 
</article>

CSS

article p {
    overflow:hidden;
}
article img {
    float:left;
    max-width:80%;
}
article {
    border:1px solid;
}

.clearfix:before,
.clearfix:after {
    content: " "; /* 1 */
    display: table; /* 2 */
}

.clearfix:after {
    clear: both;
}

Additionally, here is the Fiddle Reference

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 CSS Issues - One specific to mobile devices, the other unique to Chrome browser

Having trouble with the top banner not stretching all the way on iPhone. Any solutions? Here's a screenshot for reference: Below is the CSS applied to the div: #banner { background-color: #F7F7F7; background-size: cover; box-shadow: 0 0 ...

Retrieving the nodeId using Selenium WebDriver with Chrome Remote Interface

While I was successful in using Chrome Remote Interface functions within my Selenium WebDriver session, such as Page.captureScreenshot and Emulation.clearDeviceMetricsOverride, I encountered an issue with invoking methods that operate on DOM elements. The ...

How to dynamically update an API in a single-page VueJS application without requiring a full page reload when new data is submitted

I recently created a one-page system for school administration, which includes several student records. Interestingly, when new data is inputted, the changes are reflected in the database but do not update other components until I manually refresh the pa ...

Align text to the left and right with a centered div

Visualize the asterisk * at the center of the div textAlignRight * text AlignLeft This is essentially my goal to accomplish <center> <span class="left_host">Right aligned</span> * <span class="righ ...

Nuxt - Sending Relative Path as Prop Leads to Error 404

I am currently working with an array of JSON objects that I need to import onto a webpage. The process involves iterating through the data and passing the objects as a prop to a component. One of the attributes within the JSON data is a relative path for a ...

There seems to be an issue with Ajax functionality within the Webix framework

Exploring webix for the first time has been quite an interesting journey. I am carefully following the guidance provided in the getting started document to create my own webix program. By placing my code in an HTML page and two JSON files as instructed, he ...

The Angular UI Datepicker is not reflecting changes in scope variables within the dates-disabled function

I'm currently working with AngularJS and the Angular UI Bootstrap. I've encountered an issue that I initially thought was related to scope, then initialization, but now I'm stuck trying to figure out what's causing the problem. I' ...

Issue with $sce.trustAsResourceUrl(url) function in angularJS

Having trouble with loading a file into an iframe. Here is the code for the iframe: <iframe width="100%" height="800px" scrolling="no" ng-src="{{someUrl}}"></iframe> In the controller, I am trying to: $scope.someUrl = $sce.trustAsResourceUr ...

The storing of data in an HTML form input

Within my submission form, there are five distinct inputs that users can enter and submit. Currently, the entered data is being written to a .txt file successfully. Nevertheless, the objective is to organize and display the information in an easily readabl ...

Ensuring form field accuracy through server-side validation using Ajax - Mastering the art of Ajax

I am in need of implementing Ajax to validate my form fields, currently I have a javascript validation set up. Is it possible to reuse my existing javascript code and integrate Ajax for form validation? HTML Form <form method="post" action="ajax/valid ...

Ways to identify when the scroll bar reaches the end of the modal dialog box

I have been working on a modal that should display an alert when the scrollbar reaches the bottom. Despite my efforts to research a solution, I am struggling to detect this specific event within the modal. The desired outcome is for an alert to pop up once ...

Having trouble closing my toggle and experiencing issues with the transition not functioning properly

Within my Next.js project, I have successfully implemented a custom hook and component. The functionality works smoothly as each section opens independently without interfering with others, which is great. However, there are two issues that I am facing. Fi ...

Executing functions in a pre-defined order with AngularJS: A step-by-step guide

In my AngularJS Controller, I have a receiver set up like this: // Broadcast Receiver $rootScope.$on('setPlayListEvent', function(event, playListData) { if($scope.someSoundsArePlaying === true) { $scope.stopAllS ...

Pressing the non-responsive button automatically chooses the following item

This example demonstrates how to create a disabled button: import { Grid, IconButton } from "@material-ui/core"; import ArrowBackIosIcon from "@material-ui/icons/ArrowBackIos"; export default function App() { const handleClick = (e) ...

Problem with Raphael Sketch and Request to Ajax

Utilizing Raphael.js and jQuery Ajax, I am attempting to display some dots (circles) on the map in this [Demo][1]. I have a PHP file called econo.php which looks like this: <?PHP include 'conconfig.php'; $con = new mysqli(DB_HOST,DB_USER,DB_P ...

What is the best way to design a layout utilizing the "display: inline-block, block, or inline" properties in a style sheet?

https://i.sstatic.net/IqsRt.jpg Currently facing an issue with incorrect output. Code Snippet: <!DOCTYPE html> <html> <head> <style> .largebox { display: block; margin: 10px; border: 3px solid #73AD21; } .box1 { disp ...

"Exploring the process of integrating angular-xeditable into a MeanJS project

I recently attempted to install angular-xeditable from the link provided, but encountered issues while trying to reference the JavaScript files in layout.html after downloading it with bower. According to the documentation, these files should be added auto ...

Using the length of an array as an iterator within a nested ngFor loop in Angular 9

I am looping through an array of objects where each object contains another array of objects with attributes like "name" and "id". The length of this array of objects (noticias) varies. I am struggling to display these values and have only managed to acce ...

Use jQuery to refresh the jQuery sparkline chart after fetching data asynchronously

Background Utilizing the jquery.sparkline library to generate Pie Charts. The data for these charts is stored in an array. Upon initial page load, a web-service call is made (using .ajax) to fetch the data. The callback function associated with this call ...

What is the best way to retrieve all Objects by a specific property in React when working with an array of Objects?

I am looking to create a multiple checkbox filter where selecting the 'Accessories' option will display items with the 'Accessories' value under the 'type' property. However, before I proceed with that, I need to ensure that I ...