 |
| 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
|
|
|
|

October 10th, 2006, 07:35 AM
|
|
Wrox Technical Editor
|
|
Join Date: Dec 2005
Posts: 271
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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]
|
|

October 10th, 2006, 09:37 AM
|
|
Wrox Technical Editor
|
|
Join Date: Dec 2005
Posts: 271
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
That's not the answer I was hoping for. :)
Thanks Rich.
- Adam Kahtava [ http://adam.kahtava.com]
|
|

October 10th, 2006, 02:15 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
|
|
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
|
|

October 10th, 2006, 03:50 PM
|
|
Wrox Technical Editor
|
|
Join Date: Dec 2005
Posts: 271
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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]
|
|

October 10th, 2006, 03:59 PM
|
|
Wrox Technical Editor
|
|
Join Date: Dec 2005
Posts: 271
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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]
|
|

October 10th, 2006, 04:04 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
|
|
> 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
|
|

October 11th, 2006, 09:39 AM
|
|
Wrox Technical Editor
|
|
Join Date: Dec 2005
Posts: 271
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks Rich,
Greatly appreciated.
- Adam Kahtava [ http://adam.kahtava.com]
|
|
 |