Solved

make child div 100% width of parent

Posted on 2009-07-14
10
468 Views
Last Modified: 2012-05-07
hi there; a little backstory first: i need to display 2 dynamically generated divs horizontally.  now because it is impossible to know the widths of these divs before they are rendered, i am unable to simply float them (which is why i have made them inline).

my first question; is this an acceptable method to acheive the intened result.  seems to work.

second, and more importantly, i would like the header height div to be 34px and stretch the entire width of the parent div.  

without a height, the header div stretches as intended.  however, as soon as a height is applied, the header div ends at whatever width the header text is (see attached image where red div (css_heading) has height applied and div below that (css_subheading) has no height applied and displays perfect).

*** this is only an issue in explorer ... not firefox

my question is, why is this and what can be done to resolve the issue?

thanks all.
.css_container
{
    border:solid 1px #dcdcdc;
    font-family: arial, verdana;
    font-size:13px;
}
 
 
 
.css_container .css_heading
{   
    background-color:red; 
    font-size:17px;
    height:34px;
}
 
 
.css_container .css_subheading
{   
    background-color:#eaeaea;
    font-weight:bold;
}
 
 
.css_container .css_content
{   
    padding:5px;
}

Open in new window

width-v01.jpg
0
Comment
Question by:vbnewbie01
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
10 Comments
 
LVL 4

Expert Comment

by:ryangiglio
ID: 24854575
I can't be sure without seeing the HTML of the page, but try making the divs display:block instead of display:inline. Or is that impossible because of the way the page is set up?
0
 
LVL 1

Author Comment

by:vbnewbie01
ID: 24854685
sorry, meant to include that (see below) ...

i had origianlly tried block in the css_heading div and no luck.

thanks.
<div style="float:left; display:inline; margin-right:20px;">
                <div class="css_container">
                    <div class="css_heading"> This is a heading This is a heading This is a heading This</div>
                    <div class="css_subheading"> This is a heading</div>
                    <div class="css_content"> This is a whole bunch of content in the content area This is a whole bunch of content in the content area</div>
                </div>
            </div>

Open in new window

0
 
LVL 4

Expert Comment

by:ryangiglio
ID: 24854799
This is an odd solution, but it occured to me that header tags (<h1>, <h2>, etc) always span the entire width of an area...so...


.css_container .css_heading
{   
    background-color:red; 
	width:100%;
}
 
.css_heading h2
{
	background-color:red;
    height:34px;
	margin:0px;
	display:inline;
 
}
 
<div style="float:left;">
	<div class="css_container">
		<div class="css_heading">
			<h2>This is a heading This is a heading This is a heading This</h2>
		</div>
		<div class="css_subheading"> This is a heading</div>
		<div class="css_content"> This is a whole bunch of content in the content area This is a whole bunch of content in the content area</div>
	</div>
</div>

Open in new window

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:vbnewbie01
ID: 24855034
hi, ryangiglio; unfortunately, exact same result.  if you can screencap it working, would love to see.

thanks.
0
 
LVL 1

Author Comment

by:vbnewbie01
ID: 24855038
btw my doctype is strict ...
0
 
LVL 4

Accepted Solution

by:
ryangiglio earned 250 total points
ID: 24856044
Sure.

this is the HTML I'm looking at.

Attached are IE8 and IE7 screenshots.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
<style type="text/css"> 
 
.css_container
{
    border:solid 1px #dcdcdc;
    font-family: arial, verdana;
    font-size:13px;
}
 
.css_container .css_heading
{   
    background-color:red; 
        width:100%;
}
 
.css_heading h2
{
        background-color:red;
    height:34px;
        margin:0px;
        display:inline;
 
}
 
.css_container .css_subheading
{   
    background-color:#eaeaea;
    font-weight:bold;
}
 
 
.css_container .css_content
{   
    padding:5px;
}
 
</style>
</head>
 
<body>
<div style="float:left;">
        <div class="css_container">
                <div class="css_heading">
                        <h2>This is a heading This is a heading This is a heading This</h2>
                </div>
                <div class="css_subheading"> This is a heading</div>
                <div class="css_content"> This is a whole bunch of content in the content area This is a whole bunch of content in the content area</div>
        </div>
</div>
</body>
</html>

Open in new window

IE7.png
IE8.png
0
 
LVL 1

Author Comment

by:vbnewbie01
ID: 24861852
hi, ryangiglio; thanks for those however, i have copy and pasted your exact code into a fresh page in not one but two of my computers and i still get the exact same result (see attached).  also tested in ie8 which renders like ie7.

i also tried going to the getdropbox.com url but i guess you've removed it?

thanks.
width-v02.jpg
0
 
LVL 4

Expert Comment

by:ryangiglio
ID: 24861938
http://files.getdropbox.com/u/1264486/test3.html

It's still up and public.

I tested it on my Work PC in IE8 and IE7 Compatibility and it looks like the two screenshots I posted.

Strange.
0
 
LVL 1

Author Comment

by:vbnewbie01
ID: 24862422
the issue, i discovered, is in it's compatability mode.  when i run in ie7 i get my 'broken' display ... when i run in ie8 i get your 'working' solution.

not sure how you got your ie7.png image working but it certainly doesn't for me.

unfortunately, i need a ie6/ie7 solution at this point )=

thanks again.
0
 
LVL 4

Expert Comment

by:ryangiglio
ID: 24862489
Ah, I'm sorry about that.

Unfortunately I don't have a machine running genuine IE7 (all Macs at home) so I can't be of any more help.

I hope someone else finds you a solution.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
In this tutorial viewers will learn how to embed custom externally-hosted Google Fonts using the Google Font API in CSS Go to the Google Fonts website at google.com/fonts: Browse or search based on font properties or name to find a suitable font for…
Suggested Courses

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question