I'm trying to create an HTML/CSS-based week calendar using CSS display:table-cell styling on the divs corresponding to each day. When I specify a percent width for the day divs that is greater than 17%, the divs fills the whole screen as expected (since 7*17% > 100%).
jsfiddle here: http://jsfiddle.net/huDxZ/1/
However, when I specify a percent width that is 16% or less, the divs behave entirely differently, taking up only part of the page width.
jsfiddle here: http://jsfiddle.net/DLjnH/
I would like my day divs to each have widths of about 14% so they roughly fill the width of the page and have equal sizes. Unfortunately, a width of 14% looks even worse.
jsfiddle here:http://jsfiddle.net/YB5bY/
What is causing this unexpected behavior? Is there any way around it? I need to explicitly specify widths because eventually I would like the days of the calendar to expand on mouseover.
Please, no solutions involving floats.
Thanks!
Note: Using a percentage as the size unit for a width means how wide will this element be compared to its parent element, which in this case is the <body> element.
The <percentage> CSS data type represents a percentage value. It is often used to define a size as relative to an element's parent object. Numerous properties can use percentages, such as width , height , margin , padding , and font-size . Note: Only calculated values can be inherited.
The width property in CSS specifies the width of the element's content area. This “content” area is the portion inside the padding, border, and margin of an element (the box model). .wrap { width: 80%; } In the example above, elements that have a class name of . wrap will be 80% as wide as their parent element.
CSS rules percentage values is always relative to the value of the same property of the parent.
Try adding an explicit width to the container:
#calendar { display: table; height:900px; width: 100%; }
The you can use 14%
for the ".day" elements:
DEMO
I cannot tell you the reason but if you force the container div
to have 100% width the behaviors of the two cases are identical.
#calendar { display: table; height:900px; width: 100%; }
Updated version: http://jsfiddle.net/DLjnH/1/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With