Align width of container div to the sum of floating div - css

I have the following html:
<div class="main_container">
<div class="sub_container">
<div class="floating">wookie1</div>
...
<div class="floating">wookie5</div>
</div>
</div>
Consider it's like an image gallery.
main_container has an unfixed size, it's set as a percentage of the user resolution.
I want sub_container to have the exact width of the sum of the floating div.
If I use "display:table;" for sub_container and "display: inline-block;" for floating divs, it works fine:
until I have enough div in the list, so that the sum of width is larger than main_container and they break on the next line:
But still, I want subcontainer (yellow background) to to be ALWAYS the EXACT WIDTH of the sum of the divs, even when they go on several lines, like this:
I've googled for hours now, and wasn't able to find an elegant solution (css only, if possible.)
Here's the jsfiddle, to play with this.

Pure CSS Solution
The problem is that for the items to "know" to wrap to the next line, the container has to have "filled" its available horizontal space, which is your .main_container width. Yet you want the background to not go beyond what is needed for the actual elements themselves. So I've used the elements themselves to create the background with the help of cobbled together pseudo-elements.
Here's the fiddle (tested in IE9, Firefox 18, Chrome 24 on a Win 7 machine)
What I am doing is piecing together the background with each individual .floating element, which makes the right most element to be the right border control for the size of the background (note the two different width examples in the fiddle).
The explanation of each part is given in the comments below. There are a two key limitations to note:
The .floating cannot have a position set, so that is a potential limitation based on particular application.
The background needs to be either a solid color or purely vertical oriented "motion" (i.e. a gradient fading from top to bottom, or horizontal lines would work).
KEY CSS (with explanatory comments)
.sub_container {
border-left: 1px solid #333; /* forms its own left border */
overflow: hidden; /* needed for background and border to work */
position: relative; /* positioning background off this */
z-index: 1; /* needs a stacking context */
}
.floating {
font-size:20px;
line-height:30px;
padding:0 5px 0 5px;
border: 1px solid black;
margin: 3px;
display: inline-block;
/* NOTE: CANNOT be given positioning */
}
.floating:after {
content: '';
position: absolute; /* will position off subcontainer */
border-top: 1px solid black; /* makes the top/bottom border itself */
border-bottom: 1px solid black;
z-index: -1; /* push it to the background */
top: 0; /* set it to top of sub_subcontainer */
bottom: 0; /* set it to bottom of sub_container */
margin-left: -100%; /* shove it past the far left edge of sub_container */
/* next, use padding to bring it back to its position at the end
of the text string of .floating */
padding-left: 100%;
/* next, add enough padding on the right to compensate for the right
padding, right margin, and right border of .floating */
padding-right: 9px;
background-color: yellow; /* set your background color */
/* NOTE: this will not work with a background image that
has any horizonal differences to it (top to bottom
gradient would probably be okay) */
}
.floating:before { /* make right border */
content: '';
padding-top: 10000px; /* give it some obscene height that will not be exceeded */
margin: -5000px 0; /* counter the padding height by half size margins top/bottom */
/* next, push this behind the background with an even lower z-index
to hide it if it is not the right most element beign used to
form the right border */
z-index: -2;
border-right: 1px solid black; /* make the right border */
float: right; /* get the before element to the right */
position: relative; /* needs to be adjusted in position */
right: -9px; /* move it same as padding-right of the after element */
display: block; /* give it a display */
}

I got bored trying this and created a JS script based on jQuery to solve it.
var t = $(".sub_container").width()/$(".floating").outerWidth();
$(".sub_container").width(parseInt(t) * $(".floating").outerWidth());
Demo

Reread your question...since you won't commit to anything (max-width:80%, 500px, etc) I broke everything on the 4th child - per your example.
CSS
.main_container, .sub_container, .floating { outline:1px solid black }
.sub_container { background-color:yellow; display:table; padding-left:5px }
.floating {
float:left;
padding:5px;
margin:5px 5px 5px 0;
}
.floating:nth-child(4n+5) {
clear:left;
float:left;
}
HTML
<div class="main_container">
<div class="sub_container">
<div class="floating">wookie1</div>
<div class="floating">wookie2</div>
<div class="floating">wookie3</div>
<div class="floating">wookie4</div>
<div class="floating">wookie5</div>
<div class="floating">wookie6</div>
<div class="floating">wookie7</div>
<div class="floating">wookie8</div>
<div class="floating">wookie9</div>
</div>
</div>
EDIT (option 2)
I don't believe what you're trying to do can be accomplished by HTML/CSS alone. I offer another solution based on a hunch...and your Image Gallery comment.
CSS
.main_container, .sub_container, .floating { outline:1px solid black }
.main_container {
text-align:center
}
.sub_container { background-color:yellow; display:inline-block; max-width:80%; }
.floating {
display:inline-block;
padding:5px;
margin:5px;
}
HTML
<div class="main_container">
<div class="sub_container">
<div class="floating">wookie1wookie1wookie1</div>
<div class="floating">wookie2</div>
<div class="floating">wookie3</div>
<div class="floating">wookie4</div>
<div class="floating">wookie5</div>
<div class="floating">wookie6wookie6</div>
<div class="floating">wookie7wookie7wookie7</div>
<div class="floating">wookie8</div>
<div class="floating">wookie9</div>
</div>
</div>
It does not make .subcontainer snap to the contents; however, (using max-width) it does allow you to give it some breathing room from the main container and its children can be of various sizes.

Delete main container width and .sub_container position absolute and you should be good to go.
.main_container {
#width:380px;
}
.sub_container {
#position: absolute;
}

Use span element instead of div for "sub_container"
.sub_container{background-color:yellow;}

Related

If you specify `bottom: 0` for position: sticky, why is it doing something different from the specs?

This is a question when I read an article on the MDN position property. I thought that there was a clear difference between the behavior of sticky described there and the actual behavior.
According to the MDN, sticky position elements are treated as relative position elements until the specified threshold is exceeded, and when the threshold is exceeded, they are treated as fixed position elements until the boundary of the parent element is reached (Link).
Sticky positioning can be thought of as a hybrid of relative and fixed positioning. A stickily positioned element is treated as relatively positioned until it crosses a specified threshold, at which point it is treated as fixed until it reaches the boundary of its parent. For instance...
#one { position: sticky; top: 10px; }
...would position the element with id one relatively until the viewport were scrolled such that the element would be less than 10 pixels from the top. Beyond that threshold, the element would be fixed to 10 pixels from the top.
So, I created the following code and confirmed the operation.
body {
margin: 0;
}
.container {
display: flex;
flex-direction: column;
}
.container>* {
width: 100%;
}
header {
background: #ffa;
height: 130vh;
}
main {
background: #faf;
height: 210vh;
}
footer {
background: #faa;
height: 8vh;
position: sticky;
bottom: 0;
}
.footer {
background: #aff;
height: 100vh;
}
<div class="container">
<header>HEADER</header>
<main>MAIN CONTENT</main>
<footer>FOOTER</footer>
<div class="footer"></div>
</div>
According to the MDN article, this code "is a relative placement element until the position of the element is less than 0px from the bottom of the viewport by scrolling the viewport, and becomes a fixed placement element when it is more than 0px from the bottom" I was thinking.
However, the result is the action of "Scroll to the fixed position element until the position of the element becomes smaller than 0px from the lower end of the viewport by scrolling the viewport, and become the relative arranged element when larger than 0px from the lower end".
Why does specifying the bottom:0 result in the opposite of the behavior shown in MDN?
When top: 0 is specified, the relative position is applied when the element does not reach bottom: 0 of the viewport, and when it reaches, fixed position is applied. When bottom: 0 is specified, the opposite is true. The relative position is applied when the element does not reach the bottom: 0 of the viewport, the fixed position is applied when it is reached
I read CSS3 but its mechanism was difficult to read
According to the MDN, sticky position elements are treated as relative position elements until the specified threshold is exceeded
It's all a matter of language here because the above sentence doesn't mean the element will necesseraly start position:relative then become fixed. It says until the specified threshold is exceeded. So what if initially we have the specified threshold exceeded? This is actually the case of your example.
In other words, position:sticky has two states.
It's treated as relative
It's treated as fixed when the specified threshold is exceeded
Which one will be the first will depend on your HTML structure.
Here is a basic example to illustrate:
body {
height:150vh;
margin:0;
display:flex;
flex-direction:column;
border:2px solid;
margin:50px;
}
.b {
margin-top:auto;
position:sticky;
bottom:0;
}
.a {
position:sticky;
top:0;
}
<div class="a">
I will start relative then I will be fixed
</div>
<div class="b">
I will start fixed then I will be relative
</div>
You can also have a mix. We start fixed, become relative and then fixed again:
body {
height:250vh;
margin:0;
display:flex;
flex-direction:column;
border:2px solid;
margin:50px;
}
body:before,
body:after {
content:"";
flex:1;
}
.a {
position:sticky;
top:0;
bottom:0;
}
<div class="a">
I will start fixed then relative then fixed
</div>
As you can see in the above examples both states are independent. If the condition of the position:fixed is true then we have position:fixed, if not then it's relative.
We can consider that the browser will implement this pseudo code:
on_scroll_event() {
if(threshold exceeded)
position <- fixed
else
position <- relative
}
For more accurate and complete understanding of the mechanism, you need to consider 3 elements. The sticky element (and the values of top/bottom/left/right), the containing block of the sticky element and the nearest ancestor with a scrolling box.
The nearest ancestor with a scrolling box is simply the nearest ancestor with overflow different from visibile and by default it will be the viewport (as I explained here: What are `scrolling boxes`?). The scroll on this element will control the sticky behavior.
The containing block for a sticky element is the same as for a relative element ref
Left/top/bottom/right are calculated relatively to the scrolling box and the containing block will define the limit of the sticky element.
Here is an example to illustrate:
body {
margin:0;
}
.wrapper {
width:300px;
height:150px;
border:2px solid red;
overflow:auto;
}
.parent {
height:200%;
margin:100% 0;
border:2px solid;
}
.sticky {
position:sticky;
display:inline-block;
margin:auto;
top:20px;
background:red;
}
.non-sticky {
display:inline-block;
background:blue;
}
<div class="wrapper"><!-- our scrolling box -->
<div class="parent"><!-- containing block -->
<div class="sticky">I am sticky</div>
<div class="non-sticky">I am the relative position</div>
</div>
</div>
Initially our element is hidden which is logical because it cannot be outside its containing block (its limit). Once we start scrolling we will see our sticky and relative elements that will behave exactly the same. When we have a distance of 20px between the sticky element and the top edge of the scrolling box we reach the threshold and we start having position:fixed until we reach again the limit of the containing block at the bottom (i.e. we no more have space for the sticky behavior)
Now let's replace top with bottom
body {
margin:0;
}
.wrapper {
width:300px;
height:150px;
border:2px solid red;
overflow:auto;
}
.parent {
height:200%;
margin:100% 0;
border:2px solid;
}
.sticky {
position:sticky;
display:inline-block;
margin:auto;
bottom:20px;
background:red;
}
.non-sticky {
display:inline-block;
background:blue;
}
<div class="wrapper"><!-- our scrolling box -->
<div class="parent"><!-- containing block -->
<div class="sticky">I am sticky</div>
<div class="non-sticky">I am the relative position</div>
</div>
</div>
Nothing will happen because when there is a distance of 20px between the element and the bottom edge of the scrolling box the sticky element is already touching the top edge of the containing block and it cannot go outside.
Let's add an element before:
body {
margin:0;
}
.wrapper {
width:300px;
height:150px;
border:2px solid red;
overflow:auto;
}
.parent {
height:200%;
margin:100% 0;
border:2px solid;
}
.sticky {
position:sticky;
display:inline-block;
margin:auto;
bottom:20px;
background:red;
}
.non-sticky {
display:inline-block;
background:blue;
}
.elem {
height:50px;
width:100%;
background:green;
}
<div class="wrapper"><!-- our scrolling box -->
<div class="parent"><!-- containing block -->
<div class="elem">elemen before</div>
<div class="sticky">I am sticky</div>
<div class="non-sticky">I am the relative position</div>
</div>
</div>
Now we have created 50px of space to have a sticky behavior. Let's add back top with bottom:
body {
margin:0;
}
.wrapper {
width:300px;
height:150px;
border:2px solid red;
overflow:auto;
}
.parent {
height:200%;
margin:100% 0;
border:2px solid;
}
.sticky {
position:sticky;
display:inline-block;
margin:auto;
bottom:20px;
top:20px;
background:red;
}
.non-sticky {
display:inline-block;
background:blue;
}
.elem {
height:50px;
width:100%;
background:green;
}
<div class="wrapper"><!-- our scrolling box -->
<div class="parent"><!-- containing block -->
<div class="elem">elemen before</div>
<div class="sticky">I am sticky</div>
<div class="non-sticky">I am the relative position</div>
</div>
</div>
Now we have both behavior from top and bottom and the logic can be resumed as follow:
on_scroll_event() {
if( top_sticky!=auto && distance_top_sticky_top_scrolling_box <20px && distance_bottom_sticky_bottom_containing_block >0) {
position <- fixed
} else if(bottom_sticky!=auto && distance_bottom_sticky_bottom_scrolling_box <20px && distance_top_sticky_top_containing_block >0) {
position <- fixed
} else (same for left) {
position <- fixed
} else (same for right) {
position <- fixed
} else {
position <- relative
}
}
The specs are difficult to understand so here is my attempt to explain them based on MDN. Some definitions first:
sticky element – an element with position: sticky
containing block – the parent of sticky element
flow root – lets just say that it means viewport
A sticky element having position: sticky; top: 100px; is positioned as follows:
It is positioned according to the normal flow
And its top edge will maintain a distance of at least 100px from the top edge of the flow root
And its bottom edge cannot go below the bottom edge of the containing block
The following example shows how these rules operate:
body { font: medium sans-serif; text-align: center; }
body::after { content: ""; position: fixed; top: 100px; left: 0; right: 0; border: 1px solid #F00; }
header, footer { height: 75vh; background-color: #EEE; }
.containing-block { border-bottom: 2px solid #FA0; background: #DEF; }
.containing-block::after { content: ""; display: block; height: 100vh; }
.before-sticky { border-bottom: 2px solid #080; padding-top: 50px; }
.after-sticky { border-top: 2px solid #080; padding-bottom: 50px; }
.sticky { position: sticky; top: 100px; padding-top: 20px; padding-bottom: 20px; background-color: #CCC; }
<header>header</header>
<div class="containing-block">
<div class="before-sticky">content before sticky</div>
<div class="sticky">top sticky</div>
<div class="after-sticky">content after sticky</div>
</div>
<footer>footer</footer>
Likewise, a sticky element having position: sticky; bottom: 100px; is positioned as follows:
It is positioned according to the normal flow
And its bottom edge will maintain a distance of at least 100px from the bottom edge of the flow root
And its top edge cannot go above the top edge of the containing block
body { font: medium sans-serif; text-align: center; }
body::after { content: ""; position: fixed; bottom: 100px; left: 0; right: 0; border: 1px solid #F00; }
header, footer { height: 75vh; background-color: #EEE; }
.containing-block { border-top: 2px solid #FA0; background: #DEF; }
.containing-block::before { content: ""; display: block; height: 100vh; }
.before-sticky { border-bottom: 2px solid #080; padding-top: 50px; }
.after-sticky { border-top: 2px solid #080; padding-bottom: 50px; }
.sticky { position: sticky; bottom: 100px; padding-top: 20px; padding-bottom: 20px; background-color: #CCC; }
<header>header</header>
<div class="containing-block">
<div class="before-sticky">content before sticky</div>
<div class="sticky">bottom sticky</div>
<div class="after-sticky">content after sticky</div>
</div>
<footer>footer</footer>
I hope this is simple enough explanation.
MDN's definition of sticky position:
A stickily positioned element is an element whose computed position value is sticky. It's treated as relatively positioned until its containing block crosses a specified threshold (such as setting top to value other than auto) within its flow root (or the container it scrolls within), at which point it is treated as "stuck" until meeting the opposite edge of its containing block.
This definition is technically wrong. There happens to be an alternative definition on MDN as well, which you've linked in your question:
Sticky positioning can be thought of as a hybrid of relative and fixed positioning when it nearest scrolling ancestor is viewport. A stickily positioned element is treated as relatively positioned until it crosses a specified threshold, at which point it is treated as fixed until it reaches the boundary of its parent.
This statement is also technically incorrect, if by fixed in the last sentence MDN means fixed position(which should be case as they mentioned fixed positioning in the first sentence.). This one is very easy to prove wrong. A fixed positioned element doesn't occupy space. If sticky element is switched between relative and fixed positions, then it would fluctuate page's height which should be visible as a change in the scrollbar's height. Most likely, MDN is using fixed not in css positioning terminology.
Now, it can also be proved wrong that a sticky element is treated as relatively positioned. When you think the condition is met for the sticky element to behave as relative, go into inspect element and apply any css inset property. If it was truly a relatively positioned element then it should move without affecting the layout.
The authoritative html reference w3.org doesn't define or explain sticky position like MDN. w3.org's definition considers sticky similar to relative; not same as relative and mentions no relation with fixed position:
Sticky positioning is similar to relative positioning except the offsets are automatically calculated in reference to the nearest scrollport. For a sticky positioned box, the inset properties represent insets from the respective edges of the nearest scrollport, defining the sticky view rectangle used to constrain the box’s position.
The term sticky view rectangle(SVR) is key here. It is an imaginary rectangle in the scrollport(always visible). The sticky element must be physically positioned inside this imaginary rectangle. The sticky element can scroll as long as it stays withing the SVR. When the scroll container is scrolled the sticky element can move within that imaginary rectangle to stay visible.
For example top: 10px on a sticky element would cause the top-edge of the SVR to be at 10px from the top edge of it's scroll container. The sticky element, since has to be within SVR, will be pushed 10px down. On the other hand, bottom: 10px would cause the SVR's bottom-edge to be 10px away from scrollport's bottom. But, in this case the sticky element would not move to the bottom; rather will stay at it's normal position, because it is still within the SVR. This same explanation can be applied in regards with left and right inset properties.
In easy language top: 10px on a sticky element means the minimum physical distance between itself and it's scrollport's top edge is 10px, so if there is some content before the sticky element pushing it down, then it can be, but when we scroll, it will stick at 10px and won't scroll further. Similarly, bottom: 10px means the minimum distance from the bottom is 10px, that is it can sit at the top(distance > 10px).
In the last example of the linked answer, there is an additional wrapper to the sticky element. w3.org explains that scenario as well:
then the box must be visually shifted (as for relative positioning) to be inward of that sticky view rectangle edge, insofar as it can while its position box remains contained within its containing block. The position box is its margin box, except that for any side for which the distance between its margin edge and the corresponding edge of its containing block is less than its corresponding margin, that distance is used in place of that margin.
This explains why would the sticky element go out of SVR, so as to stay within it's parent element(containing block). Although I don't fully grasp the last part, where it says:
except that for any side for which the distance between its margin edge and the corresponding edge of its containing block is less than its corresponding margin, that distance is used in place of that margin.
I've opened this up as a separate question

CSS: Float div left next to table of arbitrary width?

I want to have a table (with an arbitrary number of columns) floated left, and some text floated left next to it if there is space, or down below it if there is not.
<div class="table">
<table>... table with arbitrary number of columns</table>
</div>
<div class="content">
Headings and paragraph text here (in a separate column, not flowing around the table)
</div>
I'd like the layout to be as follows:
I've started by just applying { float: left } to both divs, but it's not working - the second div is always below the first. Why? I thought float: left should wrap text.
JSFiddle here: http://jsfiddle.net/R9axt/1/
Remove float:left from the .visualisation-moreinfo class as it will stretch it to the left below the table and there is no need to set display:table to a table
.visualisation-moreinfo {
border: 1px solid red;
overflow:hidden;
/* float:left */ Removed */
}
Demo
Please try this FIDDLE. there is slight changes in your CSS. May solve your problem.
.visualisation-table {
border: 1px solid blue;
float: left;
width: 48%;
}
.visualisation-moreinfo {
border: 1px solid red;
width:48%;
float: left;
}

Why does the margin of a <p> effect the positioning of the containing div?

I've just come across a CSS issue that I've resolved, but I'd like to know why it happened in the first place or if it is an example of some common CSS behaviour or 'gotcha' I should know about.
Basically, if I did not set the margin of a <p> tag to 0px, I needed to compensate by adding a negative top margin to the containing div (or else there was a 20px space at the top of the div). I found it odd that the margin of the <p> seemed to extend beyond its container.
http://jsfiddle.net/rwone/4znhV/
HTML
<div class="container">
<div class="tab"></div>
<div class="bobble"></div>
<div class="bg">
<p>here is a paragraph la la la la la ...</p>
</div>
</div>
CSS
.container {
margin-top:50px;
}
.tab {
width:39px;
height:12px;
background: #ffe4c0;
border-radius: 3px 3px 0 0;
margin-left:14px
}
.bobble {
background:#fffc68;
height:22px;
width:22px;
float:right;
border-radius:12px;
border: 1px solid #f4f1e4;
margin-top:-8px;
margin-right:-4px;
}
.bg {
background: #F5F3EA;
min-height: 93px;
border-radius: 3px;
width: 100%;
/* margin-top: -20px; this is required if "margin:0px" is not set on <p> */
}
p {
color: #909090;
padding: 20px;
font-size: 20px;
margin: 0px; /* why is this required? */
}
This is due to what is called collapsing margins. According to the Box Model Spec...
Two margins are adjoining if and only if:
both belong to in-flow block-level boxes that participate in the same block formatting context
no line boxes, no clearance, no padding and no border separate them (Note that certain zero-height line boxes (see 9.4.2) are ignored for
this purpose.)
both belong to vertically-adjacent box edges, i.e. form one of the following pairs:
top margin of a box and top margin of its first in-flow child
bottom margin of box and top margin of its next in-flow following sibling
bottom margin of a last in-flow child and bottom margin of its parent if the parent has 'auto' computed height
top and bottom margins of a box that does not establish a new block formatting context and that has zero computed 'min-height', zero
or 'auto' computed 'height', and no in-flow children
If i understood well you want paragraph to expand the container right? This can be done by adding
position:absolute;
to the parent div of and:
position:relative;
to paragraph.
http://jsfiddle.net/7jG75/
Hope i helped.
css inheritance
margin for paragraph was not set so it was inherited from parent container
http://www.webdesignfromscratch.com/html-css/css-inheritance-cascade/
Like this
working fiddle
css
.container {
margin-top:50px;
}
.tab {
width:39px;
height:12px;
background: #ffe4c0;
border-radius: 3px 3px 0 0;
margin-left:14px
}
.bobble {
background:#fffc68;
height:22px;
width:22px;
float:right;
border-radius:12px;
border: 1px solid #f4f1e4;
margin-top:-8px;
margin-right:-4px;
}
.bg {
background: #F5F3EA;
border-radius: 3px;
width: 100%;
position:relative;
/* margin-top: -20px; this is required if "margin:0px" is not set on <p> */
}
p {
color: #909090;
padding: 20px;
font-size: 20px;
margin: 0px; /* why is this required? */
}
Because the browser has default style! if you don't reset the default css, they will act differently! for example p will have 20px margin-top and margin-bottom in chrome while 15px margin-top margin-bottom in ie!
usually if you want want different version and platform browser looks the same, you may have a reset css to remove all the different acts in the browser!
if you want compatible with IE8 and IE8-bellow, you may want this css http://meyerweb.com/eric/tools/css/reset/,other wise you just need a normalize css to make a small hack!
http://necolas.github.io/normalize.css/

Overflow is shown mid css3 transition, how can I hide the overflow?

I have the following structure:
<div class="service lorange">
<div class="img"></div>
<div class="title two-lines"><span>P-Accelerator for Start-Ups</span></div>
</div>
And the following CSS:
.service .img {
transition: opacity 300ms;
}
.service:hover .img {
opacity:0
}
.service has a rounded border (35px) and overflow: hidden;.
This causes the inner .title to have its borders cut-off with its parent's borders (this is the expected behavior).
However, during the transition when hovering, and only mid-transition (since it starts and till it ends, not before or after it starts and finishes), the .title borders do not cut off for some reason.
Any idea what's going on?
I've tried making a fiddle, but it doesn't reproduce the issue. What property can be causing this?
Edit: The fiddle in its shell does not reproduce the problem, but looking at the shell alone as a page does (I took the source of the iframe the fiddle uses)
My solution: (But I am looking for a better one.)
#services-grid .service .title {
position: relative;
z-index: 10;
top: 130px;
font-size: 13pt;
text-align: center;
height: 54px; /* IE fix */
/* Add radius to bottom of .title */
border-bottom-left-radius: 8px 15px;
border-bottom-right-radius: 8px 15px;
}
JSFiddle: http://jsfiddle.net/KC4TH/4/
The real reason this is happening is that browsers are only cropping the child element properly if it is not positioned (i.e. has position:static;). I've taken the liberty to alter your markup a bit and created a new jsFiddle which works as it should on Chrome, Firefox and IE10 (also working on IE9 but without the transition ofcourse).
Markup:
<div class="serviceContainer"> <!-- added a container -->
<div class="service lorange">
<!-- removed div.img -->
<div class="title two-lines"><span>P-Accelerator for Start-Ups</span></div>
</div>
</div>
CSS: (I've tried to include only the relevant CSS in the fiddle)
#services-grid .serviceContainer{ /* added a new container which the has the background image */
background:url(http://foto.hrsstatic.com/fotos/0/3/256/256/80/FFFFFF/http%3A%2F%2Ffoto-origin.hrsstatic.com%2Ffoto%2F3%2F9%2F4%2F0%2F394033%2F394033_p_465430.jpg/zoKRL9Oq7JFnhFhhAn%2FfTQ%3D%3D/128,128/6/Catalonia_Yucatan_Beach-Quintana_Roo-Pool-394033.jpg) center center no-repeat;
float:left;
border-radius:35px;
-moz-border-radius:35px;
-webkit-border-radius:35px;
-ms-border-radius:35px;
margin:0 15px;
overflow:hidden;
}
#services-grid .service.lorange .title span{ /* Give background color only to the span */
background-color:#efbd00;
}
#services-grid .service.lorange:hover{ /* fade color to container only when hovered */
background:#efbd00;
}
#services-grid .service .title {
position:static; /* This is what's doing the trick */
padding-top:130px; /* position the span using padding instead of position:absolute */
font-size:13pt;
text-align:center;
}
The "border-radius on the child" solution is only a cosmetic quickfix which can cause inconsistencies and it's also causing little bumps on each side because of the radius difference:

My div is breaking out of its container div

I have a containing div that is NOT restricting the width of its child divs. The divs are stretching all the way to the full width of the screen, when i have a set width on both the container and the child. Why is this happening. I do NOT have any positioning or floating going on.
Please view my HTML:
<ul class="tabs_commentArea">
<li class="">Starstream</li>
<li class="">Comments</li>
</ul>
<div id="paneWrap">
<div class="panes_comments">
<div class="comments">member pane 1</div>
<div class="comments">member pane 2</div>
<div class="comments">member pane 3</div>
</div>
My CSS, the relevant parts of it at least:
#MembersColumnContainer {
width: 590px;
float: left;
padding-right: 0px;
clear: none;
padding-bottom: 20px;
padding-left: 2px;
}
ul.tabs_commentArea {
list-style:none;
margin-top: 2px !important;
padding:0;
border-bottom:0px solid #666;
height:30px;
}
ul.tabs_commentArea li {
text-indent:0;
margin: !important;
list-style-image:none !important;
padding-top: 0;
padding-right: 0;
padding-bottom: 0;
padding-left: 0;
float: right;
}
#paneWrap {
border: solid 3px #000000;
}
.panes_comments div {
display: ;
padding: px px;
/*border:medium solid #000000;*/
height:150px;
width: 588px;
background-color: #FFFF99;
}
You could set max-width on either, or both, of the div elements to prevent their expansion:
#containerDiv {
min-width: 400px; /* prevents the div being squashed by an 'extreme' page-resize */
width: 50%; /* defines the normal width of the div */
max-width: 700px; /* prevents the div expanding beyond 700px */
}
It might also be that you're allowing the div's overflowed contents to be visible, as opposed to hidden (or auto). But without specific examples of your mark-up and css it's very difficult to guess.
Generally giving elements layout is pretty straight forward (always assuming you have a good understanding of floating, positioning and the box model), and in most cases you wouldn't have to use max- min-width to control elements on the page.
My two cents: If I was you, I'd start stripping out code (starting with the !important rule), and see when the problem is solved. De-constructing the code like that is a good way to find bugs.
Sorry I couldn't help, but I'm reluctant to give advice since the code you provided shows a lot of other stuff going on elsewhere that might be contributing to your problem (like having to use !important).
:D
I figured out the problem. The file that was calling in the css was conflicting with another external css file that had the same element with the same name in it. Thank you all for your help though.

Resources