Overflow area of div has no style [duplicate] - html

This question already has answers here:
Make background color extend into overflow area
(4 answers)
Closed 4 years ago.
I'm trying to create a table like structure that is scrollable horizontally. To do that I have a wrapper div that has overflow-x: auto, a div for each row and a div for each cell.
I want to apply a style to the row but the style is only applied to those elements that are visible.
.inner {
flex: 1 0 10em;
height: 2em;
background-color: green;
}
.outer {
border-bottom: 10px solid red;
display: flex;
}
.box {
width: 20em;
overflow-x: scroll;
}
<div class="box">
<div class="outer">
<div class="inner">1</div>
<div class="inner">2</div>
<div class="inner">3</div>
</div>
</div>
I want all of the green boxes to have a red bottom border, but the border only appears on those items that are not overflowing. What am I missing?

You may try this instead:
.inner {
flex: 1 0 10em;
width:10em; /*Specify a width */
height: 2em;
background-color: green;
}
.outer {
border-bottom: 10px solid red;
display: inline-flex; /* to take the width of content and not container*/
}
.box {
width: 20em;
overflow-x: scroll;
}
<div class="box">
<div class="outer">
<div class="inner">1</div>
<div class="inner">2</div>
<div class="inner">3</div>
</div>
</div>

I dont know exactly what you mean, but I hope this helps:
Since the CSS you use only for the outer,It does just that and put it only for the part that is visible. To achieve bottom red border for all of them, you have to put the border on the inner part.
HTML:
<div class="box">
<div class="outer">
<div class="inner">1</div>
<div class="inner">2</div>
<div class="inner">3</div>
</div>
</div>
CSS:
.inner {
flex: 1 0 10em;
height: 2em;
background-color: green;
border-bottom: 10px solid red;
}
.outer {
width: 20em;
display: flex;
}
.box {
width: 20em;
overflow-x: scroll;
}
Hope it helps :)

Related

How to make a scroll div height only as big as sibling div in row [duplicate]

This question already has answers here:
How can you set the height of an outer div to always be equal to a particular inner div?
(2 answers)
One flex/grid item sets the size limit for siblings
(6 answers)
Closed 2 years ago.
Is this possible with just css? There are two siblings elements. The 2nd element has height that is only big enough to fit its children (children may change over time). The 1st element should have the same height as the 2nd element. If its content is larger than its height then it should overflow with scroll.
The snippet below does not match this because the 1st element takes up as much height as it needs to fully display its contents.
html,
body {
height: 100%;
margin: 0;
padding: 0;
}
#container {
border-style: solid;
border-width: 1px;
border-color: #000;
display: flex;
flex-direction: row;
flex-wrap: nowrap;
width: fit-content;
}
#first {
background-color: #00F;
overflow-y: scroll;
height: 100%;
}
#second {
background-color: #0F0;
height: fit-content;
width: 200px;
}
#block {
height: 40px;
width: 40px;
margin: 5px;
background-color: #F00;
}
<div id="container">
<div id="first">
<div id="block">
</div>
<div id="block">
</div>
<div id="block">
</div>
</div>
<div id="second">
<div id="block">
</div>
<div id="block">
</div>
</div>
</div>
You should wrap the #first with extra wrapper and apply the background color to it. And use height:0 min-height:100% trick on the #first
I also fixed your html mistake. An ID can only be used once per page. So I changed the #block as .block
html,
body {
height: 100%;
margin: 0;
padding: 0;
}
#container {
border-style: solid;
border-width: 1px;
border-color: #000;
display: flex;
flex-direction: row;
flex-wrap: nowrap;
width: fit-content;
}
.scroll-area {
overflow-y:auto;
background-color: #00F;
}
#first {
min-height: 100%;
height: 0;
}
#second {
background-color: #0F0;
/* height: fit-content; // unnecessary */
width: 200px;
}
.block {
height: 40px;
width: 40px;
margin: 5px;
background-color: #F00;
}
<div id="container">
<div class="scroll-area">
<div id="first">
<div class="block">
</div>
<div class="block">
</div>
<div class="block">
</div>
</div>
</div>
<div id="second">
<div class="block">
</div>
<div class="block">
</div>
</div>
</div>

Auto size div and right aligned div in same div container

In the snippet below, I want the "title" div to size itself based on its content, so I don't have to specify a width. That bit is obviously working already. I then want the "rightside" div to take the remaining space and right align itself - at the moment it just sits next to the title div.
And of course I don't want to use floats because that messes up everything and we have a no floats policy here.
Based on reading other threads I thought adding an overflow:hidden to one of the parents would make it do this but I can't get it working.
I don't want to specify a width for either div but it will always be the case that one of the parents will have a width specified, so in this case I've set it on the "outer" element.
So how do we get "rightside" to appear to the right of the red box ? thanks
.outer {
width:500px;
border:1px solid red;
}
.outer div {
display:inline-block;
border:1px solid green;
}
.rightside {
width:auto;
text-align: right;
}
<div class="outer">
<div class="inner">
<div class="title">
Autosize this section based on content
</div>
<div class="rightside">
Right align this
</div>
</div>
</div>
you should use flexbox or grid to solve this kind of problems its easy and fast
flex example
.outer {
width:500px;
border:1px solid red;
}
.inner {
display:flex;
flex-direction:row;
justify-content:space-between;
}
.outer div {
/* display:inline-block; */
border:1px solid green;
}
.rightside {
width:auto;
text-align: right;
}
<div class="outer">
<div class="inner">
<div class="title">
Autosize this section based on content
</div>
<div class="rightside">
Right align this
</div>
</div>
</div>
and grid
.outer {
width:500px;
border:1px solid red;
}
.inner {
display:grid;
grid-template-columns: auto auto;
grid-template-rows: auto;
justify-content:space-between;
}
.outer div {
/* display:inline-block; */
border:1px solid green;
}
.rightside {
width:auto;
text-align: right;
}
<div class="outer">
<div class="inner">
<div class="title">
Autosize this section based on content
</div>
<div class="rightside">
Right align this
</div>
</div>
</div>
Flexbox will help!
.outer {
width: 500px;
border: 1px solid red;
}
.outer .title,
.outer .rightside {
display: inline-block;
border: 1px solid green;
}
.inner {
width: 100%;
display: flex;
justify-content: space-between;
}
<div class="outer">
<div class="inner">
<div class="title">
Autosize this section based on content
</div>
<div class="rightside">
Right align this
</div>
</div>
</div>
If you would like the rightside to fill the rest of the space, you could use flexbox and flex-grow, like this:
.inner {
display: flex;
justify-content: space-between;
}
.inner div {
display:inline-block;
border:1px solid green;
width: auto;
flex-grow: 1;
}
.rightside {
width:auto;
text-align: right;
}
With flexbox, you only need to set display: felx; for the parent element, and margin-left: auto; for the rightside (child) element :
div {
border: 2px dotted silver;
padding: .5em;
}
/* ---------------- */
.parent {
display: flex;
}
.rightside {
margin-left: auto;
}
<div class="parent">
<div>
Child 1
</div>
<div class="rightside">
Child 2
</div>
</div>

How to center horizontally divs inside another div [duplicate]

This question already has answers here:
How can I horizontally center an element?
(133 answers)
Closed 6 years ago.
I'm trying to center div's inside one outter div, but I can't.
My html is something like this :
<div class="outterDiv">
<div class="innerDivBig">
<div style="width: 180px; float:left;margin-right: 5px;background-color: yellow;">
Inner Div
</div>
<div style="width: 180px; float:left;margin-right: 5px;background-color: yellow;">
Inner Div
</div>
<div style="width: 180px; float:left;margin-right: 5px;background-color: yellow;">
Inner Div
</div>
<div style="clear:both"/>
</div>
</div>
And my css is something like this :
.outterDiv{
width: 600px;
border: 1px solid #f00;
text-align: center;
}
.innerDivBig{
margin: 0 auto;
display:table;
}
Here is jsfiddle.
.outterDiv{
width: 600px;
border: 1px solid #f00;
text-align:center;
}
.innerDivBig{
display: inline-block;
}
https://jsfiddle.net/2a8514nf/7/
UPDATE:
https://jsfiddle.net/2a8514nf/4/
I use display: table because the browser calculates the width to fit all the child elements width display: table-cell so that you wont have to worry about the width.
I also use padding instead of margin since it does not expand the element so the parent size remains the same.
.outer {
width: 500px;
border: 1px solid #000;
padding: 15px;
margin: 0 auto;
}
.inner {
display: table;
table-layout: fixed;
width: 100%;
}
.inner > div {
display: table-cell;
padding: 0 5px;
text-align: center;
}
.inner > div > div {
padding: 15px;
text-align: center;
border: 1px solid #00F;
}
<div class="outer">
<div class="inner">
<div>
<div>Inner Div 1</div>
</div>
<div>
<div>Inner Div 2</div>
</div>
<div>
<div>Inner Div 3</div>
</div>
</div>
</div>

How to center group of divs inside div?

I am a bit newbie with CSS and i am pretty obfuscated trying to center a group of divs inside a div. What i want:
divs 2,3 and 4 should be centered inside div1.
My approach:
.div1 {
display: inline-block;
margin: 0 auto;
text-align: center;
}
.restofdivs {
width: 470px;
margin: 20px;
min-height: 1px;
float:center
}
the result is: the 3 divs (2,3 and 4) one on top of another...
Regards,
This can easily be done with table display:
.table-display {
display: table;
width: 100%;
}
.cell-display {
display: table-cell;
}
.div1, .div2, .div3, .div4 {
padding: 40px;
}
.div1 {
background: #ABC;
}
.div2 {
background: #DEF;
}
.div3 {
background: #CAD;
}
.div4 {
background: #FAD;
}
<div class="div1">
<div class="table-display">
<div class="cell-display div2"></div>
<div class="cell-display">
<div class="div3"></div>
<div class="div4"></div>
</div>
</div>
</div>
Maybe set a width on .div1 and remove inline-block from .div1
.div1 {
width: 960px;
margin: 0 auto;
text-align: center;
}
.restofdivs {
width: 470px;
margin: 20px;
min-height: 1px;
}
The most common way to center a block element if you know it's width is to define the width and use "margin: 0 auto". This tells the browser to give a top and bottom margin of 0, and to automatically determine equal margins on the left and right.
Using floats, you can create the layout you described as follows:
http://jsfiddle.net/ynt4suee/
Markup:
<div>
<div id="one" class="border clearfix">one
<div id="wrapper">
<div id="two" class="border">two</div>
<div class="subcontainer">
<div id="three" class="border">three</div>
<div id="four" class="border">four</div>
</div>
</div>
</div>
CSS:
div.border{
border: 1px solid red;
}
div#wrapper{
width: 400px;
margin: 0 auto;
}
div#two{
width: 250px;
float: left;
}
div.subcontainer{
float: right;
width: 130px;
}
.clearfix:after {
content: " "; /* Older browser do not support empty content */
visibility: hidden;
display: block;
height: 0;
clear: both;
}
Here's another approach, using inline-block elements for the inner divs instead:
http://jsfiddle.net/xojqq4v5/
Markup:
<div id="one" class="border">
div 1
<div id="wrapper">
<div id="two" class="border">div 2</div>
<div id="subcontainer">
<div id="three" class="border">div 3</div>
<div id="four" class="border">div 4</div>
</div>
</div>
</div>
CSS:
div.border{
border: 1px solid red;
margin-bottom: 5px;
}
div#wrapper{
width: 450px;
margin: 0 auto;
}
div#two, div#subcontainer{
display: inline-block;
vertical-align: top;
}
div#two{
width: 300px;
}
div#three, div#four{
width: 140px;
}
Still, so long as you know the total width of the inner divs, you can center the wrapper using "margin: 0 auto", which has the advantage of not centering text on all child elements unless otherwise specified.
The difference here is that to lay out the inner divs in columns, div 2 and the container div containing divs 3 and 4 are defined as inline-block elements.

HTML / CSS what is optimal to get following layout construction

I am trying to achieve the following layout through HTML and css:
In this layout you have a red upper div, which is 100% the window width and has the height of it's containing elements
Beneath that you have a green div, containing menu items next to each other, which is 100% the window width as well and has a height that makes it fill the rest of the window.
Next to the green div there is a yellow div which momentarily has a width of 0%.
When clicking an item in the green div makes the green div shift right with the width being the width of the widest menu item and the height that makes it fill the rest of the window.
The yellow div then opens next to the green div and it's width covers the rest of the window. Same for the height, this should make it fill the rest of the window. It contains an iframe that displays the clicked menu item and should cover the yellow div entirely.
I have no problem getting the first layout, however when switching to the 2nd I can't seem to get the green and yellow divs' height right.
Here's what I've got:
<div id="Dashboard_CAClientDIV">
Red div
</div>
<div id="Dashboard_MenuDIV">
Green div
<div class="Dashboard_Tile">
Item 1
</div>
<div class="Dashboard_Tile">
Item 2
</div>
<div class="Dashboard_Tile">
Item 3
</div>
<div class="Dashboard_Tile">
Item 4
</div>
<div class="Dashboard_Tile">
Item 5
</div>
</div>
<div id="Dashboard_FrameDIV">
<iframe id="Yellow Div" src="" width="100%" height="100%">
</div>
Going to the 2nd layout adds "_Exp" to Dashboard_MenuDIV and Dashboard_FrameDIV, here's the css I've got:
html, body, #frmDashboard {
/* any div up to fullscreen-cont must have this
in this case html and body */
height:100%;
min-height:100%;
max-height: 100%;
}
body, div {
/*overflow: hidden;*/
margin: 0px;
}
.Dashboard_Tile {
display:inline-block;
}
#Dashboard_MenuDIV_Exp, #Dashboard_FrameDIV_Exp {
min-height: 100%;
height: 100%;
max-height: 100%;
display: inline-block;
}
#Dashboard_MenuDIV_Exp .Dashboard_Tile {
min-width: 100%;
width: 100%;
max-width: 100%;
margin-top: 1px;
}
#Dashboard_CAClientDIV {
min-width:100%;
width:100%;
max-width:100%;
}
#Dashboard_MenuDIV {
min-width:100%;
width:100%;
max-width:100%;
}
#Dashboard_MenuDIV_Exp {
min-width:20%;
width:20%;
max-width:20%;
float: left;
}
#Dashboard_FrameDIV {
min-width:0%;
width:0%;
max-width:0%;
}
#Dashboard_FrameDIV_Exp {
min-width:75%;
width:75%;
max-width:75%;
float: left;
}
Thanks in advance
Use the new CSS3 flex layout: http://css-tricks.com/snippets/css/a-guide-to-flexbox/:
Working fiddle: http://jsfiddle.net/5UXR9/2/
HTML:
<div id="Dashboard_CAClientDIV">Red div</div>
<div id="Dashboard_Wrapper_MenuDIV_and__FrameDIV">
<div id="Dashboard_MenuDIV">
Green div
<div class="Dashboard_Tile small">Item 1</div>
<div class="Dashboard_Tile small">Item 2</div>
<div class="Dashboard_Tile very-large">Item 3</div>
<div class="Dashboard_Tile small">Item 4</div>
<div class="Dashboard_Tile large">Item 5</div>
</div>
<div id="Dashboard_FrameDIV">
<iframe id="Yellow Div" src="" width="100%" height="100%"></iframe>
</div>
</div>
CSS:
body, html {
height: 100%;
}
#Dashboard_CAClientDIV {
background-color: red;
height: 40px;
width: 100%;
}
#Dashboard_Wrapper_MenuDIV_and__FrameDIV {
width: 100%;
height: 100%;
display: flex;
}
#Dashboard_MenuDIV {
background-color: green
}
#Dashboard_MenuDIV .Dashboard_Tile {
background-color: blue;
height: 50px;
margin-bottom: 5px;
}
#Dashboard_MenuDIV .Dashboard_Tile.small {
width: 100px;
}
#Dashboard_MenuDIV .Dashboard_Tile.large {
width: 200px;
}
#Dashboard_MenuDIV .Dashboard_Tile.very-large {
width: 300px;
}
#Dashboard_FrameDIV {
background-color: yellow;
flex: auto;
}
#Dashboard_FrameDIV iframe {
border: none;
}
Well, a CSS3 solution has already been given, but if you want a more primitive approach (CSS2), you can style your layout with display:table properties. Here's an example similar to your situation:
http://jsfiddle.net/S562t/
HTML:
<div class="stage">
<div class="row-top">
<div class="top">red</div>
</div>
<div class="row-bottom">
<div class="left">
<div class="title">Title 1</div>
<div class="title">Title 2334234234</div>
<div class="title">Title 3</div>
<div class="title">Title 4</div>
</div>
<div class="right">
<iframe src="" frameborder="0"></iframe>
</div>
</div>
</div>
CSS:
.stage
{
overflow: hidden;
display: table;
position: absolute;
width: 100%;
height: 100%;
top:0;
left:0;
}
.row-top
{
display: table-row;
position: relative;
height: 30px;
}
.row-bottom
{
display: table-row;
position: relative;
}
.top
{
background-color: red;
display: table-cell;
position: absolute;
width: 100%;
height: 30px;
}
.left
{
background-color: green;
display: table-cell;
}
.right
{
background-color: yellow;
display: table-cell;
}
iframe
{
width: 100%;
height: 100%;
}
http://jsfiddle.net/S562t/