Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7643309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:24:58+00:00 2026-05-31T09:24:58+00:00

what i have is 3 divs, 1 for left 1 for center and 1

  • 0

what i have is 3 divs, 1 for left 1 for center and 1 for right
what i need is 3 columns – the left is always there, the center as well but it’s width should be adaptive if the right is there or not

<html>
<head>
</head>
<body>
    <div style="width:460px; padding:0px 20px;">
        <div style="float:left; background: red; width:100px;">
            red
        </div>
        <div style="float:left; background: yellow;  max-width:400px">
            yellow
        </div>
        <div style="float:left; background: green; width:100px;">
            green
        </div>
    </div>
</body>
</html>

what am i’m doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T09:24:59+00:00Added an answer on May 31, 2026 at 9:24 am

    The best I could come up with, in order to avoid JavaScript solutions and to use CSS and HTML only, is to use class-names for the columns, and to re-order your HTML in order that the right-most column is first in the html:

    <div class="wrap" style="width:500px">
        <div class="col right">Right Column</div>
        <div class="col left">Left column</div>
        <div class="col middle">Middle column</div>
    </div>
    <div class="wrap" style="width:500px">
        <div class="col left">Left column 2</div>
        <div class="col middle">Middle column 2</div>
    </div>​
    

    With the CSS adjacent-sibling selector, firstSibling + secondSibling, this can be used to amend the width of the middle column:

    .wrap {
        width: 500px;
        margin: 1em auto;
        overflow: hidden;
    }
    
    .left,
    .right {
        width: 100px;
        background-color: #ffa;
    }
    
    .middle {
        width: 400px;
        background-color: #f90;
    }
    
    .left,
    .middle {
        float: left;
    }
    
    .right {
        float: right;
    }
    
    div.right + div.left + div.middle {
        width: 300px;
    }
    

    JS Fiddle demo.

    If you float the .middle column right, instead of left as in the previous example, then you can simplify the adjacent-sibling selector, and the HTML is, effectively, visually reversed (which is slightly easier to understand/work with than the above example wherein the two columns come first, in reverse order, and then the middle column comes at the end), giving:

    <div class="wrap" style="width:500px">
        <div class="col right">Right Column</div>
        <div class="col middle">Middle column</div>
        <div class="col left">Left column</div>
    </div>
    <div class="wrap" style="width:500px">
        <div class="col left">Left column 2</div>
        <div class="col middle">Middle column 2</div>
    </div>​
    

    And the CSS:

    .wrap {
        width: 500px;
        margin: 1em auto;
        overflow: hidden;
    }
    
    .left,
    .right {
        width: 100px;
        background-color: #ffa;
    }
    
    .middle {
        width: 400px;
        background-color: #f90;
    }
    
    .left {
        float: left;
    }
    
    .right,
    .middle {
        float: right;
    }
    
    div.right + div.middle {
        width: 300px;
    }
    

    JS Fiddle demo.

    References:

    • Adjacent sibling selector, at the W3.org.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 2 divs that positioned horizontally ( float:left; width:50%; ). But i want
I have such structure (divs): #content-wrapper-> #left #center #right #footer #footer { position: relative;
Is there a way to have left-, center-, and right-aligned text on the same
I have three divs page-left page-right flipper I have images of equal size in
I have three divs with float:left <div class=center> <div class=fade1></div> <div class=fade2></div> <div class=fade3></div>
I have two divs that are sliding from right to left. I am having
I have two divs sr-left-checks and sr-right-checks. they both contain unordered lists. The left
I have the following HTML: <div id=root> <div id=left_side>LEFT</div> <div id=center_s>CENTER</div> <div id=right_side>RIGHT</div> </div>
I have a two columns layout (fluid left, fixed right). I want to put
Suppose I have an div. Inside this div, I have two divs floating left,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.