Is there a way to have two divs positioned next to each other, with the left one being a fixed width of 300px and the right one taking up the rest of the available space on the screen? I appreciate any guidance you can provide. Thanks!
Is there a way to have two divs positioned next to each other, with the left one being a fixed width of 300px and the right one taking up the rest of the available space on the screen? I appreciate any guidance you can provide. Thanks!
The simplest and most effective method (in my opinion) is to utilize the CSS property display: table
:
#container {
display: table;
width: 100%;
}
#left, #right {
display: table-cell;
color: black;
}
#left {
background-color: green;
width: 250px;
}
#right {
background-color: orange;
}
<section id="container">
<aside id="left">Left content 250px wide</aside>
<div id="right">Right side filling the remaining space</div>
</section>
Feel free to adjust the size of the bottom right frame.
Enhanced with the usage of HTML5
elements like section
and aside
, recommended for projects with an HTML5 doctype
. It's important to keep this in mind...
Check out this demonstration:
http://example.com/code123
Explanation:
1. Combine both components into a single container.
2. Use absolute positioning for the element on the left and make its width 300 pixels.
3. Adjust the left margin of the element on the right to 300 pixels.
To make it work, you can simply use the CSS property float: left;
on the left div
which is set to a width of 300px
, and then add overflow: hidden;
to the right div
. Here's an example layout:
HTML:
<div class = "left">
Coding is so much fun!
</div>
<div class = "right">
Coding is so much fun!
</div>
CSS:
.left {
width: 300px;
float: left;
}
.right {
overflow: hidden;
}
Take a look at this simple demo: demo link.
Check out this code snippet for modern browsers (sorry, IE users):
CSS:
#wrapper {
display: flex;
}
#left-side {
width: 400px;
}
#right-side {
flex: 1;
}
HTML:
<div id="wrapper">
<div id="left-side">Left</div>
<div id="right-side">Right</div>
</div>
Live Demo: http://jsfiddle.net/AbCdE/2/
Here is a simple solution:
<div style="overflow: hidden;">
<div style="width: 300px; float: left;"></div>
<div style="margin-left: 300px;"></div>
</div>
overflow: hidden
allows the container div to adjust its height based on the tallest child elementfloat: left
positions the element to the left sidewidth: 300px
and margin-left: 300px
ensures that if the right column is taller than the left, it will not extend below the left floated div; instead, it maintains a gap of 300px from the left edge of the container divPro tip: try changing margin-left: 320px
for a 20px gutter
Check out this cool DEMO
If I insert the following HTML statically, the CSS style is correctly applied. HTML: <li class="connector"> <a href="#"> <img src="css/images/temp/connector2.png" alt="" width="192" height="192"> <span class="sr-only"& ...
Hey there, currently creating my website and need some assistance. I'm looking to display the date and time in different sections of the page. Having some trouble with getting Indian time to work properly using PHP. If you could help me out with Ja ...
Have you seen the awesome animation on Discord's website? Check it out here! The way those coins move up and down so smoothly is really impressive. How can I recreate that effect for my own images? I decided to start with this code snippet img { ...
My image gallery project has hit a roadblock and my JavaScript skills are not up to par. Maybe it's time to brush up on the basics with a good book from the library. Here's what I want to achieve: 1. Create an array of URL's for each imag ...
I'm currently working with React and MUI and have created a form like the following: const handleUserInput = (event) => { set_user_input(event) } const handleSubmitForm = () => { if (user_input == 'help'){ ...
Currently, I am developing a WPF application in which I create the content of an HTML file as a string (including some JavaScript functions for calculations). After generating the string, I save it as an HTML file on my local disk and then reload it using ...
<table id="result"> <a href='#' class='pop'><span class='fa fa-eye'><img src='image link here' style='display:none'></a> </table> The hyperlink above is designed to open ...
I am in the process of creating a functionality where clicking on one element will fill another element's content from bottom to top. Although I have managed to make it work on hover, the same functionality is not triggered when clicking on the eleme ...
Lately, I've been using BeautifulSoup4 to scrape data from Spotify Charts. It's been working smoothly for a few weeks until today when it suddenly started giving NaN values for all the entries... I suspect that the issue lies in the parsed HTML ...
I tried searching for a solution to my problem but I couldn't find it because of my limited English proficiency. Therefore, I apologize if my question has already been answered. I would like to place my button in the location shown in the image. If p ...
I have little experience in web development, but a small business client has me working on their website while I handle other tasks for them. I've created a home page design that is almost ready to be turned into a template for the chosen CMS. Things ...
I'm facing difficulties with incorporating three.js into my project. Initially, I executed: I am referring to the guidelines provided here: In my VS Code terminal for the project folder, I ran the following command: npm install --save three Subsequ ...
In my code, I have a portfolio-container div with two images and paragraphs inside a list element. The issue I'm facing is that the div is not expanding vertically, causing the images and paragraphs to overlap with the footer below. I've attempte ...
Attempting to transfer selected text from the current page to an HTML page using message passing: content script to background script, then background script to the HTML page. However, encountering errors if the HTML page is not already open, and even gett ...
My current setup looks like this: <div class="row"> <div class="col-md-4">Content</div> <div class="col-md-4">Content</div> <div class="col-md-4">Content</div> <div class="col-md-4">Content&l ...
I'm currently experimenting with the 960 grid css framework. How can I eliminate the space between two divs stacked on top of each other? [referring to the gap between the blue lines in the image] I created my CSS using the CSS generator found at . ...
I am currently developing a website using HTML, and I would like to create an admin section that requires a password input in order to access. After consulting resources on w3schools, I attempted the following code: <button onclick="checkPassword()" i ...
let changeClassDisplay = document.getElementsByClassName('sidebar'); for (var i = 0; i < changeClassDisplay.length; i += 1) { changeClassDisplay[i].style.display = 'block'; } I encountered an issue with this code whe ...
Currently facing a challenge with a significant amount of code here. It is referenced as follows: "ng-uikit-pro-standard": "file:ng-uikit-pro-standard-8.3.0.tgz", I am attempting to display a tab between 1 and 3 if a certain condition ...
I have implemented a full-screen menu that covers the entire screen, excluding the header and menu tab bar. You can view it here: https://i.stack.imgur.com/h5cQa.png On smaller screens, the entire menu cannot be displayed at once, as shown here: https://i. ...