How to make div's percentage width relative to parent div and not viewport
Specifying a non-static position, e.g., position: absolute/relative
on a node means that it will be used as the reference for absolutely positioned elements within it http://jsfiddle.net/E5eEk/1/
See https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Positioning#Positioning_contexts
We can change the positioning context — which element the absolutely positioned element is positioned relative to. This is done by setting positioning on one of the element's ancestors.
#outer { min-width: 2000px; min-height: 1000px; background: #3e3e3e; position:relative}
#inner { left: 1%; top: 45px; width: 50%; height: auto; position: absolute; z-index: 1;}
#inner-inner { background: #efffef; position: absolute; height: 400px; right: 0px; left: 0px;}
<div id="outer"> <div id="inner"> <div id="inner-inner"></div> </div></div>
How to make fixed div width of parent div, which itself is defined in percentage?
Use postion: absolute
instead of position: fixed
.
Absolute positionning applies to the first relative parent.
Fixed applies to the window.
You can then place the div relatively to it's parent in the viewport with top
, left
, right
, and bottom
attributes.
Fiddle: https://jsfiddle.net/k0vndvzj/3/
Is there a way to make a child DIV's width wider than the parent DIV using CSS?
Use absolute positioning
.child-div {
position:absolute;
left:0;
right:0;
}
CSS constrain absolute-position div to parent size
1) use box-sizing: border-box
in order to avoid calculations about borders
2) set position: relative
on .content
.container { height: 3em; width: 50%; border: 1px solid green;}
.content { box-sizing: border-box; position: relative; height: 1em; width: 100%; border: 3px dashed blue;}
.content .mask { position: absolute; z-index: 99; right: -3px; bottom: -3px; left: -3px; top: -3px; border: 2px dotted red;}
<div class="container"> <div class="content"><!-- should be however big the container is--> <div class = "mask"></div> <!-- should be in front of the entire content content --> </div></div>
Set width of a Position: fixed div relative to parent div
I´m not sure as to what the second problem is (based on your edit), but if you apply width:inherit
to all inner divs, it works: http://jsfiddle.net/4bGqF/9/
You might want to look into a javascript solution for browsers that you need to support and that don´t support width:inherit
Related Topics
How to Change the Default Index Page in Apache
Left-Right Movement.. CSS Only Very Generic
Html5 Video // Completely Hide Controls
Why Doesn't "Display: Block" & "Width: Auto" Stretch a Button to Fill the Container
How to Display an .HTML Document , or .HTML Fragment at CSS Content
Rendering HTML Elements to <Canvas>
What Values for Checked and Selected Are False
HTML <Base> Tag and Local Folder Path with Internet Explorer
CSS - How to Have Children in Different Parents the Same Height
How to Show Disable HTML Select Option in by Default
HTML + CSS: Ordered List Without the Period
Unskewing the Ends of an Assortment Multiple Skewed Images
How Does One Use the Onerror Attribute of an Img Element
How to Choose Between Get and Post Methods in HTML Forms
Center Image Element in Parent Div
How to Embed Latex in a Webpage
How to Write Fraction Value Using HTML
Form and File Upload with HTMLservice and App Script Not Working