Two dynamic divs positioned next to a div with a set size

I am struggling with the layout of placing two fluid divs next to one that has a fixed size. Let me show you a picture to better illustrate my issue:

#menu has a fixed width;

#owl takes up 60% of the wrapper;

#right menu takes up 40% of the wrapper.

For a larger view of the picture, please visit http://prntscr.com/5071zd
Thank you in advance.

Answer №1

Take a look at this solution. I moved the right section to a new div to ensure it fills up the entire width. The only issue is that the second margin must be set as a percentage if you want to avoid using calc().

#menu {
    position: fixed;
    width: 100px;
    border: 4px solid black;
}
#inner_container {
    width: 100%;
    padding-left: 110px;
}
#owl {
    position: relative;
    width: 60%;
    border: 4px solid red;
    display: inline-block;
}
#right_menu {
    position: relative;
    width: 38%;
    border: 4px solid green;
    display: inline-block;
    margin-left: 2%
}
#menu, #inner_container, #owl, #right_menu {
    box-sizing: border-box;
}
<div id="container">
    <div id="menu">menu</div>
    <div id="inner_container">
        <div id="owl">owl</div><!--
     --><div id="right_menu">right menu</div>
    <div>   
</div>

Fiddle: http://jsfiddle.net/wxk7j07k/

Answer №2

When you set the width of #owl to 60%, it will occupy 60% of the parent div #wrapper.

The calculation for width is as follows: #owl width + #right-menu width + #menu width = 60% + 40% + 100px.

It is recommended to group your #owl and #right-menu together in a single div for better organization.

<div id="wrapper">
    <div id="#menu></div> // 100px
    <div class="inner-warpper> // this will take up the remaining width of the #wrapper
        <div id="owl"></div> width set to 60% of the #inner-wrapper
        <div id="right-menu"></div> width set to 40% of the #inner-wrapper
   </div>
</div>

http://jsfiddle.net/x8mnqv7b/

Answer №3

We can make the markup simpler by organizing it as follows:

The HTML code becomes:

<div id="menu"></div>
<div id="owl"></div>
<div id="right"></div>

Please note that in this example, I haven't included a container, but you can add one if necessary.

CSS Styling

  • The max-width: 1024px rule is applied to the body element to center it using margin: 0 auto

  • To ensure proper alignment, vertical-align: top is used in conjunction with display: inline-block. This prevents any misalignment that could occur due to the default baseline vertical-align value.

  • The left and right flexible columns have a width of calc(x% - 60px) to account for 10px spacing and the left menu. In case of older browsers (such as IE 8 and below), a less optimized width is provided, offering graceful degradation for older browser support.

  • Setting min-height: 100% on the columns allows them to expand with content. The 100% height is achieved through height: 100% on html,body

Interactive Example

Pay attention to the use of <!-- --> in the code. This is done to eliminate any gaps that may appear when using inline elements.

* {
  box-sizing: border-box;  
}
html {
  height: 100%;
}
body {
  margin: 0;
  height: 100%;
  max-width: 1024px;
  margin: 0 auto;
}
#menu {
  width: 100px;
  border: 4px solid black;
  min-height: 100%;
  display: inline-block;
  vertical-align: top;
  margin-right: 10px;
}
#owl {
  width: 50.5%;
  width: calc(60% - 60px);
  border: 4px solid red;
  display: inline-block;
  vertical-align: top;
  min-height: 100%;
  margin-right: 10px;
}
#right {
  width: 30.5%;
  width: calc(40% - 60px);
  border: 4px solid green;
  display: inline-block;
  vertical-align: top;
  min-height: 100%;
}
<div id="menu">menu</div><!--
--><div id="owl">owl</div><!--
--><div id="right">right</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

What is the best way to use JavaScript to conceal a section of a form div?

After receiving some code from a certain platform and implementing it to hide part of my form div element, I noticed that the element hides and unhides quickly when running in a browser. This rapid hiding and showing behavior occurs when clicking on the bu ...

Using AngularJS to update attributes in an HTML tag within a string

My string contains HTML tags : var str = "<div><p></p><p><i>blabla</i></p><p><i><b>blaaaaaablaaaaa</b></i></p><iframe src='urlAAA' height='400' width=&ap ...

Using javascript to dynamically change text color depending on the selected item

I am currently working on a website for a snow cone stand and I want to incorporate an interactive feature using JavaScript. Specifically, I would like to color code the flavor list based on the actual fruit color. The flavor list is already structured i ...

The Ajax success function is failing to trigger after receiving a 200 network response

I have a basic HTML page that loads jquery 3.3.1 and an external script file called script.js. I am using a simple node http-server to serve the static page. The data.json file is also in the same folder as the HTML file. However, even though the network c ...

Addressing a pagination glitch

I seem to be encountering an issue with pagination while using tabs. Specifically, when I attempt to navigate to the second page of the candidate table within the second tab (candidate), I find myself redirected back to the first page of the contact tabl ...

Pictures failing to display in their designated location

Having trouble with my social media icons on the page. They either get hidden by other divs despite having a higher z-index or appear below the top section. I want them to be positioned to the right of the church image. I've tried different approaches ...

The menu content has a 50% chance of appearing when the open menu button is clicked

Hey there, I'm currently facing an issue with a menu I created that slides open to the bottom when a button is clicked. The problem I'm encountering is that the content of my menu only appears about half of the time... I'm not quite sure how ...

Sophisticated Arrangement of Div Elements

Here's a scenario where Two divs are dynamically styled from the Database. I am attempting to align two divs in the layout shown here: https://i.stack.imgur.com/nYI7v.png Can this be achieved using Bootstrap's CSS class col-? In responsive mo ...

Trigger a function from a Bootstrap modal

Here is a preview of my HTML code : <form action="form2_action.php" method="post"> <table> <tr> <td>First Name </td> <td>:</td> <td><input type="text" id="f ...

Achieving Vertical Centering in Bootstrap: A Step-by-Step Guide

Creating a mobile-optimized website using bootstrap 4. Currently struggling to vertically center an element within the available space. The element consists of a title with fixed size, a message, and 2 buttons in a div. Need to ensure it is vertically cent ...

swap the positions of two distinct texts

I need to dynamically change the positions of two texts based on the text direction (LTR or RTL) using CSS specifically for an email template. Here is the code snippet I am working with: '<span style="font-weight:bold; text-align: center;">US ...

Modify the select input's border color when it is in focus

My select input's focus color is not changing, and I'm struggling to figure out the proper override. .form-control:focus { border-color: inherit; -webkit-box-shadow: none; box-shadow: none; } .forma #kome { border-color: #8e8e8e; -w ...

I'm facing an issue with the footer and header that is preventing me from properly positioning any content on the website

When attempting to include an h3 element on the website, it remains stuck at the top. I have tried using CSS properties like position, top, and left but it does not respond to them. Additionally, I experimented with a gallery template from w3schools to see ...

:last-child is effective, but :first-child is inefficient

I'm having trouble using CSS to hide the first .sku element within an aside that contains two of these elements. Strangely, the :last-child selector works just fine. Can anyone explain why this might be happening? Here's a link to the JSFiddle fo ...

Is PHP the best choice for creating simple websites?

Throughout my web design experience, I have always relied on PHP for the most basic tasks and avoided using the .html extension. One of the main reasons for this was my ability to utilize "PHP Includes" on my website, allowing me to create navigation eleme ...

Exploring ways to retrieve checkbox values instead of boolean values upon submission in Angular

I am currently working with a template-driven form and facing an issue. Despite receiving true or false values, I actually need to retrieve the value of checkboxes. <form #f = "ngForm" (ngSubmit) = "onClickSubmit(f.value)"> ...

Transferring information between pop-up and webpage

I have developed a simple form within an ERP system that allows users to create quick support tickets. However, instead of manually inputting the client ID in the form, I want to provide them with a more user-friendly option. My idea is to include a search ...

Can the CSS of an iframe be modified if the iframe is located on a different domain?

Is it feasible to modify the CSS of an iframe if the iframe is not located on the same domain? If so, what are some ways to apply and alter CSS for this situation? Any assistance would be greatly appreciated. <iframe id="frame1" width="100%" height="35 ...

Execute an AJAX request and dynamically update the page when the button is clicked simultaneously

Hello everyone, I'm a beginner in ajax and I'm encountering an issue with executing JavaScript when a button is clicked. What I'm trying to achieve is, when the button is clicked, I want to run an ajax function to call a PHP script for query ...

Having trouble with clearing divs function not working as expected

I'm facing a challenge in properly aligning 3 div elements without resorting to adding padding at the bottom of the wrapping div, which isn't the most practical solution. Check out the issue demo here How would you suggest addressing this parti ...