I've been trying to figure this one out, but haven't been successful yet. I understand the 'overflow' attribute, but I can't quite get it to work in my case. Below is a simplified version of my widget structure:
The black DIV element is a specifically-sized placeholder for my widget that the host application provides. It has height and width set to a specific value.
The red DIV is my widget container which I specify the height and width to be 100%, taking up the entire parent container.
The green DIVs are general visual sections of my widget ( which in fact could be a few DIVs deep ). The first three heights are determined by static labels or buttons. I don't specifically set a height or width on them.
The blue DIV at the bottom within the last green DIV is intended to contain dynamic content which is populated at runtime.
What I'd like is that the blue DIV becomes scrollable when it overflows its parent container. Simply adding "overflow: auto" to the blue DIV doesn't work.
Here's a simulated HTML structure:
<div id="placeholder" style="margin: 8px; height: 300px; width: 300px; background-color: gainsboro;">
<div id="widget-container" style="height: 100%; width: 100%;">
<div id="widget">
<div id="section-1-container">
<div id="section-1">
<div style="display: block; padding: 4px">
Some static stuff (buttons, labels...)
</div>
</div>
</div>
<div id="section-2-container">
<div id="section-2">
<div style="display: block; padding: 4px">
Some static stuff (buttons, labels...)
</div>
</div>
</div>
<div id="section-3-container">
<div id="section-3">
<div style="display: block; padding: 4px">
Some static stuff (buttons, labels...)
</div>
</div>
</div>
<div id="section-4-container">
<div id="section-4" style="display: block; padding: 4px;">
Some dynamic stuff (rows of records...)
<div id="record-container" style="display: block; margin-left: 12px; padding: 4px;">
<div class="record" style="padding: 4px">
Record 1
</div>
<div class="record" style="padding: 4px">
Record 2
</div>
<div class="record" style="padding: 4px">
Record 3
</div>
<div class="record" style="padding: 4px">
Record 4
</div>
<div class="record" style="padding: 4px">
Record 5
</div>
<div class="record" style="padding: 4px">
Record 6
</div>
<div class="record" style="padding: 4px">
Record 7
</div>
<div class="record" style="padding: 4px">
Record 8
</div>
<div class="record" style="padding: 4px">
Record 9
</div>
<div class="record" style="padding: 4px">
Record 10
</div>
</div>
</div>
</div>
</div>
</div>
</div>
I've tried adding "overflow: auto" to "section-4-container", "section-4", and "record-container", but the records still overflow the container space. How could I modify this such that the last section (ideally the "record-container") adds the vertical scrollbar when needed?
Thanks in advance!
You have to set the section-4-container height, the browser does not know its size, so it will just increase the size as more content is added.
I removed the id="widget", and applied flexbox styles.
the id="widget-container" is the flexbox container, so it requires two css roles:
display: flex; flex-direction: column;
then we tell to section-4-container to fill the remaining space:
flex: 1 1 auto; overflow: auto;
<div id="placeholder" style="margin: 8px; height: 300px; width: 300px; background-color: gainsboro;">
<div id="widget-container" style="height: 100%; width: 100%; display: flex; flex-direction: column;">
<div id="section-1-container">
<div id="section-1">
<div style="display: block; padding: 4px">
Some static stuff (buttons, labels...)
</div>
</div>
</div>
<div id="section-2-container">
<div id="section-2">
<div style="display: block; padding: 4px">
Some static stuff (buttons, labels...)
</div>
</div>
</div>
<div id="section-3-container">
<div id="section-3">
<div style="display: block; padding: 4px">
Some static stuff (buttons, labels...)
</div>
</div>
</div>
<div id="section-4-container" style="flex: 1 1 auto; overflow: auto;">
<div id="section-4" style="display: block; padding: 4px;">
Some dynamic stuff (rows of records...)
<div id="record-container" style="display: block; margin-left: 12px; padding: 4px;">
<div class="record" style="padding: 4px">
Record 1
</div>
<div class="record" style="padding: 4px">
Record 2
</div>
<div class="record" style="padding: 4px">
Record 3
</div>
<div class="record" style="padding: 4px">
Record 4
</div>
<div class="record" style="padding: 4px">
Record 5
</div>
<div class="record" style="padding: 4px">
Record 6
</div>
<div class="record" style="padding: 4px">
Record 7
</div>
<div class="record" style="padding: 4px">
Record 8
</div>
<div class="record" style="padding: 4px">
Record 9
</div>
<div class="record" style="padding: 4px">
Record 10
</div>
</div>
</div>
</div>
</div>
</div>
Related
[enter image description here][1]currently i am facing one problem.
I generated table using div with fix header and scrollbar to div row section.
but problem is both div are not taking whole 50% 50% width.
I have tried following code.but not working.
.brd2 {
height: auto;
max-height: 100px;
overflow: auto;
position: absolute;
width: 100%;
}
.back-clr {
background-color: red;
}
HTML PART
<div class="container">
<div class="row">
<div class="col-md-8">
<div style="display: table;width:100%">
<div style="display: table-row">
<div style="width:50%; display: table-cell;">
Test
</div>
<div style="width:50%; display: table-cell;">
test
</div>
</div>
<div class="brd2" style="display: table-row;">
<div class="content" style="width:50%; display: table-cell;">
<p>sdfds
fdsf</p>
<p>dsfds
fds</p>
<p> fds
fsf
dsf</p>
<p>sdfds
fdsf</p>
<p>dsfds
fds</p>
<p> fds
fsf
dsf</p>
</div>
<div class="content back-clr" style="width:50%;display: table-cell;">
this is second div
</div>
</div>
</div>
</div>
</div>
</div>
I have two Div's, the left one is a sidebar of sorts (but it does not extend the full height of the screen), and the right one is the content Div that should occupy as much of the screen as possible and collapse/move underneath the sidebar as the screen shrinks. Right now I have the sidebar set up how I expect it to be, but the Content Div begins to overlap the Sidebar as the page shrinks and does not move below.
I have tried different position: parameters (fixed,absolute,relative) different width/min-width values, as well as different values for float. I have everything in html styling right now for simplicity. The css files that were being used seemed to be interfering with functionality so I attempted to override them via styling directly within the HTML.
<body style="padding-top: 5px; padding-bottom: 20px; padding-left: 15px; padding-right: 15px; min-height: 80%; min-height: 50vh;">
<h3 class="text-center"> Title </h3>
<div class="SideContainer" style="background-color: green;position:absolute;left:0; top:80; bottom: 400;width: 20vw;min-width: 200px;max-width: 300px;padding: 3px;">
<div style="background-color: red;width: 100%;">Keys</div>
<div style="background-color: blue;">Error Box</div>
<div style="background-color: grey;border: none;width: 100%;border-radius: 3px;">File Menu Button</div>
<p> Enter Display Name</p>
<div style="background-color: yellow;">Name Box</div>
<p> Users Viewing </p>
<div style="background-color: orange;">User box</div></div>
<div class="ContentContainer" style="background-color: gold;position: relative;float: left;left:20vw; top: 25;width:80%;min-width: 400px;margin-right: 3px;padding: 8px;">
<div style="background-color: purple;border: 1px solid;border-radius: 4px;line-height: 2.6;padding: 3px;margin-bottom: 6px;">Doc Title</div>
<div style="background-color: maroon;min-height: 150px;border: 1px solid;border-radius: 4px;padding: 3px;">Doc Content</div></div><body>
Content div should shrink, and at a certain point, move below the Sidebar div.
<body style="padding-top: 5px; padding-bottom: 20px; padding-left: 15px; padding-right: 15px; min-height: 80%; min-height: 50vh;">
<h3 class="text-center"> Title </h3>
<div style="display: flex; flex-flow: row wrap;">
<div class="SideContainer" style="background-color: green;left:0; top:80; bottom: 400;width: 20vw;flex-grow: 1;padding: 3px;min-width: 200px;max-width: 300px">
<div style="background-color: red;width: 100%;">Keys</div>
<div style="background-color: blue;">Error Box</div>
<div style="background-color: grey;border: none;width: 100%;border-radius: 3px;">File Menu Button</div>
<p> Enter Display Name</p>
<div style="background-color: yellow;">Name Box</div>
<p> Users Viewing </p>
<div style="background-color: orange;">User box</div>
</div>
<div class="ContentContainer" style="background-color: gold;float: left;left:20vw; flex-grow: 4;top: 25;margin-right: 3px;padding: 8px;min-width: 200px;">
<div style="background-color: purple;border: 1px solid;border-radius: 4px;line-height: 2.6;padding: 3px;margin-bottom: 6px;">Doc Title</div>
<div style="background-color: maroon;min-height: 150px;border: 1px solid;border-radius: 4px;padding: 3px;">Doc Content</div>
</div>
</div>
<body>
I got your code working using Display:flex, it's a good idea to also separate your code into html and css and use classes references in the HTML. There is a lot of benefits to this including easier to maintain, cleaner, and also makes it easy to follow etc.
I have a problem with using box-shadow. Below is the code:
<div class="container-fluid h-100" style="background-color : #F0F0F0;">
<div id="row1" class="row" style="box-shadow : 0 5px 10px 0 black; height: 100px;">
<div class="col-lg-3">
LOGO
</div>
<div class="col-lg-9" style="background-color: aqua">
HEADER
</div>
</div>
<div id="row2" class="row" style="height: 300px;">
<div id="sectiona" class="col-lg-3" style="background-color: aqua;">
Section A
</div>
<div id="sectionb" class="col-lg-9">
Section B
</div>
</div>
</div>
The box-shadow is not working for the id="sectiona" div? I tried using z-index but still not working. Any solution to this? I'm using bootstrap 4.
z-index property requires that the element's position is set.
<div id="row1" class="row" style="position: relative; z-index: 1; box-shadow : 0 5px 10px 0 black; height: 100px;">
Try applying the box-shadow style to the div with id="row2". That will give you a box-shadow in that section.
I'm not using the tag, so I can't use the colspan attribute.
I'd like to create a table with three cells in the first row, one cell in the last row and two cells in the other rows.
Here's my code (minimal):
.row {
display: table-row;
}
.cell {
display: table-cell;
}
HTML:
<div style="display: table;">
<div class="row" style="width: 100%;">
<div class="cell" style="width: 33% !important;">
aaaa
</div>
<div class="cell" style="width: 33% !important;">
bbbbb
</div>
<div class="cell" style="width: 33% !important;">
ccccc
</div>
</div>
<div class="row" style="width: 100%;">
<div class="cell" style="width: 50% !important;">
ddddd
</div>
<div class="cell" style="width: 50% !important;">
eeeee
</div>
</div>
<div class="row" style="width: 100%;">
<div class="cell" style="width: 50% !important;">
fffff
</div>
<div class="cell" style="width: 50% !important;">
ggggg
</div>
</div>
<div class="row" style="width: 100%;">
<div class="cell" style="width: 100% !important;">
last cell
</div>
</div>
</div>
And this is what I get (I can't post images): http://gyazo.com/cc036ed406f6c1a166955522d40e05b0.png
I would build this layout as follows.
For the HTML:
<div class="parent">
<div class="row r3">
<div class="cell">aaaa</div>
<div class="cell">bbbbb</div>
<div class="cell">ccccc</div>
</div>
<div class="row r2">
<div class="cell">ddddd</div>
<div class="cell">eeeee</div>
</div>
<div class="row r2">
<div class="cell">fffff</div>
<div class="cell">ggggg</div>
</div>
<div class="row r1">
<div class="cell">last cell</div>
</div>
</div>
and apply the following CSS:
.row {
display: table;
border: 1px dashed blue;
width: 100%
}
.cell {
display: table-cell;
border: 1px dotted blue;
}
.r3 .cell {
width: 33.333333%;
}
.r2 .cell {
width: 50%;
}
.r1 .cell {
width: 100%;
}
Use display: table for each div.row block element with 100% width.
You don't need to explicitly define a CSS table row, one will be created anonymously as needed.
See reference: http://www.w3.org/TR/CSS2/tables.html#anonymous-boxes
See demo: http://jsfiddle.net/audetwebdesign/72yb5th2/
You're trying to emulate a table with divs. Why? The <table> tag is made for exactly this kind of tabular data.
I have the following HTML:
<article id="articlesss" class="container_12 clearfix" style="margin-top: 2em; display: table;">
<div style="display: table-row">
<div class="grid_6" style="display: table-cell;">
<div class="block-border">
<div style="background-color: red; height: 100px;"></div>
</div>
</div>
<div class="grid_6" style="display: table-cell;">
<div class="block-border">
<div style="background-color: red; height: 200px;"></div>
</div>
</div>
</div>
</article>
I am using display: table-row because I heard that this would make my DIVs work like table cells and I was wanting the DIVs to be the same height. However it seems like the first grid_6 grid has a small height while the second has at least 100px. How can I make it fill to be the same height?
Here's an example: fiddle
<div class="block-border">
<div style="background-color: red; height: 100px;"></div>
You have set the height of second element i.e Height = 100px .
Set the height to both the div elements .
Both grid_6 elements are the same height. The reason why you see one red rectangle larger than the other is you are coloring the inside divs. If you put the color on the grid_6 elements - they are the same. http://jsfiddle.net/A7yXc/
<article id="articlesss" class="container_12 clearfix" style="margin-top: 2em; display: table;">
<div style="display: table-row">
<div class="grid_6" style="display: table-cell; background-color: red;">
<div class="block-border">
<div style="height: 100px;">das</div>
</div>
</div>
<div class="grid_6" style="display: table-cell; background-color: red;">
<div class="block-border">
<div style="height: 200px;">das</div>
</div>
</div>
</div>