skip to Main Content

I have a responsive <div> element placed in between two fixed <div> elements. I’ve tried the following code:

 <html>
 <head>
 <title>Sample1</title>
 <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.4/css/bootstrap.min.css">
 </head>
 <body>
     <div style="width: auto">
         <div style="float: left; width:270px; background-color: green">Fixed div</div>
         <div style="float: right; width: 120px; background-color: yellow"> Fixed div</div>
         <div style="background-color: red" class="row">Responsive div</div>        
     </div>
</body>
</html>

Currently the responsive <div> element is taking the whole screen. When I try to checkout the width and height, it has acquired my entire main <div>. Is there any approach where I can put this responsive <div> inside 2 fixed <div>?

3

Answers


  1. Try with this:

    <body style="display:table;width:100%;">
      <div style="float: left; width:270px; background-color: green;display:table-cell;">Fixed div </div>
      <div style="background-color: red;display:table-cell;" class="row"> Responsive div </div>  
      <div style="float: right; width: 120px; background-color: yellow;display:table-cell;"> Fixed div</div>  
    </body>
    
    Login or Signup to reply.
  2. Since you got their div widths already, we can took advantage of the calc

    width: calc(100% - 390px);
    

    The 390px value is the sum of the width of left and ride side elements.

    <html>
     <head>
     <title>Sample1</title>
     <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.4/css/bootstrap.min.css">
     </head>
     <body>
      <div style="width: auto">
        <div style="float: left; width:270px; background-color: green">Fixed div </div>
        <div style="float: right; width: 120px; background-color: yellow"> Fixed div</div>
        <div style="background-color: red;  width: calc(100% - 390px);margin-left: 270px;" class="row"> Responsive div </div>
    
      </div>
    </body>
    </html>
    Login or Signup to reply.
  3. Check below code: Here I have altered Div sequence and change display style of the three.

    <html>
     <head>
       <title>Sample1</title>
       <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.4/css/bootstrap.min.css">
     </head>
     <body>
      <div style="display:table; width:100%">
        <div style="display:table-cell; width:270px; background-color: green">Fixed div </div>
        <div style="background-color: red; display:table-cell;"> Responsive div </div>
        <div style="display:table-cell; width: 120px; background-color: yellow"> Fixed div</div>
      </div>
    </body>
    </html>
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search