Click here to Skip to main content
15,881,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am building this module in html and css I would like to avoid the use of JavaScript. To help explain what I'm trying to create I've attached a picture.

http://imageshack.com/a/img716/2821/nd4x.jpg[^]

Box A - #left will have a picture inside
Box B - #right will have text inside.
Neither Box A or B can overlap each other.

So far - I have managed to build the module relying on (%) and have got it to rescale smaller or larger depending on the width of browser. But it's not quite working how I intend it to yet.

The problem I'm facing -

When the module is scaled down to its smallest with the help of (min-width) Box B's width scales down with it. This is not what I intend to happen, Box B needs to stay a fixed (px) width while Box A rescales by a (%) width.

To overcome this problem I tried giving Box B (px) width instead of (%). This made matters worse - now when the browser is scaled down to its smallest Box B leaves the viewport & the scrollbars (x axis) takeover. Box B needs to be within the viewport even at the smallest scale. Any ideas of how to get this working? Thanks.

html -
HTML
<div id="outer">
<div id="left">Box A</div>
<div id="right">Box B</div>
</div>

css -
CSS
#outer {
background-color:#830000;
margin:0px 0px 0px 0px;
max-width:815px;
min-width:518px;
position:relative;
width:100%;
z-index:1;
}
/*Box A*/
#left {
background-color:#b1b1b1;
float:left;
padding-bottom:57%;
position:absolute;
width:72%;
height:10px; /* extra 10px helps show overlap of #left onto #right*/
z-index:2;
}
/*Box B*/
/*Switch between #right(px) and #right2(%) for the two outcomes I'm getting*/
#right { /* using px - Good - the width is fixed, But - should not overlap #left */
width:229px; 
background-color:#81dd27;
float:right;
padding-bottom:57%;
position:relative;
z-index:1;
}
#right2 { /*using % - Good - no overlapping, But - the width of 229px decreases*/
width:28%; 
background-color:#81dd27;
float:right;
padding-bottom:57%;
position:relative;
z-index:1;
}

http://codepen.io/JimTiger/pen/mlvLE[^]
Posted
Updated 15-Nov-13 2:53am
v3
Comments
Jimtiger 15-Nov-13 8:29am    
vbmike - Try increasing the z-index of #right to 3 and see if that is what you are trying to achieve.
Jimtiger 15-Nov-13 8:48am    
Hi Mike. I forgot to mention #left will have a picture inside. Changing #right z-index to 3 will overlap the image inside #left. #right will have text inside it, so neither can overlap each other. Do you think this will be possible with css alone? or will JavaScript be the only way.
vbmike 15-Nov-13 9:01am    
what is the size of the picture?
Jimtiger 15-Nov-13 9:21am    
width - 586px
height - 483px
vbmike 15-Nov-13 9:18am    
Try placing a 100x100 placeholder image inside your div. use this css for the img:
img {
display: block;
position: absolute;
top:0;bottom:0;right:0;left:0;
margin: auto;
vertical-align: middle;
}
You will have to play around with the text etc. Experiment. Most anything can be done with css only. There are numerous solutions probably.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900