DIVs and css

Log in to stop seeing adverts

Status
Not open for further replies.

Joe_Fox

Well-Known Member
Can anyone help me?
I need to make a page layout that has four rows, one of which has two columns. The left column will always have content whereas the right column may or may not have any content.

If the right hand column contains no content, I want to hide the right hand column and expand the left hand column across the page but if the right hand column DOES contain some content, I want the right hand column to take up 50% of the page width.

What is the css property I should be using?
 
If the right hand column contains no content, I want to hide the right hand column and expand the left hand column across the page but if the right hand column DOES contain some content, I want the right hand column to take up 50% of the page width.

What is the css property I should be using?

There isn't one, you can't use CSS to dynamically set CSS, you will need to script it.

The easiest way to that is to use a framework like jQuery.

First off, either download the jquery library and point to it as you would any other .js file, or you can access it using the google api link:

Code:
<script type="text/javascript" src="jquery.js"></script>
OR:
Code:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>

Then include this script, either directly in the head of the page or point to it as a separate .js file. This will run when the page loads.

Code:
$(function() {
    var containsText = $('div#rightHand').text();
    if(containsText){
        $('div#rightHand').css({'width':'50%'});
        $('div#leftHand').css({'width':'50%'});
    }else{
        $('div#rightHand').css({'width':'0px'});
        $('div#leftHand').css({'width':'100%'});
    }
});

This assumes that you have two divs with IDs set to 'rightHand' and 'leftHand'. You can obviously call them what you want to, as long as you've explicitly set their ID.

*edit: This will work in all browsers btw
 
Last edited:
I didn't know that.
 
Status
Not open for further replies.
Log in to stop seeing adverts

Championship

P Pld Pts
1Leicester4697
2Ipswich4696
3Leeds Utd4690
4Southampton4687
5West Brom4675
6Norwich City4673
7Hull City4670
8Middlesbro4669
9Coventry City4664
10Preston 4663
11Bristol City4662
12Cardiff City4662
13Millwall4659
14Swansea City4657
15Watford4656
16Sunderland4656
17Stoke City4656
18QPR4656
19Blackburn 4653
20Sheffield W4653
21Plymouth 4651
22Birmingham4650
23Huddersfield4645
24Rotherham Utd4627
Top