---
title: "Rubber Layouts – Combining Static and Fluid Layouts"
id: "15511"
type: "post"
slug: "rubber-layouts-combining-static-and-fluid-layouts"
published_at: "2011-08-31T09:53:52+00:00"
modified_at: "2024-05-15T16:07:10+00:00"
url: "https://speckyboy.com/rubber-layouts-combining-static-and-fluid-layouts/"
markdown_url: "https://speckyboy.com/rubber-layouts-combining-static-and-fluid-layouts.md"
excerpt: "Many web pages nowadays are using fluid layouts. While these are very useful, they do have some minuses. Imagine trying to read a fluid layout on your phone – it’s..."
taxonomy_category:
  - "Web Design"
taxonomy_post_tag:
  - "Code Snippet"
  - "Responsive Web Design"
---

# Rubber Layouts – Combining Static and Fluid Layouts

Last Update:  May 15, 2024  
 By  Alexandre Smirnov

[Web Design](https://speckyboy.com/category/web-design/)

Many web pages nowadays are using fluid layouts. While these are very useful, they do have some minuses. Imagine trying to read a fluid layout on your phone – it’s impossible.

The sidebar would be maybe 50px wide, and the main layout would be maybe 250px. Another problem is with really wide screens – the layout fills up almost the whole screen, which results in a horrible reading experience.

Today, I’ll show you how to take the best of two worlds: static layouts and fluid layouts. We’ll call this a **rubber layout**.

Let me explain how everything will work. There are going to be four stages for the layout.

- **First**, there’s going to be a container of 1000px wide.
- **Second**, using media queries, we’ll change the width of the container to 720px when the user’s browser is 999px wide.
- **Thirdly**, once the user’s browser is 719px wide, we’ll change the main container to have a width of 100%, so everything fits right in the browser.
- The **fourth** and final stage will make everything inside the container have an equal width. This change will happen at 479px.

![CSS Rubber Layouts](https://speckyboy.com/wp-content/uploads/2011/08/rubber_layout.jpg)

## Stage 1 – The HTML & CSS

### The HTML

First off, we’ll have to code an extremely simple layout. There’s going to be a header, a main content div, and a sidebar.

```
<div id="container">

  <h1 id="header">Rubber</h1>

  <div id="main">

  </div>

  <div id="sidebar">

  </div>

</div>
```

That’s it for the HTML.

### The CSS

Great, we’re at the fun part. We’ll start off by defining a default set of widths for everything.

```
#container {
width: 1000px;
margin: 0 auto;
background: #52a0ff;
}

#header {
font-size: 50px;
margin-top: 50px;
float: left;
width: 98%;
margin-left: 1%;
margin-right: 1%;
}

#main{
background: #eeeeee;
float: left;
width: 68%;
margin-left: 1%;
margin-right: 1%;
height: 1000px;
}

#sidebar{
background: #dddddd;
float: left;
width: 28%;
margin-left: 1%;
margin-right: 1%;
height: 1000px;
}
```

Notice the widths of the header, main, and sidebar elements. They are in percentages for a reason. More about this later.

## Stage 2

In stage 2, the container will change to 720px wide.

```
@media screen and (max-width: 999px) {
#container {
width: 720px;
}
}
```

As you can see, we aren’t redefining the widths of the header, main, and sidebar elements, because they automatically scale to fit into their new size container. That’s part of the beauty of rubber layouts.

## Stage 3

When the user’s browser is 719px wide, the layout changes, and the container becomes fluid.

```
@media screen and (max-width: 719px) {
#container {
width: 100%;
}
}
```

Now, when the user resizes their browser, the layout resizes with them as well. This is useful for tablets and small laptops.

## Stage 4

When the user’s browser hits 479px, all of the elements will become the same size. This solves the problem with iPhones and Androids and such.

```
@media screen and (max-width: 479px) {
#header {
width: 98%;
}

#main {
width: 98%;
}

#sidebar {
width: 98%;
}
}
```

## Finished!

That’s it! We’ve got a fully functional rubber layout, with four stages depending on browser sizes. Widescreen, small screens, smaller screens, and handheld devices.

[Download the Source Files](https://speckyboy.com/wp-content/uploads/2011/08/rubber-layout-source.zip)

## Related Articles

- [What is Responsive Web Design?](https://speckyboy.com/responsive-design-101/) It wasn't too long ago that designers didn't really need to worry about how websites looked on mobile phones and tablets. Phones weren't yet really…
- [How to Create Responsive Off-Screen Menus with CSS3](https://speckyboy.com/off-screen-menus-transition-css3/) In this tutorial, we're going to create some slide and push menus using CSS3 transitions. The menus will be hidden off screen at first, and…
- [How to Create a Full Width Responsive Tiled Menu with CSS](https://speckyboy.com/full-width-responsive-tiled-menu/) Full width tiled menus are a crisp way for displaying your site's navigation and for giving end to end coverage, creating a very full-bodied effect…
- [Things You Have to Consider When Designing for Mobile](https://speckyboy.com/things-you-have-to-consider-when-designing-for-mobile/) As designers, we will have to start thinking about mobile users by designing not only for desktops but also for smaller devices.
- [10+ Free Responsive Website Mockup Templates for UI Designers](https://speckyboy.com/free-responsive-website-mockup-template/) A fantastic collection of free responsive website mockups templates you can use to showcase your web design in realistic scenarios.

## Related Topics

- [Code Snippet](https://speckyboy.com/topic/code-snippet/)
- [Responsive Web Design](https://speckyboy.com/topic/responsive-web-design/)

## Written by Alexandre Smirnov

Alexandre Smirnov is a web developer and designer who lives and works in California. He enjoys creating cool new stuff out of CSS3 and HTML5, and is convinced that Jquery is the meaning of life. He also regularly writes on his blog, DesignLunatic.com.

[Read more articles by Alexandre Smirnov](https://speckyboy.com/author/alexandresmirnov/)

---

Top

This page may contain affiliate links. At no extra cost to you, we may earn a commission from any purchase via the links on our site. You can [read our Disclosure Policy](https://speckyboy.com/affiliate-disclosure/)
 at any time.
