blocks that adapt to different screen sizes, in addition to the

My primary DIV has the CSS properties {width:100%; max-width: 900px} applied.

I am looking to add an additional DIV that aligns with the left free space and another that aligns with the right space, all without using Javascript. Is this possible and if so, how can it be achieved?

Answer №1

If you're looking to achieve a specific layout, flexbox might be the solution:

.container {
  display:flex;           /* set container as flex */
  flex-direction:row;     /* arrange children in a row */
  width:100%;
}
.center {             /* main div */
  width: 100%;
  max-width: 900px;  

  height: 200px;      /* temporary test value */
  background:green;
}

.col {
  flex-grow:1;        /* allow side columns to expand and fill remaining space */
  background:blue;
}
<div class="container">
  <div class="col"></div>
  <div class="center"></div>
  <div class="col"></div>
</div>

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

difference in flex-shrink behavior between Firefox and Chrome

Why does this code sample render differently on Firefox than on Chrome? Is this a browser bug, and if so, which browser is rendering per spec? If there is a bug report available, I would appreciate a link to it. Currently, adding flex-shrink: 0 to the na ...

Having trouble aligning the image to the center

After researching and trying various solutions suggested for aligning an image, I am still unable to get it to align as desired. Here is the HTML code snippet: <section> <img class="seattle" src="img/Seattle Pier.jpg" alt="Seattle docks"> ...

Setting the width of colspan elements can be challenging when other columns have dynamic widths

I am working with a table setup that includes various columns for data tracking: <table > <thead style="width: calc(100% - 15px); display: table; table-layout: fixed;"> <tr> <th colspan="3">& ...

Building a sturdy base with foundation 6 and incorporating blank columns for

I wanted to format my columns like this: | TEXT | TEXT | TEXT | TEXT | BLANK | BLANK | so I implemented it in the following way: <div class="row"> <div class="columns medium-4 large-2">TEXT</div> <div class="columns medium-4 lar ...

Inconsistent animations on Firefox with animate.css

Rock, Paper, Scissors! Greetings, I've been honing my coding skills by developing an HTML game utilizing these fantastic CSS3 animations paired with jQuery. Unfortunately, I've encountered a frustrating issue with Firefox as it only plays the a ...

Creating a Striking Multi-Layered CSS Header

Can someone help me figure out how to add horizontal lines behind the words in this header? Here is what I have so far: https://i.sstatic.net/dN7s4.jpg. However, I want to achieve something similar to this design: https://i.sstatic.net/FZoSF.jpg. You can v ...

The hover effect does not carry over to duplicated HTML

I successfully added a node, but I forgot to include the hover function of the node in my application. The hover function is not necessary, and I need it to work with ie8 compatibility. Here's my HTML: <div id="appendCell" style="color:green; colo ...

Collapsed Bootstrap 5 select drop-down featuring the multiple attribute

I am facing a challenge with using the select element along with the 'multiple' attribute. My aim is to have it collapsed by default and expand only when the user clicks on it. Unfortunately, Bootstrap 5 no longer supports the multiselect feature ...

Transform Your HTML Into a Stunning Canvas

Help Needed: Despite searching through various questions on Stack Overflow, I have not been able to find a solution to my problem. I am attempting to transform HTML into Canvas using either JavaScript or jQuery. Check out the JsFiddle Demo here .conta ...

Adjusting the image size would cause website functionality issues

I just started my journey with FCC, and I'm currently working on my first project which is the Tribute Page. I would really appreciate some feedback on my code, as I'm not entirely confident in it. However, my main issue right now is making the i ...

Enlargen div or unordered list according to content exceeding limits

What is the best way to ensure a div expands when it contains a lot of content? Code Example (HTML): <div class="content"> Content goes here <br /> Content goes here <br /> Content goes here <br /> Content goes her ...

The CSS hover effect on a <td> element is malfunctioning and not working as expected

My goal is to create a dropdown list embedded within each td cell of a table, similar to this setup: <!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <style> ...

Relocating the output of JavaScript to a different location

I'm currently facing an issue with transferring my JavaScript output (start) from the black box to the grey box. I am unsure about what needs to be included in the functions (moveRight and moveLeft) for the transition to occur smoothly. Even after re ...

Updating the background of the <html> tag using jQuery

Is there a way to modify this CSS using jQuery? html { background: yellow; } Attempting the following code does not yield the desired results: $('html').css('background','red'); ...

CSS Conditional Enrollment feature malfunctioning

Struggling to register a conditional CSS for a SharePoint 2013 masterpage. No matter what style I apply, the layout remains unchanged. After researching, it seems like this is how I should register the CSS: <SharePoint:CssRegistration ID="CssRegistra ...

Conceal/Reveal the visibility of the webkit scrollbar when scrolling

I'm attempting to create a unique user experience where the scrollbar is initially hidden using opacity. Then, when the user interacts with the page by scrolling or hovering over the scrollbar, it fades in smoothly thanks to CSS transitions. Finally, ...

What is the reason behind Bootstrap displaying a non-existent LESS file during inspection?

Working on a project, I decided to test the responsiveness of my CSS. Suddenly, my page underwent a style transformation, especially my navbar (built with Bootstrap) changed completely. Upon inspecting, I noticed that properties were coming from a less/nav ...

Align an element to the right side of the webpage using CSS

I've been struggling to align elements to the right side of the page using various methods like float and flex, but nothing seems to work. To make it easier to understand my issue, I've attached a picture that illustrates what's going on. I& ...

Expanding the input range slider to fill the entire available space

https://jsfiddle.net/a5gdhmfn/1/ <div> <i>O</i> <input type="range" /> <button/> <div>...</div> </div> Inside a div, there is a range slider along with other fixed-width elements. The issue ...

How do I adjust the Bootstrap 4 column width to match the size of its content?

I am facing the following situation: [![enter image description here][1]][1] What I want is: Number 1: Adjust the column width to fit the content, in this case the image. Number 2: Resize the column width to accommodate the text "Title of Content" ...