it looks that textarea don't respect the css max-width when is setted to 100% and it is ok when setted to fixed pixels
<textarea cols="80">text here</textarea>
and
max-width: 100%;
or
max-width: 100px;
See the snippet code for max-width: 100%:
.table {
width: 100%;
display:table;
}
.table-cell {
display: table-cell;
padding: 10px;
width: 300px;
background: #DAC082;
}
textarea {
max-width: 100%;
}
<div class="table">
<div class="table-cell">
<p>textarea cell</p>
<textarea cols="80">TEXT</textarea>
</div>
</div>
and see the snippet code for max-width: 100px:
.table {
width: 100%;
display:table;
}
.table-cell {
display: table-cell;
padding: 10px;
width: 300px;
background: #DAC082;
}
textarea {
max-width: 100px;
}
<div class="table">
<div class="table-cell">
<p>textarea cell</p>
<textarea cols="80">TEXT</textarea>
</div>
</div>
Note that in the first example the textarea is overriding the css max-width 100%, I suppose it is wrong and It should be into 300px of table-cell width.
In the second example textarea stay into 100px: It works.
N.B. my browser is Firefox ESR 60.3. Is a firefox bug?
Have you tried
textarea {
width: 100%;
}
this worked for me and matched the width of whatever I set in .table-cell
Table cells have a tendency to treat their width properties as hints rather than being set in stone.
One solution is to put an extra div in the table cell around the content, and set the width of that one. Then the textarea will honour it.
.table {
width: 100%;
}
.table-cell {
display: table-cell;
padding: 10px;
background: #DAC082;
}
.table-cell>div {
width: 300px;
}
textarea {
max-width: 100%;
}
<div class="table">
<div class="table-cell">
<div>
<p>textarea cell</p>
<textarea cols="80">TEXT</textarea>
</div>
</div>
</div>
Update: after it has become more clear what you want, a new solution is as follows: don't assign width properties to the table, but assign them to the content instead; then the table will mold itself to its contents rather than vice versa.
.table {
display: table;
}
.table-cell {
display: table-cell;
padding: 10px;
background: #DAC082;
}
textarea {
max-width: calc(100vw - 16px - 20px); /* = viewport - body margin - cell padding */
}
<div class="table">
<div class="table-cell">
<p>textarea cell</p>
<textarea cols="80">TEXT</textarea>
</div>
</div>
The max-width of the textarea is the width of the viewport, minus the margin of the body and the padding in the cell. You can adjust this to your needs of course!
Related
I would like to expand the child-content to the full width. I've tried everything and I don't know what can run.
I've only made it run with min-width: n px; but I wouldn't like to define a specific width in pixels because the design won't be adaptive in smaller screens.
https://jsfiddle.net/tiranium/e8w22j39/
HTML
<div class="ficha_container">
<div class="ficha_row">
<div class="ficha_cell">
<h1>Title</h1>
<p>Content.</p>
</div>
</div>
</div>
CSS
.ficha_container {
display: table;
background-color: green;
box-sizing: border-box;
overflow: hidden;
display: block;
}
.ficha_row {
display: table-row;
}
.ficha_cell {
display: table-cell;
}
.ficha_cell p {
background: pink;
}
Assuming you want a display:table solution, you can't also add display: block to the same element.
My guess why you did that, were to make it full width.
To make a table full width you simply set it to 100%, so to make your existing markup work properly, remove display: block from .ficha_container and add width: 100%;
.ficha_container{
display:table;
background-color: green;
box-sizing: border-box;
width: 100%;
}
.ficha_row{
display:table-row;
}
.ficha_cell{
display: table-cell;
}
.ficha_cell p{
background: pink;
}
<div class="ficha_container">
<div class="ficha_row">
<div class="ficha_cell">
<h1>Title</h1>
<p>Content.</p>
</div>
</div>
</div>
Update: This is the closest to a solution so far: http://jsfiddle.net/bfcr62yd/11/
I am having trouble solving the following problem. In short, I need one element to fill the remaining width, where all other elements that are all stacked horizontally have fixed widths.
The UI has 5 wrapper elements that need to be stacked horizontally with a fixed min-width. The 2 elements on the left and the 2 elements on the right have fixed widths. The center wrapper element width needs to dynamically fill the remaining width. The center element has a child element that has a very large fixed width. If the responsive parent width is smaller than the child fixed width, I would like the child to overflow-x: scroll (hide the remaining width and view it via scroll).
<div>
<div class="box dates"></div>
<div class="box dates_presets"></div>
<div class="box groupings"></div> <!-- to fill remaining width -->
<div class="box columns"></div>
<div class="box columns_video"></div>
</div>
My attempts so far:
http://jsfiddle.net/bwgrwgnz/1/
http://jsfiddle.net/hycd4non/13/
I have found this simple example that works with only 2 elements: http://jsfiddle.net/SpSjL/
Try using display: table | table-row | table-cell:
.table { display: table; width: 100%; } /* set the width to your maximum width value */
.tr { display: table-row; }
.tr div { display: table-cell; }
you also need to remove all of the floats from your 'table-cell' elements
JSFiddle Demo
And, one more no-flexbox solution. Problem was to force scrolling. One more or less dirty hack made it!
http://jsfiddle.net/d4n2fnpy/1/
#table {
display:table;
width:100%;
table-layout:fixed;
}
.box {
border: 2px dashed #00f;
min-height: 100px;
padding-right: 10px;
display:table-cell;
word-wrap:break-word;
}
.dates {
width: 200px;
}
.dates_presets {
width:200px;
}
.groupings {
overflow-x: scroll;
word-wrap:initial!important;
display:block!important;
width:auto;
}
.columns {
width:200px;
}
.columns_video {
width: 200px;
}
P.S. Set overflow-x: auto; to remove ugly scroler when there is no need for it...
Are you looking for something like this? http://jsfiddle.net/DIRTY_SMITH/bfcr62yd/14/
I restructured it but I think this is what you wanted
HTML
<div id="container">
<div class="box-1"></div>
<div class="box-2"></div>
<div class="box-3">
<div class="inside-div">
blah blah blah blah blah blah blah blah blah blah blah blah
</div>
</div>
<div class="box-4"></div>
<div class="box-5"></div>
</div>
CSS
#container{width: 100%;}
.box-1, .box-2, .box-4, .box-5{width: 200px; height: 100px; background-color: blue; float: left;}
.box-3{width: calc(100% - 800px); height: 100px; overflow-x: scroll; overflow-y: hidden;background-color: red; float: left;}
.inside-div{height: 50px; width: 400px;}
.mini-box {
padding: 5px;
margin: 5px;
border: 1px solid red;
width: 20px;
}
I added a width using Calc(). It's pretty straight forward. I have it here: http://jsfiddle.net/bwgrwgnz/3/
width: calc(100% - 770px);
But to be honest, flexbox is probably the way you want to go if you can deal with the lack of support in older browsers.
Ps. calc() isn't supported everywhere either.
Edit: There is a table example above as well which could work well.
My solution using tables: http://jsfiddle.net/bwgrwgnz/41/
.box {
border: 2px dashed #00f;
height: 100px;
width: 50px;
}
.dynamic-box {
width:auto !important;
}
.dynamic-box-fixed-inner {
display:block !important;
overflow-x:scroll;
}
.inner-item {
position:inline-block;
padding:5px;
}
.table { display: table; width: 100%; table-layout:fixed; }
.tr { display: table-row; }
.tr div { display: table-cell; }
<div class="table">
<div class="tr">
<div class="box">a</div>
<div class="box">b</div>
<!-- this element should fill the remaining width -->
<div class="box dynamic-box">
<div class="dynamic-box-fixed-inner">
<div class="inner-item">item</div>
<div class="inner-item">item</div>
...
</div>
</div>
<div class="box">d</div>
</div>
</div>
Here is a jsfiddle where you can see cells expanding outside of their container(or extending the size of a table when this happens with tables) because:
of a long word even if "word-wrap: break-word" is set
of a large div even if "overflow: hidden" is set
http://jsfiddle.net/NUHTk/166/
<div class="container">
<div class="leftBlock">
Too-much-text-ъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъъ
</div>
<div class="rightBlock">
Right block content
</div>
</div>
<div class="container">
<div class="leftBlock">
<div style="width: 1200px; height: 200px;">
Huge element
</div>
</div>
<div class="rightBlock">
Right block content
</div>
</div>
CSS
.container
{
width: 500px;
padding: 10px;
margin: 20px auto;
background: rgb(255,240,240);
}
.leftBlock, .rightBlock
{
display: table-cell;
vertical-align: top;
}
.leftBlock
{
width: 100%;
//max-width: 0;
word-wrap: break-word;
overflow: hidden;
background: rgb(240,255,255);
}
.rightBlock
{
width: 200px;
max-width: 200px;
min-width: 200px;
background: rgb(200,200,200);
}
This issue can be fixed by adding a "max-width: 0" to .leftBlock, result of which can be seen here:
http://jsfiddle.net/CyberAP/NUHTk/103/
This same problem and fix can occur when dealing with tables.
This feels like a hack. My questions are:
why does max-width: 0 solve the problem.
Why and how does it change the behavior of the cell sizing.
I guess, why isn't this the default behavior?
You can add display:table; and table-layout:fixed to container class. Hope this is solve your issue.
I have a header with a div which have display:table; max-width: 800px. It should act as a frame to restrict the contents width. Inside the frame are images which auto-scale and are nested inside div's with display:table-cell.
Everything is working on Chrome and Mobile Safari, but Firefox and IE are not restricting the frame width.
jsFiddle
Can anybody help me, please ;(
Set the table to have table-layout: fixed and a width of 100%.
.frame {
display: table;
max-width: 800px;
width: 100%;
height: 300px;
margin: 0 auto;
padding: 10px;
background: #ccc;
table-layout: fixed
}
.item {
display: table-cell;
vertical-align: middle;
padding: 0 5px;
}
img {
max-width: 100%;
height: auto;
}
<div class="frame">
<div class="item">
<img src="http://lorempixel.com/250/250" />
</div>
<div class="item">
<img src="http://lorempixel.com/250/200" />
</div>
<div class="item">
<img src="http://lorempixel.com/250/100" />
</div>
</div>
Check this Fiddle
Replace max-width to width from image css, the reason behind this is max-width does not apply to inline elements, so you will get inconsistent behavior across browsers.
img {
width: 100%;
height: auto;
}
I have trouble with textarea inside a div whose display style is table-cell. You can see the problem here. The last div has a textarea and somehow it causes an empty area below itself and above other divs.
BTW I am trying to have a structure like this. According to selection, cells will be displayed in a fixed height area with equal widths having a total 100%. Problem occurs when there is a textarea inside any div. If there is an existing component that behaves like this any recommendation will be appreciated.
HTML
<div class="panes">
<div id="pane1" class="pane">
<div class="pane-content"></div>
</div>
<div id="pane2" class="pane">
<div class="pane-content"></div>
</div>
<div id="pane3" class="pane">
<div class="pane-content">
<textarea></textarea>
</div>
</div>
</div>
CSS
.panes {
display: table;
table-layout: fixed;
width:100%;
height:100px;
}
.pane {
display: table-cell;
border: solid 1px;
}
.pane-content {
display: block;
overflow: auto;
height: 100px;
border: solid 1px red;
}
.pane-content textarea {
display: block; /*This fix the issue in IE but other browsers still broken*/
width: 100%;
height: 100px;
}
make it like this:
.pane {
display: table-cell;
border: solid 1px;
vertical-align: top;
}