I am trying to absolute position a text area that will stretch to cover it's parent. Unfortunately Chrome seems to ignore right property and Firefox ignores both right and bottom properties.
Here is the CSS I am using :
#container {
position: relative;
}
#my-text-area {
position: absolute;
top: 0px;
bottom: 0px;
left: 10px;
right: 10px;
}
Here is a JsFiddle example :enter link description here
Is there a textarea default property that i have to disable or are these just bugs? There are workarounds to achieve the full width and height of the parent by inheriting these properties from the parent but i am looking for a way to make the absolute positioning for the scenario you would in the future have custom right and bottom not only 0.
If you are placing an element with absolute position, you need the base element to have a position value other than the default value. In your case if you change the position value of the parent div to 'relative' you can fix the issue.
Absolutely positioned elements are positioned with respect to a containing block, which is the nearest postioned ancestor. If there is no positioned ancestor, the viewport will be the containing block. Elements with fixed positioning are fixed with respect to the viewport—the viewport is always their containing block.
An element with position: absolute; is positioned relative to the nearest positioned ancestor (instead of positioned relative to the viewport, like fixed). However; if an absolute positioned element has no positioned ancestors, it uses the document body, and moves along with page scrolling.
Wrap the textarea in an element and use same css on that element. Demo: https://jsfiddle.net/lotusgodkk/csub6b96/2/
HTML:
<div id="container">
<div id="my-text-area">
<textarea></textarea>
</div>
</div>
CSS:
body,
html,
#container {
width: 100%;
height: 100%;
}
body {
margin: 0px;
}
#container {
position: relative;
}
#my-text-area {
position: absolute;
top: 0px;
bottom: 0px;
left: 0px;
right: 0px;
}
textarea {
height: 100%;
width: 100%;
}
Reference: http://snook.ca/archives/html_and_css/absolute-position-textarea
If you're interested in why this is required, it's because the browsers affected are those which render textarea
as a replaced element. Rendering this control is delegated to the OS, and not handled by the browser itself, and it appears that certain CSS properties aren't respected when rendering a replaced element with position: absolute
. The relevant (and complicated) section of the CSS spec is https://www.w3.org/TR/CSS21/visudet.html#abs-replaced-width
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