I am trying to create three parallel columns of the same width (33.3%) and height (100%). In each column, I want to split it vertically into 80% - 20% ratios. The code below seems straight forward, but I couldn't achieve that. If someone could advise?
Note that I keep the flex and wrap stuff in the inner parts because I will be adding elements into them later. Thanks.
#outer-container {
height: 500px;
width: 100%;
}
#left-container, #mid-container, #right-container {
background-color: #495052;
width: 33.3%;
height: 100%;
border: 1px solid;
border-color: #cae329; /*Bright citrus*/
overflow: auto;
}
#left-top-container, #mid-top-container, #right-top-container {
display: flex;
flex-wrap: wrap;
background-color: #495052;
width: 100%;
height: 80%;
overflow: auto;
}
#left-bottom-container, #mid-bottom-container, #mid-bottom-container {
display: flex;
flex-wrap: wrap;
background-color: yellow;
width: 100%;
height: 20%;
border: 1px solid;
border-color: #cae329;
overflow: auto;
}
<div id="outer-container">
<div id="left-container">
<div id="left-top-container">
</div>
<div id="left-bottom-container">
</div>
</div>
<div id="mid-container">
<div id=mid-top-container">
</div>
<div id="mid-bottom-container">
</div>
</div>
<div id="right-container">
<div id="right-top-container">
</div>
<div id="right-bottom-container">
</div>
</div>
</div>
You've got a few typos in your code. Notably a missing quotation mark on one of your ids in your HTML (mid-top-container), and a duplicate rule for #mid-bottom-container instead of #right-bottom-container.
Also, your columns are still display:block, so they will not stay on the same line. I changed them to display: inline-block; to fix that. Their widths should be calc(100% / 3) to make them exactly one third of the width. They need box-sizing: border-box to make the padding/border part of the width figure, and finally, the parent #outer-container needs font-size:0 to remove any white space between the columns.
#outer-container {
height: 500px;
width: 100%;
font-size: 0;
}
#left-container, #mid-container, #right-container {
display: inline-block;
background-color: #495052;
width: calc(100% / 3);
height: 100%;
border: 1px solid;
border-color: #cae329; /*Bright citrus*/
overflow: auto;
box-sizing: border-box;
}
#left-top-container, #mid-top-container, #right-top-container {
display: flex;
flex-wrap: wrap;
background-color: #495052;
width: 100%;
height: 80%;
overflow: auto;
}
#left-bottom-container, #mid-bottom-container, #right-bottom-container {
display: flex;
flex-wrap: wrap;
background-color: yellow;
width: 100%;
height: 20%;
border: 1px solid;
border-color: #cae329;
overflow: auto;
}
<div id="outer-container">
<div id="left-container">
<div id="left-top-container">
</div>
<div id="left-bottom-container">
</div>
</div>
<div id="mid-container">
<div id="mid-top-container">
</div>
<div id="mid-bottom-container">
</div>
</div>
<div id="right-container">
<div id="right-top-container">
</div>
<div id="right-bottom-container">
</div>
</div>
</div>
Though there are some Typos. But some un-necessary ids and CSS is also present in the Code.
You may try CSS-GRIDS and Flexbox (in a better way) to achieve the same with much lesser code so that the performance of the app increases.
Have removed all extra selectors.
CODEPEN: https://codepen.io/emmeiWhite/pen/RwGyBLO
*{
margin:0;
padding:0;
box-sizing:border-box;
}
#outer-container {
height: 500px;
display:grid;
grid-template-columns:repeat(3,1fr);
width: 100%;
}
.column-wrapper{
display:flex;
flex-direction:column;
background-color: #495052;
border: 1px solid;
border-color: #cae329; /*Bright citrus*/
}
.top-section{
height:80%;
}
<div id="outer-container">
<div class="column-wrapper">
<div class="top-section">
left top
</div>
<div>
bottom
</div>
</div>
<div class="column-wrapper">
<div class="top-section">
mid-top
</div>
<div>
mid-bottom
</div>
</div>
<div class="column-wrapper">
<div class="top-section">
right-top
</div>
<div>
right-bottom
</div>
</div>
</div>
Related
I have a simple HTML, one parent div, and two children. When I am styling one child with float set to right, the next child goes up and the margin-top doesn't apply to it, which I don't want.
Here is the sample code.
.inner1 {
width: 50%;
height: 100px;
border: 5px solid red;
float: right;
}
<div class="outer">
<div class="inner1">
</div>
<div class="inner2">
Text that goes up after float.
</div>
</div>
Can someone please suggest how to handle this situation?
Here is the JSFiddle
I want the output to be something like
Don't use float. float is deprecated. Please take note of this solution using flex.
.outer {
width: 100%;
height: 100%;
display: flex;
flex-flow: row-reverse;
align-items: center;
}
.inner1 {
width: 50%;
height: 100px;
border: 5px solid red;
}
.inner2 {
width: 50%;
text-align: center;
}
<div class="outer">
<div class="inner1">
</div>
<div class="inner2">
Text that goes up after float.
</div>
</div>
Snippet #2
.outer {
width: 100%;
height: 100%;
display: flex;
flex-flow: column;
align-items: flex-end;
}
.inner1 {
width: 50%;
height: 100px;
border: 5px solid red;
}
.inner2 {
width: 50%;
}
<div class="outer">
<div class="inner1">
</div>
<div class="inner2">
Text that goes up after float.
</div>
</div>
Try this code:
.outer{
display:flex;
flex-direction:column;
align-items:flex-end;
}
.inner1 {
width: 50%;
height: 100px;
border: 5px solid red;
}
.inner2{
width: 50%;
}
<div class="outer">
<div class="inner1">
</div>
<div class="inner2">
Text that goes up after float.
</div>
</div>
You can use clear: both; in the element what has float: right; property.
To keep things neat and short:
https://jsfiddle.net/m53ockLu/
.container {
max-height: 500px;
background: grey;
}
.sidebar {
height: 100vh;
width: 150px;
overflow-x: scroll;
overflow-y: auto;
background: red;
}
.element {
position: relative;
display: flex;
flex-direction: row;
flex-wrap: nowrap;
margin: 5px;
height: 200px;
width: 20px;
background: green;
}
.first {
position: relative;
display: block;
height: 20px;
width: 100px;
background: pink;
}
.second {
display: inline-block;
}
.second-absolute {
position: absolute;
height: 20px;
width: 250px;
background: purple;
}
<div class="container">
<div class="sidebar">
<div class="element">
<div class="first"></div>
<div class="second">
<div class="second-absolute"></div>
</div>
</div>
<div class="element">
</div>
<div class="element">
</div>
<div class="element">
</div>
</div>
</div>
Is it possible to keep the red container scrollable on vertical axis, and at the same time make the purple (.second-absolute) element overflow this red container horizontally? I'm totally out of ideas, I thought that overflow-x & overflow-y should do the trick, but no dice.
Thank you very much for any help.
Is it possible to keep the red container scrollable on vertical axis, and at the same time make the purple (.second-absolute) element overflow this red container horizontally?
No.
I tried Ethan's suggestion and couldn't get the purple box to visibly overflow the scrollbar:
.container {
max-height: 500px;
background: grey;
}
.sidebar {
height: 100vh;
width: 150px;
overflow-y: scroll;
background: red;
}
.element {
position: relative;
display: flex;
flex-direction: row;
flex-wrap: nowrap;
margin: 5px;
height: 200px;
width: 20px;
background: green;
}
.first {
position: relative;
display: block;
height: 20px;
width: 100px;
background: pink;
}
.second {
display: inline-block;
}
.second-absolute {
position: absolute;
height: 20px;
width: 250px;
background: purple;
}
<div class="container">
<div class="sidebar">
<div class="element">
<div class="first"></div>
<div class="second">
<div class="second-absolute"></div>
</div>
</div>
<div class="element">
</div>
<div class="element">
</div>
<div class="element">
</div>
</div>
</div>
I don't think the browser will let you overflow the scrollbar, I even put z-index, explicitly said to visibly overflow, played around with the position property etc.
Consider this example of letting the content dictate the size:
.container {
max-height: 500px;
background: grey;
}
.sidebar {
height: 100vh;
width: max-content;
overflow-y: auto;
background: red;
}
.element {
position: relative;
display: flex;
flex-direction: row;
flex-wrap: nowrap;
margin: 5px;
height: 200px;
background: green;
}
.first {
display: block;
height: 20px;
background: pink;
}
.second {
display: inline-block;
}
.second-absolute {
height: 20px;
width: 250px;
background: purple;
}
<div class="container">
<div class="sidebar">
<div class="element">
<div class="first"></div>
<div class="second">
<div class="second-absolute"></div>
</div>
</div>
<div class="element">
</div>
<div class="element">
</div>
<div class="element">
</div>
</div>
</div>
You made the parent div sidebar have overflow-x: scroll;, overflow-y: auto;. Instead, make each child have its own overflow properties instead of the parent.
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>
I have a html structure like this and some basic style
.container {
display: block;
width: auto;
/* this is must */
height: auto;
/* this is must */
max-width: 300px;
}
.container .row {
display: flex;
width: 100%;
height: auto;
}
.container .row .left {
display: inline-block;
width: 100px;
height: auto;
}
.container .row .right {
display: inline-block;
width: auto;
height: auto;
}
<div class="container">
<div class="row">
<div class="left"></div>
<div class="right"></div>
</div>
<div class="row">
<div class="left"></div>
<div class="right"></div>
</div>
<div class="row">
<div class="left"></div>
<div class="right"></div>
</div>
</div>
The style may not working, I only pasted the basic part of it.
What I want to achieve is, the parent element has a max-width, it contains multiple rows, each row has two elements, 'left' and 'right'. I give a fixed width to 'left' element, and a min-width/max-width to 'right' element. I would like the width of the right element auto grow as the content grow until the max-width, but if the content is short, the right element shall also shrink.
I tried table and flex box, but no luck. Thanks for any help
The problem is because you have to specify the max-width to the .right class.
1) The overall container's max-width:300px and left one's width: is 100px, so the remaining 200px; you can give it to right row.
2) Have added background for better understanding.
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<style>
.container {
display: block;
width: auto; /* this is must */
height: auto; /* this is must */
max-width: 300px;
}
.container .row{
display: flex;
width: 100%;
height: auto;
background-color:Red;
}
.container .row .left{
display: inline-block;
width: 100px;
background-color:yellow;
}
.container .row .right{
display: inline-block;
height: auto;
background-color:green;
max-width: 200px;
overflow:hidden;
}
</style>
<body>
<div class="container">
<div class="row">
<div class="left">qweqweqwe</div>
<div class="right">qweqweqwew<p>afdllssssssssdddddddddssssssssss</p><p>asdasdasdadsas</p></div>
</div>
<div class="row">
<div class="left">qweqweqwe</div>
<div class="right">qweqweqwe</div>
</div>
<div class="row">
<div class="left">qweqweqw</div>
<div class="right">qweqweqweqwe</div>
</div>
</div>
</body>
</html>
Find the codepen sample here and check it with your requirement. Also, let me know if there is something that you want to get from.
.container .row{
display: flex;
width: 100%;
height: auto;
}
.container .row .left{
display: inline-block;
width: 100px;
height: auto;
}
.container .row .right{
display: inline-block;
width: auto;
height: auto;
max-width: 150px;
overflow: hidden;
}
Add display: flex to your .row class and set min-width: 100px to .right - see a working jsfiddle here: https://jsfiddle.net/o3o9j4za/1/
<div class="container">
<div class="row">
<div class="left">1234</div>
<div class="right">4312</div>
</div>
<div class="row">
<div class="left">1235</div>
<div class="right">qweqwereqwr</div>
</div>
<div class="row">
<div class="left">5342</div>
<div class="right">3g43g3g3g</div>
</div>
.container {
display: block;
width: auto; /* this is must */
height: auto; /* this is must */
max-width: 300px;
}
.container .row{
width: 100%;
height: auto;
display:flex;
}
.container .row .left{
display: inline-block;
height: auto;
width: 100px;
background-color:#ff0;
}
.container .row .right{
display: inline-block;
width: auto;
min-width: 100px;
height: auto;
background-color:#f0f;
}
Note, that your flex container (.row) is affected by the max-width of .container.
(Edit: misread a bit - should be like you want it now?)
How about this flexbox solution? I think it comes closest to what you are looking for:
<div class="container">
<div class="row">
<div class="left">test left</div>
<div class="right">test right</div>
</div>
<div class="row">
<div class="left">test left</div>
<div class="right">test right</div>
</div>
<div class="row">
<div class="left">test left</div>
<div class="right">test right</div>
</div>
</div>
.container {
padding: 2px;
border: 1px solid green;
max-width: 300px;
}
.row {
display: flex;
padding: 2px;
border: 1px solid red;
max-width: 300px;
}
.left {
padding: 2px;
border: 1px solid blue;
width: 100px;
}
.right {
padding: 2px;
border: 1px solid purple;
width: 180px;
}
And the fiddle:
https://jsfiddle.net/xr7ebmsz/
I guess you can try this one for your class "right"
.right{
width:calc(100% - 100px);
}
I try to display a left and right area but it's not working actually with the cotes "right" and "left"
I tried the position :absolute but it's display me something strange
Maybe I'm doing something wrong with my conteneur div or my div element1
Someone knows how I can achieve that?
#conteneur {
padding-top: -25px;
display: flex;
border: 2px solid black;
padding-bottom: 10px;
}
#element1 {
display: block;
width: 350px;
border: 1px solid black;
}
.right {
float: left;
width: 100%;
}
.left {
float: right;
width: 100%;
}
<div id="conteneur">
<div id="element1">
<img src="{{ public_path('../public/uploads/logo-FFRXIII-2017-01.png')}}" style="max-width: 300px;">
<div id="right">
adresse_right
</div>
<div id="left">
adresse_left
</div>
</div>
</div>
you are using flexbox, so stick with flexbox and forget floats
#conteneur {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
width: 100%;
border: 1px solid black;
padding-bottom: 10px;
}
.img {
flex: 0 100%;
}
img {
max-width: 300px;
}
<div id="conteneur">
<div class="img">
<img src="http://placehold.it/300x200">
</div>
<div class="right">
adresse_right
</div>
<div class="left">
adresse_left
</div>
</div>
First of all your
<div id="right">
adresse_right
</div>
<div id="left">
adresse_left
</div>
Won't react to your CSS since these are ID's and in your CSS you are trying to find classes with the . selector. So change the . to a # or change your ID tags to Classes.
Secondly i've created a jsfiddle and edited your code hope this helps!