Reputation: 282885
HTML
<div id="page"><div id="results"><div class="result">1+2</div>
<div class="result">3*4</div><div class="result">5/9</div>
<div class="result">y=mx+b</div></div><input id="eq" type="text" autofocus=""></div>
CSS
@import url(http://fonts.googleapis.com/css?family=Rokkitt);
body {
background-color: #444047;
margin: 0;
padding: 0;
}
#page {
width: 40%;
background-color: #ececec;
position: fixed;
top: 0;
bottom: 0;
left: 50%;
margin-left: -20%;
}
#results {
position: absolute;
top: 0;
right: 0;
left: 0;
bottom: 75px;
}
#eq {
width: 96%;
margin-left: -48%;
box-sizing: border-box;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
-webkit-border-radius: 20px;
-moz-border-radius: 20px;
-ms-border-radius: 20px;
-o-border-radius: 20px;
border-radius: 20px;
border-width: 2px;
border-color: #9A9A9A #EEEEEE #EEEEEE #9A9A9A;
border-style: solid;
font-family: 'Rokkitt', serif;
letter-spacing: 1px;
font-size: 24pt;
padding: 5px 10px;
position: absolute;
bottom: 10px;
left: 50%;
}
#eq:focus {
border-color: #4E9FF2 #84B2E0 #84B2E0 #4E9FF2;
-webkit-box-shadow: 0 0 10px #007eff;
-moz-box-shadow: 0 0 10px #007eff;
-ms-box-shadow: 0 0 10px #007eff;
-o-box-shadow: 0 0 10px #007eff;
box-shadow: 0 0 10px #007eff;
outline: none;
}
#results {
font-family: 'Rokkitt', serif;
font-size: 16pt;
vertical-align: bottom;
text-align: left;
box-sizing: border-box;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
padding: 5px;
display: table-cell;
overflow: auto;
}
.result {
padding: 2px;
}
.result + .result {
border-top: 1px dotted gray;
}
How can I align the .result
divs to the bottom of the #result
container?
Edit: The #results
div needs to gain a scrollbar if there are too many .result
s to fit. overflow:auto
seems to be incompatible with some of the solutions below.
Upvotes: 2
Views: 187
Reputation: 12974
Here's a version which doesn't break your overflow: auto
.
Here's a jsFiddle.
Basically what I'm doing is wrapping your markup in enough div
's so that I can make the wrapper div
's behave like a table, with the display: table;
, display: table-row;
and display: table-cell;
CSS properties.
Now that the wrapping markup behaves like a table, I can absolutely position a div
inside the "cell" in the top "row" and set it to stick to the bottom with a max-height
of 100%
and its overflow
set to auto
. This is the exact same technique I used in the original answer I posted here. But now the max-height
of 100%
will stay inside the top row of the table
, eliminating the issues which you pointed out with the solutions I posted earlier.
Here are the relevant CSS classes:
#page {
width: 40%;
background-color: #ececec;
position: fixed;
bottom: 0;
left: 50%;
margin-left: -20%;
display: table;
height: 100%;
}
#results, #input {
display: table-row;
}
#results > div {
display: table-cell;
height: 100%;
position:relative;
}
#results > div > div {
overflow: auto;
max-height: 100%;
width: 100%;
position: absolute;
bottom: 0px;
}
#input {
height: 75px;
}
#results {
font-family:'Rokkitt', serif;
font-size: 16pt;
vertical-align: bottom;
text-align: left;
box-sizing: border-box;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
overflow: auto;
height: 100%;
}
And here's the edited HTML:
<div id="page">
<div id="results">
<div>
<div>
<div class="result">1+2</div>
<div class="result">3*4</div>
<div class="result">5/9</div>
<div class="result">y=mx+b</div>
<div class="result">y=mx+b</div>
<div class="result">y=mx+b</div>
<div class="result">y=mx+b</div>
<div class="result">y=mx+b</div>
<div class="result">y=mx+b</div>
<div class="result">y=mx+b</div>
<div class="result">y=mx+b</div>
<div class="result">1+2</div>
</div>
</div>
</div>
<div id="input">
<input id="eq" type="text" autofocus="" />
</div>
</div>
Upvotes: 1
Reputation: 157334
Lets clean up your mess, wrap the inner container which is position: absolute;
in a position: relative;
container, I've made this from scratch, you can have a look
<div class="wrap">
<div class="inner_wrap">
<span>1+2</span>
<span>3*4</span>
<span>5/9</span>
<span>y=mx+b</span>
<span><input id="eq" type="text" autofocus="" /></span>
</div>
</div>
CSS (Excluding input
element style, but I've included that in the demo fiddle)
html, body {
background-color: #444047;
height: 100%;
}
.wrap {
width: 230px;
background: #ECECEC;
height: 100%;
margin: auto;
position: relative;
}
.wrap span {
display: block;
border-bottom: 1px dotted #515151;
padding: 5px;
font-size: 18px;
font-family: Arial;
}
div span:last-child {
border-bottom: 0;
}
.inner_wrap {
position: absolute;
bottom: 0;
}
Upvotes: 4
Reputation: 606
DEMO:http://jsfiddle.net/H2qBH/1/ do you want like this.....
#results {
position: absolute;
top: 275px;
right: 0;
left: 0;
bottom:0px;
}
Upvotes: 0