I have a block like this:
<div class="container">
<div class="someStuff">Some stuff of unknown height</div>
<div class="myDGrid" data-dojo-attach-point="dgrid"></div>
</div>
The DGrid is started like this:
new (declare([OnDemandGrid, DijitRegistry]))({
store: ...,
columns: ...
}, this.dgrid);
Requirements:
The container block has some height.
The someStuff block has some height that is dynamically set.
The myDGrid block contains a Dojo DGrid. It should use the remainder of the space in container. For example:
If container is 400px and someStuff is 200px then myDGrid should be 200px.
If container is 300px and someStuff is someStuff is 10px then myDGrid should be 290px.
The dgrid should have scrollbars if all rows cannot be shown.
What is the best way to do this?
One solution is to change the html to this:
<div class="container">
<div class="someStuff">Some stuff of unknown height</div>
<div class="containsDGrid">
<div class="myDGrid" data-dojo-attach-point="dgrid"></div>
</div>
</div>
And then use CSS like this:
.container {
display: table;
}
.someStuff {
display: table-row;
}
.containsDGrid {
display: table-row;
height: 100%;
}
.dgrid {
width: 100%;
height: 100%;
}
.dgrid .dgrid-scroller {
overflow-y: auto;
overflow-x: hidden;
}
Related
I have a flexbox container with two flex items in it. One is an image and the other a paragraph. I've been trying to resize the image proportionally by giving width:some-percentage and height:auto but it's not working. Please help me solve this.
.item{
display:flex;
}
img{
width: 25%; /* not working */
height: auto;
}
<div class="item">
<img
src=
"https://png.pngtree.com/element_origin_min_pic/16/10/16/105802ebe43fe0f.jpg"/>
<p>some paragraph</p>
</div>
JSFiddle link - https://jsfiddle.net/dizzyramen/xfot3Lwv/2/
A default setting on a flex container is align-items: flex-start.
In a row-direction container, this makes flex items, not having a defined height (e.g. height: auto), extend the full height of the container (full explanation).
In this particular case, however, the image is stretching to its fullest, and expanding the size of the container along with it.
The solution is to set a height limit on the container or override the default with align-items: flex-start on the container or align-self: flex-start on the item.
jsFiddle demo
.item {
display: flex;
}
img {
width: 25%;
align-self: start; /* new */
}
<div class="item">
<img src="https://png.pngtree.com/element_origin_min_pic/16/10/16/105802ebe43fe0f.jpg" />
<p>some paragraph</p>
</div>
here is another option:
wrap your img in a div <div class="image-wrapper"> and set manage the width in this node.
asign width: 100%; height: auto; to the img so it adjust proportionally to its parent.
Here you have it in a snippet. Hope it helps.
<div class="item">
<div class="image-wrapper">
<img
src=
"https://png.pngtree.com/element_origin_min_pic/16/10/16/105802ebe43fe0f.jpg"/>
</div>
<p>some paragraph</p>
</div>
<style>
.item{
display:flex;
}
.image-wrapper {
width: 25%; /* means 25% of .item */
}
img{
width: 100%; /* means 100% of its parent .image-wrapper */
height: auto;
}
</style>
It happens because, per default the tag <img>is inline. You need to change it to block or flex
I am wondering if this is possible: I have a header that can contain a variable amount of text. Below that I have another element which I want to take up the remaining height of the page.
<div class="header row">
<div class="title column large-5">Potentially very long text</div>
<div class="menu column large-7">Menu items</div>
</div>
<div class="content">
</div>
<div class="footer">
</div>
Normally I would do this using calc, eg:
.content {
height: calc(100vh - 75px);
}
Where 75px is the set height of .header.
But in this example, the .header element is dynamic and does not have a set height. Only a padding and font-size are set.
To complicate things, this also uses the Foundation Grid layout, which makes me nervous about using display: table (.title and .menu sit side by side on desktop, but stacked on mobile) .
Is there anyway to get the height of the dynamic header element (without resorting to JQuery)?
You can use flexbox and set .content to flex-grow: 1 so that it will fill to grow the available space.
body {
display: flex;
flex-direction: column;
min-height: 100vh;
margin: 0;
}
.content {
flex-grow: 1;
background: #eee;
}
<div class="header row">
<div class="title column large-5">Potentially very long text</div>
<div class="menu column large-7">Menu items</div>
</div>
<div class="content">
</div>
<div class="footer">
</div>
I made a small pen to show the way to do this using flex box, it involved changing your markup a bit:
css:
.container {
display: flex;
flex-direction: column;
height: 250px; // whatever you want here
}
.header {
width: 100%;
background: red;
padding: 10px;
}
.content {
background: yellow;
width: 100%;
flex-grow: 1;
}
So the content will always take the available space inside the content div.
check the whole pen: http://codepen.io/anshul119/pen/yMYeLa
hope this helps.
In a responsive layout, I have two columns. The left column is the sidebar and the right column is the content.
Using a media query, when the screen width is tiny, the columns turn to 100% width and stack on top of each other.
In this case, I want the sidebar (the first div) to appear beneath the content (the second div).
I tried using float: right on a small screen once it's at 100%, but at 100% width, the float apparently doesn't matter.
.left, .right {
width: 100%;
float: left;
background: green;
}
.left {
float: right;
background: red;
}
.half {
width: 50%;
}
.space {
width: 100%;
display: block;
height: 40px;
}
And on the page:
<div class="left half"> <!-- To mimic full screen size -->
Left
</div>
<div class="right half">
Right
</div>
<div class="space"></div>
<div class="left"> <!-- To mimic small screen size -->
Left
</div>
<div class="right"><!-- This should appear first -->
Right
</div>
Here is the fiddle: https://jsfiddle.net/ph09frvw/
I'm sure this is not the first time someone wanted to wrap the sidebar under the content, I just haven't been able to find a solution.
You can use display: flex and use the order property to change the order of the <div> elements. While floating can be helpful for horizontal alignment, it will be of little help for vertical alignment, Here is an example:
.flex {
display: flex;
flex-flow: row wrap;
}
.left {
order: 2;
flex: 1 0 50%;
background: red;
}
.right {
order: 1;
flex: 1 0 50%;
background: green;
}
.full {
margin-top: 20px;
}
.full > .left,
.full > .right {
flex: 1 0 100%;
}
<div class="flex">
<div class="left">
Left
</div>
<div class="right">
Right
</div>
</div>
<div class="flex full">
<div class="left">
Left
</div>
<div class="right">
Right
</div>
</div>
You could use the display:flex; property combined with flex-direction to reorder your divs. Ref: https://css-tricks.com/almanac/properties/f/flex-direction/
Remember to reference your related class-names in your HTML elements' class attribute.
Your CSS display:block should do the trick, else try something like:
float: left
When you use: display:block on a div element, you do not need to specify width:100% as it should automatically span across the width if it is not hindered by anything else.
Make sure the position of these elements are "relative", else it may not work as expected; it may be stated globally that some specific tags should be displayed "absolute" and that may break what you're trying to achieve.
<div class="wrapper">
<div class="sidebar-wrapper"></div>
<div class="content-wrapper"></div>
</div>
The height of content-wrapper is dynamic (auto). Is there any way to get the height of it and use it for the sidebar-wrapper so that it looks nice?
Displaying them like table cells would do it. Table cells can adjust their height automatically to the content, and all cells on the same row get the same height. If you give the side bar a fixed width (which is likely), you can easily get the content wrapper to fill the remaining space.
Whichever has the longest content will determine the height.
.wrapper {
width: 100%;
display: table;
}
.sidebar-wrapper,
.content-wrapper {
display: table-cell
}
.sidebar-wrapper {
width: 200px;
background-color: silver;
}
.content-wrapper {
background-color: yellow;
}
<div class="wrapper">
<div class="sidebar-wrapper">Here is <br>content<br>that is .....<br><br><br><br><br><br>Quite long</div>
<div class="content-wrapper">Smaller content</div>
</div>
Flexbox is an alternative to #GolezTrol's CSS tables.
.wrapper {
display: flex;
}
.sidebar-wrapper {
width: 200px;
background-color: silver;
}
.content-wrapper {
background-color: yellow;
flex: 1;
}
<div class="wrapper">
<div class="sidebar-wrapper">Here is
<br>content
<br>that is .....
<br>
<br>
<br>
<br>
<br>
<br>Quite long</div>
<div class="content-wrapper">Smaller content</div>
</div>
This question already has answers here:
How can I make Bootstrap columns all the same height?
(34 answers)
Closed 7 years ago.
Consider the code below:
<div class="row">
<div class="col-xs-3"><div id="sidebar">sidebar</div></div>
<div class="col-xs-3">content content content content content content content content content content content content content content content</div>
</div>
I want the sidebar always has the height of the right column.
Demo: http://www.bootply.com/FT3DVckZgp
Use table method. It works in all browsers. Give display: table to parent and display: table-cell to children.
.row {
display: table;
}
[class*="col-"] {
float: none;
display: table-cell;
vertical-align: top;
}
Here is the fiddle
Another cool method is with the help of margins.
.row{
overflow: hidden;
}
[class*="col-"]{
margin-bottom: -99999px;
padding-bottom: 99999px;
}
Here is the fiddle
You can use following code to define column of same height by providing display layout as table, table-cell.
Define these CSS classes
.container-sm-height
{
display: table;
padding-left:0px;
padding-right:0px;
}
.row-sm-height
{
display: table;
table-layout: fixed;
height: 100%;
}
.col-sm-height
{
display: table-cell;
float: none;
height: 100%;
}
For Small devices use this media query
#media (min-width: 480px)
{
.row-xs-height {
display: table;
table-layout: fixed;
height: 100%;
width: 100%;
}
.col-xs-height {
display: table-cell;
float: none;
height: 100%;
}
}
Now Apply these classes in your HTML structure as following
<body>
<div class="row container-fluid row-sm-height">
<row class="col-sm-3 col-sm-height" id="sidebar">
<!--your code-->
</row>
<row class="col-sm-9 col-sm-height">
<!--Your code-->
</row>
</div>
</body>
HTML
<div class="row">
<div class="col-xs-3 euqlHeight"><div id="sidebar">sidebar</div></div>
<div class="col-xs-3 euqlHeight">content content content content content content content content content content content content content content content</div>
</div>
JS
var maxHeight = 0;
$(document).ready(function() {
$(".euqlHeight").each(function() {
if ($(this).height() > maxHeight) {
maxHeight = $(this).height();
}
});
$(".euqlHeight").height(maxHeight);
});
$(window).resize(function() {
maxHeight = 0;
$(".euqlHeight").removeAttr("style");
$(".euqlHeight").each(function() {
if ($(this).height() > maxHeight) {
maxHeight = $(this).height();
}
});
$(".euqlHeight").height(maxHeight);
});
Give id to the second right col and on page load use jquery as
$("#sidebar").css("height", $("#IdOfRightDiv").height());
You can Go For the Display:table Property to Get the Output You Desired
Have Tweeted Your Code
Check the above Link
<div class="row" style="display:table">
<div id="sidebar" class="col-xs-3" style="display:table-cell;float:none"><div>sidebar</div></div>
<div class="col-xs-3" style="display:table-cell;float:none">content content content content content content content content content content content content content content content</div>
</div>