Three fluid columns in a CSS flexible container

I need help with creating a fluid div container:

width: 97%;
min-height: 80px;
-webkit-box-shadow: 1px 1px 5px 1px rgba(0,0,0,0.45);
-moz-box-shadow: 1px 1px 5px 1px rgba(0,0,0,0.45);
box-shadow: 1px 1px 5px 1px rgba(0,0,0,0.45);
background: white;
margin-bottom: 20px;
margin: auto auto;
max-width: 880px;

Within this div, I aim to create a 3 column layout as follows:

  1. Fixed width column.
  2. Fluid width column.
  3. Another fixed width column.

Here is an image for better visualization: https://i.sstatic.net/lsXxg.png

View the code here: https://jsfiddle.net/ukgvexsu/

.post_wrapper {
  width: 97%;
  min-height: 80px;
  -webkit-box-shadow: 1px 1px 5px 1px rgba(0,0,0,0.45);
  -moz-box-shadow: 1px 1px 5px 1px rgba(0,0,0,0.45);
  box-shadow: 1px 1px 5px 1px rgba(0,0,0,0.45);
  background: white;
  margin-bottom: 20px;
  margin: auto auto;
  max-width: 880px;
}
.post_image {
  background-position: center;
  min-height: 60px;
  width: 60px;
  border-style: solid;
  border-color: #91A9A7;
  border-radius: 3px;
  border-width: 4px;
  margin-top: 5px;
  margin-left: 5px;
  float: left;
}
.post_1 {
  float: left;
  min-height: 10px;
  background: red;
  margin-top: 5px;
  min-width: 10%;
  max-width: 70%;
  margin-left: 5px;
}
.post_2 {
  float: right;
  min-height: 10px;
  width: 110px;
  margin-top: 5px;
  border-left: 1px solid black;
  padding-left: 5px;
}
.post_datum {
  margin-top: 5px;
  margin-left: 5px;
  font-size: 12px;
}
.post_text {
  padding: 5px;
  min-height: 40px;
  font-size: 14px;
  margin-bottom: 3px;
  line-height: 18px;
  font-size: 14px;
  width: 70%;
}
<div class="post_wrapper">
  <div class="post_image"></div>
  <div class="post_1">
    <div class="post_datum"><a href="./index.php?act=profil&amp;id=960bd310d33a704d836f19e39f61f3e2">USER XXXXXX</a> - 01.02.2016 - 21:06 Uhr</div>
    <div class="post_text">Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam</div>

  </div>
  <div class="post_2">vxcvc</div>
  <div class="clear"></div>
</div>

Answer №1

Fiddle: https://jsfiddle.net/bdc13xpj/1/

If you're working with layouts like this, the calc() function is your best friend.

Make sure to check browser compatibility: http://caniuse.com/#search=calc()

To achieve this, set fixed widths on the side elements and then use calc() to determine the width of the middle div.

Here's an example:

#middle-div-fluid{
  float: left;
  width: calc(100% - 100px - 30px); /*adjust according to your requirements*/
}

Answer №2

Consider implementing it in the following manner :

<div class="LeftFixedWidth">
</div>
<div class="MiddleFluidWidth">
    <div class="MiddleContentWrapper">
        <!-- Add your content here -->
    </div>
</div>
<div class="RightFixedWidth">
</div>

Then, apply this styling :

.LeftFixedWidth {
    position: fixed;
    left: 0;
    top: 0;
    width: 200px;
}
.RightFixedWidth {
    position: fixed;
    right: 0;
    top: 0;
    width: 200px;
}
.MiddleFluidWidth {
    padding-left: 200px;
    padding-right: 200px;
}

Ensure that the padding value aligns with the width of the fixed column

Answer №3

To achieve this, you can utilize the calc CSS3 function.

For compatibility reference, check out the link here.

div{
  display:block;
  width:100%;
  float:left;
  background-color: #607D8B;
  padding: 10px;
  box-sizing: border-box;
}

span {
    display: block;
    float: left;
    border: 1px solid white;
    background-color: #3F51B5;
    height: 100px;
    box-sizing: border-box;
}

span.fixed_width {
    width: 30px;
}

span.fluid_width {
    width: calc(100% - (30px * 2));
    background-color: #2196F3;
}
<div>
  <span class="fixed_width"></span>
  <span class="fluid_width"></span>
  <span class="fixed_width"></span>
</div>

Answer №4

Give this a try:

.post_wrapper {
    width: 97%;
    min-height: 80px;
    -webkit-box-shadow: 1px 1px 5px 1px rgba(0,0,0,0.45);
    -moz-box-shadow: 1px 1px 5px 1px rgba(0,0,0,0.45);
    box-shadow: 1px 1px 5px 1px rgba(0,0,0,0.45);
    background: white;
    margin-bottom: 20px;
    margin: auto auto;
    max-width: 880px;
    display:table;
}

.post_image {
    background-position: center;
    min-height: 60px;
    width: 60px;
    border-style: solid;
    border-color: #91A9A7;
    border-radius: 3px;
    border-width: 4px;
    margin-top: 5px;
    margin-left: 5px;
    float: left;
}

.post_1 {
    float: left;
    min-height: 10px;
    background: red;
    margin-top: 5px;
    min-width: 10%;
    max-width: 87%;
    margin-left: 5px;
    display:table-cell;
}

.post_2 {
    float: none;
    min-height: 10px;
    width: 110px;
    margin-top: 5px;
    border-left: 1px solid black;
    padding-left: 5px;
    display:table-cell;
    vertical-align:top;
}

.post_datum {
    margin-top: 5px;
    margin-left: 5px;
    font-size: 12px;
}

.post_text {
    padding: 5px;
    min-height: 40px;
    font-size: 14px;
    margin-bottom: 3px;
    line-height: 18px;
    font-size: 14px;
}
<div class="post_wrapper">
<div class="post_image"></div>
<div class="post_1">
<div class="post_datum"><a href="./index.php?act=profil&amp;id=960bd310d33a704d836f19e39f61f3e2">USER XXXXXX</a> - 01.02.2016 - 21:06 Uhr</div>
<div class="post_text">Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam</div>

</div>
<div class="post_2">vxcvc</div>
<div class="clear"></div>
</div>

Answer №5

Employ the flex property. Refer to this response for the solution. View the working example on this jsfiddle link.

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

Utilize JavaScript to trigger a div pop-up directly beneath the input field

Here is the input box code: <input type='text' size='2' name='action_qty' onmouseup='showHideChangePopUp()'> Along with the pop-up div code: <div id='div_change_qty' name='div_change_qty&ap ...

The body's width is more compact compared to one of my containers in HTML/CSS

After completing my code for a beginner's HTML/CSS project, I realized that the main parent container holding two smaller containers needed to be set at specific widths. The two inner containers had to be exactly 650px and 270px wide, while the main p ...

Submitting a document on Android version 2.2.1 webview through an HTML form

I am currently working on an Android 2.2.1 app using a webview, and I am facing challenges with implementing a file upload feature. Despite having a standard file upload form, the browser box does not pop up when using webview. However, everything function ...

A method to trigger the opening of a div tag when a button is clicked using Vue.js

<div class="input-wrapper"> <div class="mobile-icon"></div> <input class="input-section label-set" type="text" v-model.trim="$v.mobile.$model" :class="{'is-invalid': ...

What is the best way to choose all cells that begin, include, or finish with a specific term using JQuery/CSS?

I have a table with some cells and I am looking to utilize JQuery to select specific cells. For example: <td>John Doe</td> <td>John Doe1</td> <td>1John Doe</td> I want to select cells that start with 1, include Doe, a ...

javascript for each and every textarea

I am looking to apply my JavaScript code to all the Textarea elements on my page. $_PAGE->addJSOnLoad(" $('.textarea').each(function() { $(this).keyup(function() { var characterCount = $(this).val().length; var mes ...

Enhancing Material UI icons with a sleek linear gradient

Despite following the instructions in this post Attempting to incorporate a linear gradient into a MaterialUI icon, as per a comment's recommendation, I am unable to get it to work. I experimented with the idea that the icons could be considered text ...

Switch up the box-shadow color with ColorThief!

Is there a way to adjust this script to change the box-shadow color of #player1? <script type="text/javascript> $(window).ready(function(){ var sourceImage = document.getElementById("art"); var colorThief = new ColorThief(); var color = ...

Fade out a div with jQuery when hovered over, while preventing the links within the div

I've been experimenting with using jQuery to create a fade effect on a div when hovered over. However, I'm encountering an issue where the anchor link within the div cannot be selected once it is shown. $('#show').hover(function() { ...

Ensure that a select input, dynamically generated, is marked as 'required' only when other inputs have been filled out

Displayed below is a snapshot of a page I'm developing that allows users to input details about various rooms in a property. Users have the ability to 'add' multiple rooms, triggering javascript/jQuery to dynamically create additional input ...

Ways to conceal ad container when ad space remains empty

After setting up my ad HTML like this: <div class="ad-container"> <p>Ad slot #1</p> <div id="ad-slot-1" class="ad-slot"></div> </div> I implemented the code below to collapse the ad if ...

Conceal an element from view upon clicking on it

Task at Hand : Implement a smooth element hiding effect upon clicking, similar to the behavior on this website , where the letter A fades away smoothly when clicked. Is it possible to achieve this effect using only HTML, CSS, and JavaScript? var t ...

ways to conceal the default icon in bootstrap navbar

I am looking to incorporate Bootstrap tags into my HTML file in order to display my menu items. However, I want to avoid having the default navbar highlight box and hamburger icon appear when users visit my site using a tablet or mobile device. <nav cl ...

The Django code snippet "if request.method == 'POST':" encounters an error

Greetings, I'm encountering a peculiar issue in my recent Django project. Currently, I am experimenting with the NameForm example provided in the Django Documentation on Working with Forms. On the surface, it appears to be a straightforward exercise. ...

Enhance data table by displaying a set number of rows that do not completely fill the table's height

I'm currently attempting to implement a v-data-table with fixed header and footer. However, I've encountered an issue where if I set the table height to be larger than the row height, the table takes on the defined height and the footer ends up b ...

Need help with JQuery mouseOver fading in twice when you only want it to fade in

The version can be displayed here. I'm looking to have the current text fade away and the new text fade in. Strangely, it seems to fade in twice for some reason. $(window).load(function(){ var originalTitle = $('.Pinctitle').text(); $(&apo ...

Signs that indicate you have reached the bottom of the page

Wondering how they achieve that cool effect on where the top line appears with a new logo when you scroll down? Is it done using a jQuery trick? How can you determine when a person has scrolled down a certain amount of pixels and then show them new HTML ...

Can images be accessed and displayed on an HTML page by opening a directory and reading file data using Javascript?

Is it feasible in JavaScript to access a directory, read an image file, and display it in HTML? While it may not be possible to directly open files in a directory using JS, I am looking for a way to achieve the following: I have an XML file that includes ...

Utilize a SCSS class defined in one file within a different SCSS file

In my React project, I have a day/night theme button that changes the main body color in the App.scss. It's a simple setup using body.light and body.dark. However, I need to also change the text color in the navigation bar, which is located in a diffe ...

Can pagination numbers in Jquery DataTable be configured based on the total records returned by the server and the number of records chosen by the user?

I am currently diving into the world of DataTable.js, a jQuery plugin, and working hard to articulate my questions effectively. For my specific needs, I need to retrieve only 10 records initially whenever an AJAX request is made, even if there are 100 rec ...