Maximizing the width of a right-hand div while the left div remains a fixed size

My challenge involves creating a layout with two div elements displayed as inline-block. I want the left div to have a fixed size, while the right div should fully span the remaining space on the same line without moving to the next line. Essentially, I need both divs to be on the same line, one fixed and the other spanning dynamically.

I attempted to showcase this in a JSFiddle, but unfortunately, the result is not what I intended as the divs appear on separate lines. Are there any CSS experts out there who have encountered and solved this issue before? http://jsfiddle.net/yT5Gc/1/

Answer №1

Consider trying out the code snippet provided below:

HTML

<div id="wrapper">
    <div id="box1">
        Box 1
    </div>
    <div id="box2">
        Box 2
    </div>
</div>

CSS

#wrapper { width: 100%; }
#box1 { width: 200px; float: left; border:1px solid; }
#box2 { border:1px solid; }

View demo on jsfiddle

Answer №2

To achieve the desired layout, you can use the following CSS:

#left {width:80px; float: left;background-color: yellow;}
#right {background-color: red;}

I utilized background colors to distinguish between the two divs. It is important to note that floats must be used instead of inline-block.

A tailored version of the code can be found in this updated fiddle: http://jsfiddle.net/SamanthaSmith/uR8Jh/6/

Answer №3

Alright, I have the full script ready. Let's take a trip down memory lane: I initially wanted to write 2 columns using DIVs.

The key here is to specify the overflow attribute as hidden:

div {border: 1px solid red;}
#left {width: 120px; float: left;}
#right {width: 100%; overflow: hidden;}

You can check out the demonstration here: http://jsfiddle.net/yT5Gc/7/

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

Issue with fluid layout in CSS - Unable to specify height in pixels and minimum height property not functioning as expected

While working on a liquid layout, I have set all my width and height values in percentages. However, during the design process, I needed to check how my CSS was rendering so I temporarily set the height in pixels. Eventually, the height in percentage wil ...

Having difficulty locating the value in the input search field

I am attempting to customize my search bar so that it automatically includes wildcards on both ends when a user performs a search. Although the code below almost does what I want by adding the wildcards on both sides, it adds them to an empty search term ...

Creating a responsive design with HTML and CSS that expands an image to hold additional text

I have a blue bubble image that I want to overlay text on. The amount of text will vary, so I need the image to expand vertically to accommodate more text. I'm hoping for some guidance on how to make the image adjust its size based on the amount of ...

Having trouble retrieving the object variable that begins with http

Within my application, I utilize a JSON object named profile which can be accessed in my HTML like so: <pre>{{ profile | json }}</pre> By using the above code, I am able to display the contents of the profile object on the screen, although sp ...

In HTML, specify that the height of both the `html` and

I am facing an issue with the container-about div. I have set its height to 100% so that the div occupies the entire width and height after the header div. The problem is that currently, I cannot scroll to view the full text. It would be great if there wa ...

Top scroll button malfunctioning on this page

Updated question for better understanding. In my current project, let's imagine I am on the following URL: http://127.0.0.1:8000/blog/ and within that page I have the following HTML: <a href="#top">Back to top</a> Upon hovering over tha ...

Using inline CSS to apply conditional styles to a component in React is a great way to customize the

I'm currently working on customizing the styles of some buttons depending on their 'active' status and whether the user is hovering over them. So far, it's partially working but I'm encountering behavior that I can't fully com ...

Passing values between a JavaScript function and a PHP script - Here's how!

I am looking to display the output of a PHP script in a div tag without having to refresh the page. I have a collection of .c files that users can compile on the server, and I want to list them in a dropdown like this: <option value="" selected="select ...

Increase or decrease a variable by 1 using jQuery

There are simple plus and minus buttons on each side of an input field, as shown in the code below: <input type="button" value="-" id="subs" class="btn btn-default pull-left" style="margin-right: 2%" onclick="subst()" />  <input type="text" ...

What css method is used for combining styles?

When it comes to combining files for CSS, what do you think is the most effective approach? Imagine I have a master.css file that is used on all pages of my website (page1.aspx, page2.aspx) Page1.aspx - This specific page has some unique css that is only ...

Tips for ensuring that 3 divs fill the height of their parent container

I'm facing an issue with 3 dynamic content divs inside a parent container. I want them to all have equal heights and fill the parent container. To demonstrate my problem, I've set up a simple example on jsfiddle. .parent { overflow: hidden; ...

Output each uploaded file using jQuery's console.log function

My AJAX upload form is set up and working, but when multiple files are selected they all upload at once. I want to create a separate div for each file to show the progress individually. However, when I try to test the number of files using this code snippe ...

What is the method for implementing tooltips using JQuery?

AJAX call returns data for dropdown lists 'list1' and 'list2'. If there is no data available, I want to hide the dropdowns with `pointer-events: none` and display a tooltip that says "Data not available". else if (monthly_list.lengt ...

Issue with a "hover" effect on a specific input[type="submit"] button

I'm having trouble getting my CSS styles to apply correctly to the input field. Can anyone help me understand why this is happening? If you'd like to take a look at the code, here are the links to the .html file and the .CSS styles. The goal is ...

Beginning of my initial endeavor (seeking feedback, general advice, criticism)

Hey everyone! I'm looking for a forum-style platform similar to Stack Overflow where I can get some feedback on my first project. It's the first one I've built from scratch, so I'm open to any critiques or suggestions on what could be i ...

Is there a way to position my input at the bottom of its parent element?

Is there a way to position this input element at the bottom and center of its parent div? https://i.sstatic.net/gs1yP.jpg ...

Adjust the width of the inline textarea using HTML and CSS to match that of the input field

Is it possible to create an inline textarea element using CSS that is selectable but still seamlessly integrated into a sentence without specifying the number of columns? Here's an example with a static number of characters (cols="11"): <p>To r ...

Layer one image on top of another using z-index

I'm having trouble layering one image on top of another in my code. Here is my code: body { background: #000000 50% 50%; height: 100% width:100%; overflow-x: hidden; overflow-y: hidden; } .neer { z-index: 100; position: absolute; } ...

The primary division containing two inner divisions, one centered and the other positioned to the right

I would like the layout to resemble the image provided. The div header contains two nested divs - the logo div should be centered, and the info div should be positioned to the right with some margin. ...

Encountering a problem with loading the stylesheet

I keep encountering a 404 error when trying to load the CSS in my web application. The HTML content looks like this: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>PSL Inter App</title> <meta nam ...