I have to fix this layout, which is a messy combination of flexbox, table layout and absolute positioning.
While it's working normal on Chrome, FF and Safari, the output screen on IE11 is strange.
In my code, I want the span to be at the bottom-right of each square, but on IE11, it appears on top-right instead.
Can anyone please help me to fix this problem? The constraint here is that the flexbox .container and the table system must be maintained. I want to fix only the span element. Thanks in advance!
.container {
display: flex;
width: 400px;
}
.inner {
width: 50%;
}
.table {
display: table;
width: 100%;
border: 1px solid;
}
.table:before {
content: '';
display: table-cell;
width: 0;
padding-bottom: 100%;
}
.cell {
display: table-cell;
vertical-align: bottom;
position: relative;
padding: 20px;
}
.cell span {
position: absolute;
bottom: 20px;
right: 20px;
}
<div class="container">
<div class="inner">
<div class="table">
<div class="cell">
Yeah?
<span>Yo!</span>
</div>
</div>
</div>
<div class="inner">
<div class="table">
<div class="cell">
Yeah?
<span>Yo!</span>
</div>
</div>
</div>
</div>
remove your .cell span block and
use below code instead of that.
i have checked its working in every browser.
.cell span {
float: right;
}
One thing you can do to fix it in IE11 is to wrap your cell contents into a block container and then add position: relative to it. Now you can adjust the position with right: 0px - see demo below:
.container {
display: flex;
width: 400px;
}
.inner {
width: 50%;
}
.table {
display: table;
width: 100%;
border: 1px solid;
}
.table:before {
content: '';
display: table-cell;
width: 0;
padding-bottom: 100%;
}
.cell {
display: table-cell;
vertical-align: bottom;
position: relative;
padding: 20px;
}
.cell span {
position: absolute;
/*bottom: 20px;
right: 20px;*/
right: 0px; /* ADDED */
}
.cell div { /* ADDED */
position: relative;
}
<div class="container">
<div class="inner">
<div class="table">
<div class="cell">
<div>Yeah?
<span>Yo!</span></div>
</div>
</div>
</div>
<div class="inner">
<div class="table">
<div class="cell">
<div>Yeah?
<span>Yo!</span></div>
</div>
</div>
</div>
</div>
Related
This codepen will make clear what I am trying to do:
HTML:
<div class="slider-container">
<div class="table">
<div class="row">
<div class="cell">
<img src="https://images.robertharding.com/preview/RM/RH/VERTICAL/983-675.jpg">
</div>
<div class="padding-cell"></div>
<div class="cell">
<img src="https://images.robertharding.com/preview/RM/RH/VERTICAL/983-675.jpg">
</div>
<div class="padding-cell"></div>
<div class="cell">
<img src="https://images.robertharding.com/preview/RM/RH/VERTICAL/983-675.jpg">
</div>
</div>
</div>
</div>
CSS:
.slider-container {
left: 4.5em;
right: 4.5em;
position: fixed;
top: 4.5em;
height: calc(100vh - 9em);
}
.slider-container .table {
display: table;
height: inherit;
width: 100%;
}
.slider-container .table .row {
display: table-row;
width: 100%;
height: inherit;
vertical-align: middle;
text-align: center;
}
.slider-container .table .row .padding-cell {
display: table-cell;
height: inherit;
width: 1.5em;
}
.slider-container .table .row .cell {
display: table-cell;
height: inherit;
vertical-align: middle;
}
.slider-container .table .row .cell img {
max-height: 100%;
max-width: 100%;
}
https://codepen.io/simonhrogers/pen/WJJVgL
When the aspect ratio of the image is particularly tall, or the screen particularly squashed, the gaps between each image will begin to stretch much wider than the width of the specified padding cell between them. How can I prevent this behaviour so that the images are always separated by just the width of the padding cell?
I still need the images to shrink if too close to the top/bottom or sides of the screen; as I have here, but with a fixed-width gap between them instead of that changing too.
Desired:
Undesired:
You can get the desired behavior by doing some minor changes in your code:
First set width:100% for your image.
Second set a fixed padding in your class padding-cell in unit px or rem
.slider-container {
left: 4.5em;
right: 4.5em;
position: fixed;
top: 4.5em;
height: calc(100vh - 9em);
}
.slider-container .table {
display: table;
height: inherit;
width: 100%;
}
.slider-container .table .row {
display: table-row;
width: 100%;
height: inherit;
vertical-align: middle;
text-align: center;
}
.slider-container .table .row .padding-cell {
display: table-cell;
height: inherit;
width: 20px;
}
.slider-container .table .row .cell {
display: table-cell;
height: inherit;
vertical-align: middle;
}
.slider-container .table .row .cell img {
max-height: 100%;
max-width: 100%;
width: 100%;
}
<div class="slider-container">
<div class="table">
<div class="row">
<div class="cell">
<img src="https://images.robertharding.com/preview/RM/RH/VERTICAL/983-675.jpg">
</div>
<div class="padding-cell"></div>
<div class="cell">
<img src="https://images.robertharding.com/preview/RM/RH/VERTICAL/983-675.jpg">
</div>
<div class="padding-cell"></div>
<div class="cell">
<img src="https://images.robertharding.com/preview/RM/RH/VERTICAL/983-675.jpg">
</div>
</div>
</div>
</div>
Although you can achieve the layout more easily with flexbox.
I want to create two divs, one under other without JS and with IE8 support.
Each has 100% width.
Each with relative or absolute positioning for nested layout.
Top div have height by content, not fixed (it is important) and bottom div on whole leftover space.
In my example bottom div is too short, how i can stretch it to bottom?
<html>
<head>
<style type="text/css"><!--
* {
padding: 1px;
margin: 0px;
border: solid 1px;
width: 100%;
}
#super {
position: absolute;
height: 100%;
}
#top {
position: relative;
}
#bottom {
position: relative;
top: 0px;
bottom: 0px;
}
--></style>
</head>
<body>
<div id="super">
<div id="top">top</div>
<div id="bottom">bottom</div>
</div>
</body>
</html>
You can use css table properties to create this layout.
HTML:
<div id="super">
<div id="top">
<div class="content">
top
</div>
</div>
<div id="bottom">
<div class="content">
bottom
</div>
</div>
</div>
Necessary CSS:
html,
body {
height: 100%;
}
#super {
height: 100%;
width: 100%;
display: table;
}
#super > div {
display: table-row;
}
#top {
background: green;
}
#bottom {
background: blue;
}
html,
body {
height: 100%;
padding: 0;
margin: 0;
}
#super {
height: 100%;
width: 100%;
display: table;
}
#top {
background: green;
overflow: hidden;
height: 1%;
}
.content {
padding: 10px;
}
#bottom {
background: blue;
}
#super > div {
display: table-row;
}
<div id="super">
<div id="top">
<div class="content">
top
</div>
</div>
<div id="bottom">
<div class="content">
bottom</div>
</div>
</div>
Output Image:
You can use display: table for wrapping container and table-row for top and bottom divs:
* {
padding: 1px;
margin: 0px;
border: solid 1px;
width: 100%;
}
#super {
display: table;
position: absolute;
height: 100vh;
}
#top {
display: table-row;
height: 1px;
position: relative;
background: orange;
}
#bottom {
display: table-row;
position: relative;
top: 0px;
bottom: 0px;
background: teal;
}
<div id="super">
<div id="top">top<br>top text</div>
<div id="bottom">bottom</div>
</div>
Use flex-box
.parent{
display: flex;
flex-direction: column;
min-height: 100vh
}
.child2{
flex: 1;
background: blue;
}
<div class="parent">
<div class="child1"> first child</div>
<div class="child2"> second child</div>
</div>
Demo here
Try this :
#bottom {
position: relative;
top: 0px;
bottom: 0px;
HEIGHT: 800px;
}
I have 2 divs inside a parent:
<div class="parent">
<div class="foo1"></div>
<div class="foo2"></div>
</div>
foo1 will have a dynamic height, so I can't use the style below:
height: calc(100% - foo1Height);
Now, what I want to do is make sure that the lower child foo2 never expands outside of the parent div, and to show the scrollbar if it gets too big. I would prefer CSS only solutions.
You can either use flexbox. no markup changes.
.parent {
display: flex;
flex-direction: column;
height: 100px;
}
.foo2 {
flex: 1; /*expand to fit*/
background: silver;
overflow: auto; /*scroll as needed*/
}
<div class="parent">
<div class="foo1">1</div>
<div class="foo2">2<br>2<br>2<br>2<br>2<br>2<br>2<br>2</div>
</div>
Or use CSS table, additional markup is required.
.parent {
display: table;
width: 100%;
height: 100px;
}
.foo1, .foo2 {
display: table-row;
}
.cell {
display: table-cell;
position: relative;
}
.foo2 {
height: 100%; /*expand to fit*/
background: silver;
}
.scroll {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
overflow: auto; /*scroll as needed*/
}
<div class="parent">
<div class="foo1">
<div class="cell">1</div>
</div>
<div class="foo2">
<div class="cell">
<div class="scroll">2<br>2<br>2<br>2<br>2<br>2<br>2<br>2</div>
</div>
</div>
</div>
.table {
display: table;
width: 10rem;
background-color: yellow;
}
.table-row {
display: table-row;
height: 100%;
width: 100%;
}
.table-cell {
display: table-cell;
height: 100%;
width: 50%;
position: relative;
}
.cell-top-div {
height: 1.5rem;
border-left: 1rem solid red;
}
.cell-bottom-div {
position: absolute;
top: 1.5rem;
bottom: 0;
width: 100%;
border-left: 1rem solid black;
}
.cell-right-div {
background-color: green;
height: 5rem;
}
<div class="table">
<div class="table-row">
<div class="table-cell">
<div class="cell-top-div"> </div>
<div class="cell-bottom-div"> </div>
</div>
<div class="table-cell">
<div class="cell-right-div"> </div>
</div>
</div>
</div>
Chrome & Firefox:
Internet Explorer:
Height of cell-top-div is fixed whereas height of cell-bottom-div is variable and depends on right cell. I want to add a left border to cell-bottom-div but in IE browser height is calculated as 0.
Simplest solution I've found is to remove position:relative from .table-cell and add it to .table. I think by doing this the table is determining the height vs. the table-cell which is only being given height by its contents.
.table {
display: table;
width: 10rem;
background-color: yellow;
position: relative;
}
.table-row {
display: table-row;
height: 100%;
width: 100%;
}
.table-cell {
display: table-cell;
height: 100%;
width: 50%;
}
.cell-top-div {
height: 1.5rem;
border-left: 1rem solid red;
}
.cell-bottom-div {
position: absolute;
top: 1.5rem;
bottom: 0;
width: 100%;
border-left: 1rem solid black;
}
.cell-right-div {
background-color: green;
height: 5rem;
}
<div class="table">
<div class="table-row">
<div class="table-cell">
<div class="cell-top-div"> </div>
<div class="cell-bottom-div"> </div>
</div>
<div class="table-cell">
<div class="cell-right-div"> </div>
</div>
</div>
</div>
An absolute positioned div in IE10 is not filling its parents height (works OK in latest Chrome and Firefox).
In the code below, the "percent-height" class is where the issue lies. It fills the width OK, but not the height.
If I set a pixel height (in cell 3), this is how I know the percentage "height" is the issue, not the width. I need a percentage height as this will be responsive.
Codepen for visuals: http://codepen.io/anon/pen/eNexOg
HTML:
<div class="table">
<div class="cell">
<img src="http://placehold.it/200x200" alt="" />
</div>
<div class="cell">
<div class="percent-height"></div>
</div>
<div class="cell">
<div class="px-height"></div>
</div>
<div class="cell">
</div>
</div>
CSS:
.table {
display: table;
width: 100%;
border-spacing: 5px;
}
.cell {
display: table-cell;
width: 25%;
position: relative;
background-color: grey;
}
.percent-height {
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
background-color: green;
}
.px-height {
position: absolute;
width: 100%;
height: 200px;
top: 0;
left: 0;
background-color: red;
}
For this Issue You can use the "display:flex" CSS where it will distribute the height dynamically.
.table{
display: -ms-flex;
display: -webkit-flex;
display: flex;
}
.cell {
-ms-flex: 1;
-webkit-flex: 1;
flex: 1;
}