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 439161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T20:44:56+00:00 2026-05-12T20:44:56+00:00

I have the following layout with a sidebar that is only present on some

  • 0

I have the following layout with a sidebar that is only present on some pages and not others. When the sidebar is not present #main should fill the available width of the container.

It works but makes use of a CSS expression – is it possible to achieve the same layout without this expression?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="application/xhtml+xml; charset=utf-8" />
<style type="text/css">
/* reset css */

* {
    border: 0px none;
    margin: 0;
    padding: 0;
    vertical-align: baseline;
    font-family: inherit;
    font-style: inherit;
    font-weight: inherit;
    font-size: 100%;
}

/* end reset */

#container {
    margin: 0 auto;
    width: 800px;
    background-color: red;
}

#sidebar {
    display: inline;
    float: left;
    width: 130px;
    background-color: green;
}

#main {
    float: left;
    background-color: blue;
    width: expression(document.getElementById('sidebar') == null ? "100%" : "670px");
    max-width: 100%;
}

#sidebar + #main {
    width: 670px;
    background-color: yellow;
}

#clear {
    clear: both;
    height: 1px;
    font-size: 0px;
}
</style>
</head>
<body>
<div id="container">
    <div id="sidebar"><p>This is the side bar</p></div>
    <div id="main"><p>This needs to expand to fill available width, what if I have sufficient content in here to push this div so it spans across the whole width of the page like so...</p></div>
    <div id="clear"></div>
</div>
</body>
</html>
  • 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-12T20:44:56+00:00Added an answer on May 12, 2026 at 8:44 pm

    The + adjacency selector would do it, except in IE6 where it isn’t supported. The usual workaround would be to add some extra class information:

    <div id="container" class="with-sidebar">
    

    and then select on that in the stylesheet:

    #sidebar { float: left; width: 130px; }
    .with-sidebar #main { margin-left: 130px; }
    

    This needs to expand to fill available width

    Then don’t bother make it float; I’m not sure what that’s supposed to achieve.

    Also avoid ‘inherit’ rules, they don’t work in IE previous to version 8.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following layout: <div id=content> <div id=img><img src=></div> <div id=main>Some content</div> <div
Suppose I have the following directory layout in a Maven project: src/ |-- main
Say I have the following DIVs: <div id=top>Page header</div> <div id=main>Main content</div> <div id=sidebar>Sidebar
I have the following layout for my test suite: TestSuite1.cmd: Run my program Check
I have the following div layout: Everything is fine when I put normal txt
I have following string String str = replace :) :) with some other string;
I have following situation. A main table and many other tables linked together with
I have the following layout in my project (quite simplified): Assembles App.WinClient <--- client
I have the following layout: <?xml version=1.0 encoding=utf-8?> <RelativeLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=fill_parent android:layout_height=fill_parent> <GridView android:id=@+id/grid
I have the following layout. This defines a row in my ListView. I noticed

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.