This question already has answers here:
Make a div span two rows in a grid
(2 answers)
Left column and stacked right column using flexbox CSS [duplicate]
(2 answers)
Closed 18 days ago.
The community is reviewing whether to reopen this question as of 18 days ago.
note: it's not a duplicate, since i mentioned those solutions, and wrote that they not what i needed
I want to "grid" 3 elements using flex.
It is composed of three div elements:
Two that takes 80% of the container element and with 50% height each, both stacked one above the other.
One that is beside them, and takes 100% height and 20% width of the container.
like this:
<div id="container">
<div>A</div>
<div>B</div>
<div>C</div>
</div>
------------------------
| | B |
| A -------------------
| | C |
------------------------
I know how to do it with grid or with inner-container for B and C.
I also know how to do it using flex with flex-direction: column.
I know how to do it using display:grid
However, for some reason :-\ I have to do it using flex & row and without inner-container. any ideas?
See if the below code works out for you. I am also attaching the output image.
.container{
display : flex;
height : 300px;
width : 500px;
}
.left{
height: 100%;
width : 20%;
background-color : red;
}
.right{
height : 100%;
width : 80%;
}
.r{
height : 50%;
width : 100%;
}
.r1{
background-color : yellow;
}
.r2{
background-color : blue;
}
<div class="container">
<div class="left"></div>
<div class="right">
<div class="r r1"></div>
<div class="r r2"></div>
</div>
</div>
Related
This question already has answers here:
Make a div fill the height of the remaining screen space
(41 answers)
Fill remaining vertical space with CSS using display:flex
(6 answers)
Closed 1 year ago.
I have an element that can be any size. I need to set the child element to fill the remaining space. I wrote a little demo of my problem.
https://www.w3schools.com/code/tryit.asp?filename=GPOS93IXT6E7
.random-size{
height:200px;
width:100px;
padding:10px;
background-color:grey;
}
.container-fill{
background-color:red;
height:100%;
}
<div class="random-size">
<div class="container-fill">
hello world
</div>
</div>
Outputs:
This is correct for the output for now but if I add another child element
https://www.w3schools.com/code/tryit.asp?filename=GPOSB2B28A0I
<div class="random-size">
<div>uh oh</div>
<div class="container-fill">
hello world
</div>
</div>
The output is now:
As you see there is out of bounds content. I can't use overflow:hidden due to content will be displayed at the bottom. I tried using grids/tables but I could not figure it out. I don't want to resort to using calc.
If you can use display: flex, I'd like to recommend it.
.container{
width: 300px;
padding: 16px;
height: 400px;
background: gray;
display: flex;
flex-direction: column;
}
.box{
background: red;
flex-grow: 1;
}
<div class="container">
<p>some string</p>
<div class="box">
BOx
</div>
</div>
This question already has answers here:
Image inside div has extra space below the image
(10 answers)
Closed 3 years ago.
I have a <div> containing child <img> element:
<div class="wrapperdiv">
<img src="blob" class="myimg">
</div>
Now, I want the <div> to have the same height as <img>.
More elaborately, my goal is to have div with img inside to have exactly the same position as if there was only img without wrapper div!
I've tried setting height: auto to the <div>, but while it sets the height to roughly same as <img>, it is larger by 1 pixel, and I'd like them to absolutely equal.
#Justin Trevein, I have prepared one working demo on the basis of comment provided by #fcalderan. I hope this will be helpful.
This DEMO is related to show only Height, and not a width.
.wrapperdiv {
background-color: green;
}
.wrapperdiv img {
display: block;
}
<div class="wrapperdiv">
<img src="https://cdn.pixabay.com/photo/2015/12/01/20/28/road-1072823_960_720.jpg" class="myimg"/>
</div>
Thanks, Jignesh Raval
set css :
.myimg { display: block ;}
and
.wrapperdiv { height: unset;}
This question already has answers here:
Maintain the aspect ratio of a div with CSS
(37 answers)
Height equal to dynamic width (CSS fluid layout) [duplicate]
(9 answers)
Responsively change div size keeping aspect ratio [duplicate]
(5 answers)
Closed 4 years ago.
I don't know how but I've been at this for hours and can't figure it out.
I'm trying to make a div have a fixed aspect ratio of 1:1, but the padding-top trick just isn't working.
Here is my code:
HTML:
<div class="test">
<div/><div/><div/><div/>
</div>
CSS:
.test {
width: 50px;
height: 0px;
padding-top: 100%;
background: blue;
}
Can anyone figure what I am doing wrong?
JSFiddle link: http://jsfiddle.net/ajpgbc0L/
Expected result: http://jsfiddle.net/ajpgbc0L/2/
EDIT: I should have made it clear that the width could be anything
Adding a wrapper element around it with a set width will allow you to achieve the desired result:
<div class="test__outer">
<div class="test">
<div/><div/><div/><div/>
</div>
</div>
css:
.test {
height: 0px;
padding-top: 100%;
background: blue;
}
.test__outer {
width: 50px;
}
This is because precent padding is calculated, based on the width of the containing block, not the block you are setting padding on:
https://developer.mozilla.org/en-US/docs/Web/CSS/padding#Values
This question already has answers here:
html/css responsive 3-column layout - stack right column below left column
(2 answers)
Is it possible for flex items to align tightly to the items above them?
(5 answers)
Closed 5 years ago.
I have a grid system that uses flexbox. At present I'm trying to work out if I can make it work with the following scenario.
<div class="flex-outer">
<div class="flex-inner span-all red-box">
<h2>Title</h2>
</div>
<div class="flex-inner span-1of2 green-box">
<div>Some text</div>
</div>
<div class="flex-inner span-1of2 blue-box">
<p>A table perhaps</p>
</div>
</div>
.flex-outer {
display:flex;
flex-wrap:wrap;
}
.span-all {
width:100%;
}
.span-1of2 {
width:50%;
}
.red-box {
background-color:Red;
}
.green-box {
background-color:Green;
}
.blue-box {
background-color:blue;
}
The html above could be used to create the following layout:
However on a certain breakpoint, I'd be looking to change the layout to something like this:
I can change the order of the green and blue boxes to suit, but on wrapping, the second box is position below the blue box. This is the behaviour I expected.
So, are there any flexbox tricks I can use to tuck the green box immediate beneath the red one?
I want to display static naive bar in top and rest entire page into grid of 6 column and increasing rows.
css:
http://grids.heroku.com/grid.css?column_width=182&column_amount=6&gutter_width=5
Here is html:
<div class=container_6>
<div class=grid_5>
</div>
</div>
JSFIDDLE : http://jsfiddle.net/karimkhan/vpqvrxhn/1/
Why display page still looks empty?
I am following this doc : http://1200px.com/
Why display page still looks empty?
Because your container's height is 0px. You must set some height to your Container's Grids.
I've created 6 Grids Container for you as 1200px.com for 6 columns - TRY THIS DEMO
HTML:
<div class=container_6>
<div class=grid_1></div>
<div class=grid_1></div>
<div class=grid_1></div>
<div class=grid_1></div>
<div class=grid_1></div>
<div class=grid_1></div>
</div>
CSS:
/* ---------- Containers ---------- */
.container_6 {
margin-left: auto;
margin-right: auto;
width: 1122px;
}
.grid_1 {
background-color: #FF0000;
height: 300px;
}
[EDITED]
As per your comment:
I want entire screen to be divided into grid of 6 column and 5 row. It
should be responsive to any device. IS that possible? – #user2129623
TRY - THIS DEMO
I've set padding: 5px 0px; and height: 20%; to .container_6 to divided the entire screen into grid of 6 columns and 5 rows and you can adjust the padding as you want.