Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > CSS > CSS Cascading Style Sheets
|
CSS Cascading Style Sheets All issues relating to Cascading Style Sheets (CSS).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the CSS Cascading Style Sheets section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 10th, 2006, 07:35 AM
Wrox Technical Editor
 
Join Date: Dec 2005
Posts: 271
Thanks: 0
Thanked 0 Times in 0 Posts
Default Possible to positioning two divs side by side?

I'd like to position two HTML Div tags horizontally (side by side) with one single CSS class that is compatible with Fire fox and IE.

I am aware of the common ways to positioning Div tags horizontally like:
  Assigning "Float: left" and "Float: right" to the respective div containers, but this method requires two separate CSS classes or attributes.

I want to display Div tags horizontally from a single class - I'm using a custom control that generates tables wrapped in Divs from a asp:Formviews, I really don't want to change the custom control.

An Example:

.FormViewCSS
{
  /*Some CSS Here*/
}

<div class=”FormViewCSS”>

</div>

<div class=”FormViewCSS”>

</div>

Any suggestions?

- Adam Kahtava [http://adam.kahtava.com]
__________________
- Adam Kahtava [http://adam.kahtava.com]
 
Old October 10th, 2006, 07:48 AM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

It's not possible, every method requires at least two rules, sometimes more. One rule would logically tell us the divs are identical anyway, and they clearly aren't. You want one on the right and one on the left, that one difference destroys what you want to do.

Regards,
Rich

--
Author,
Beginning CSS: Cascading Style Sheets For Web Design
CSS Instant Results

http://www.catb.org/~esr/faqs/smart-questions.html
 
Old October 10th, 2006, 09:37 AM
Wrox Technical Editor
 
Join Date: Dec 2005
Posts: 271
Thanks: 0
Thanked 0 Times in 0 Posts
Default

That's not the answer I was hoping for. :)

Thanks Rich.

- Adam Kahtava [http://adam.kahtava.com]
 
Old October 10th, 2006, 02:15 PM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Well, you might experiment anyway.

Theoretically, you can float both left or both right. Then set the width to 50%. Problem with that approach, if you don't run into other problems, is IE. It's pretty buggy with percentage measurements (one of the divs will more than likely drop down to the next line, IE just doesn't make 50% + 50% = 100%. Also, since percentage measurement is based on the containing block, if you have padding, borders, or margins you'll go over 50% and get scroll bars. If you want a background or borders or anything like that, you'll have to set the margin of one of the two to margin-left: 50%;

The best approach, IMO, is positioning the content absolutely, which gets around the percentage bug in IE, but that requires at least two rules. One with left: 0;, and the other with left: 50%;

I don't have any experience with ASP, so I'm at a loss to suggest anything else. Imar or one of the other resident ASP gurus might have a suggestion.

Regards,
Rich

--
Author,
Beginning CSS: Cascading Style Sheets For Web Design
CSS Instant Results

http://www.catb.org/~esr/faqs/smart-questions.html
 
Old October 10th, 2006, 03:50 PM
Wrox Technical Editor
 
Join Date: Dec 2005
Posts: 271
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Rich,

Thanks, I am aware of the 50/50, left/right percentage problem with IE and the work around using 48% in place of 50%.

If I use a container box with the style attributes set to "display: inline" will the divs within the container display side by side?


- Adam Kahtava [http://adam.kahtava.com]
 
Old October 10th, 2006, 03:59 PM
Wrox Technical Editor
 
Join Date: Dec 2005
Posts: 271
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The solution:

FormViewCSS
{
  display: inline;
}

<div class=”FormViewCSS”>

</div>

<div class=”FormViewCSS”>

</div>

Both div tags will be displayed side by side or horizontally.

- Adam Kahtava [http://adam.kahtava.com]
 
Old October 10th, 2006, 04:04 PM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

> Thanks, I am aware of the 50/50, left/right percentage problem with IE and the work around using 48% in place of 50%.

I think you can also use 49.99%.

> If I use a container box with the style attributes set to "display: inline" will the divs within the container display side by side?

It might work, depends on what the children elements are. Once display is set to inline you can no longer set a width. In IE quirks mode width still applies to inline elements, but every other browser and IE in standards mode ignore width and height on inline elements.

You could use display: inline-block; (width and height still apply there) but that only works in IE, and maybe Opera, and possibly Safari. Doesn't work in Firefox, that I know for sure. Depends on what browsers you're targeting, I guess.

Regards,
Rich

--
Author,
Beginning CSS: Cascading Style Sheets For Web Design
CSS Instant Results

http://www.catb.org/~esr/faqs/smart-questions.html
 
Old October 11th, 2006, 09:39 AM
Wrox Technical Editor
 
Join Date: Dec 2005
Posts: 271
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Rich,

Greatly appreciated.

- Adam Kahtava [http://adam.kahtava.com]





Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem Converting Client-side to Server-side Code kwilliams ASP.NET 2.0 Professional 1 November 21st, 2007 05:25 PM
Firing server side events at client side codes mehdi62b ASP.NET 1.0 and 1.1 Basics 6 May 18th, 2005 09:11 AM
sharing a server-side variable with client-side pigtail Javascript How-To 6 November 4th, 2004 02:01 AM
Two Client Side vs Server Side issues Milo Classic ASP Professional 5 May 25th, 2004 02:47 PM
Accessing Server Side Data on Client Side steve456 Classic ASP Professional 3 October 15th, 2003 02:33 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.