Two resizable divs positioned next to each other - first div adapts to the size of the second div

I have a unique challenge with two divs positioned side by side. The first div contains random text of varying lengths, while the second div holds a random number of inner divs.

My goal is to have these two divs completely fill the space within their wrapper, with the text overflowing from the first div once the second div expands enough. This setup allows me to use a font-sizing plugin like jquery-textfill to adjust the font size as needed to ensure it fits within the first div.

Check out this full example with buttons to refresh the random text and add squares within the wrapper:

jsfiddle

Here is the HTML code:

<div id="wrapper">
  <div id="left"></div>
  <div id="right"></div>
</div>

Here is the associated CSS:

#wrapper{
  width: 400px;
  height: 50px;
  background-color: lightgreen;
}

#left{
  float:left;
}

#right{
  float:right;
  overflow: hidden;
}

.square{
  margin-left: 2px;
  width: 50px;
  height: 50px;
  background-color: red;
  float:right;
}

Best regards, teamol

Answer №1

Here is the code snippet in HTML:

<div id="wrapper">
  <div id="right"></div>
  <div id="left"></div>
</div>

And here is the corresponding CSS code:

#wrapper{
  width: 400px;
  height: 50px;
  background-color: lightgreen;
}

#left{
  background-color: yellow;
  overflow: hidden;
}

#right{
  float:right;
  background-color: blue;
}

You can view the updated version on jsfiddle

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 way to have a fixed width div positioned in the center of the screen, with two additional divs on either side

I have come across this stunning image: https://i.stack.imgur.com/tUYMc.png It serves as a header for a website - click on it to see the full size. I am trying to replicate this using HTML, CSS, and images, but I'm struggling. It needs to be 100% w ...

What is the solution to the question: "Hey there, time traveler. We are currently in an era where CSS prefixes are no longer necessary, thanks to the advances in prefix-less CSS

I'm having an issue in my Next.JS app with importing my stylesheet in _app.js. Here is how I currently import it: import '../public/css/Index.css'; The content of Index.css looks like this: .index-container { margin: 20px auto 0; } Wha ...

Setting text alignment in Bootstrap based on breakpoints

Imagine this code: import React from 'react' import DarkPattern from '../Assets/dark-pattern.jpg' const Profile = () => { return ( <div> <section className="bg-dark text-light text-center " ...

Locate all inputs containing a special attribute name, wherein a portion of the name corresponds to a JavaScript variable

$("td[id^='td' + myvar + '_']") Can someone help me with a solution to substitute the static value of 0 in this code snippet with the dynamic variable myvar? Thanks! ...

Having trouble repositioning a div element in CSS

I am having an issue with my code. The problem I'm facing is that I am unable to move the green div.free_space below the other two divs, div.main_pic and div.navigation. I don't understand why this is happening. As I am still learning, I would g ...

Converting a JavaScript variable into a jQuery object

Is there a way to transform this JavaScript variable and make it into a jQuery object as $(myFragment) alter the id attribute from "fragment" to "fragment1"? myFragment = "\ <div id='fragment'>\ <input type='hidde ...

Is it possible to adjust the vertical background-position independently?

While creating a navigation bar using the <ul> element, I have come up with the following CSS code: .nav { list-style: none; background: url(/images/nav.png) no-repeat; width: 666px; height: 60px; } .nav li { font-size: 0px; backgr ...

Retrieve the URL from an iframe using Python and Selenium

On my website's main page, there is an iframe containing the text Code: LWBAD that I need to retrieve. For a clearer visual, refer to the image below: https://i.sstatic.net/DJgbd.png Below is the source code of my main HTML page which includes the ...

Tips for fetching integer numbers in a string in JavaScript in sequential order starting from the left side

Within an input element, users are required to input the price of a product. <input size=10 type="text" id="prd_price" title="prd_price" name="prd_price"> Users have the ability to enter Currency Symbols along with other characters, and we cannot ...

Is it possible to employ a jQuery handler as the selector for the .on() method?

Can a jQuery handler $(...) be used as the selector for .on()? The code snippet below illustrates this: how can I change the circle's color to blue without having a plain text representation of my selector, but still using a handler? // This works. ...

Sculpting the excess from a div-generated HTML button

I need help with adjusting the appearance of a link to make it look like a button. Currently, the button looks too "fat" because of the red background around the text. How can I reduce this effect? I've tried tweaking the width of the div, but that j ...

Automatically add values after successful Facebook login

Currently, I am working on a Cordova project where I have implemented Facebook login for user authentication. While the login is functioning correctly, I am facing an issue where I need to manually press a button with the ID getinfo in order for the values ...

Deselect the DOM element

Here is a jQuery code snippet: $(document).ready(function () { $(".story-area > h1, .story-area > p, .story-area > div > p").text(function () { return convertString($(this).text()); }); }); Additionally, there is a function de ...

Google Web Fonts: Exploring the World of Font Weight Variations

It's quite puzzling as to why the weight of my Google web font in the navigation menu keeps changing on different pages even though I have specifically set it to 700. The CSS for the menu is exactly the same across all pages. Can anyone shed some ligh ...

Overflow scrollbars do not appear on flex divs

I am struggling with implementing a simple flex container that contains standard divs. The issue I am facing is that the overflow does not display a vertical scroller as desired. In order to achieve this, I have included the following CSS code snippet: #c ...

The radius remains constant

Check out my code snippet here: http://jsfiddle.net/VDC5h/ var xStart; var yStart; var xStop; var yStop; var i=0; var d=0; $('#obrazek').click( function(e) { if(i==1) { i=2; } if(i==0) { var posX = $(this).off ...

Setting up a slider in Jquery UI

This problem has got me scratching my head! The slider on this link is functioning perfectly: http://jsfiddle.net/EuTA8/ $("#s2").slider({ min: 0, max: 200, step: .1, value: 100.0, values: [200.0], slide: ...

Double Checkbox

My current project involves creating an update page, and I have successfully completed most of it except for the checkbox section. Strangely, the checkboxes are being duplicated, and I haven't been able to identify the reason behind this issue yet. Th ...

Optimizing Title Tags for Static Pages with Header Inclusion

Working on developing static web pages for a client who preferred not to use a content management system. These pages all have a shared header and footer php files. I am in need of creating unique title and meta description tags for each page, but I am un ...

Using jQuery delegate with anchor elements in Internet Explorer has proven to be

My website is functioning flawlessly on Firefox and Chrome, however in IE 8 (I have yet to test on 7) some of the .on delegates are not working. Specifically, the ones used on anchor tags. Here is the HTML: <ui id='daylist'> <li& ...