I am trying to mock up a design for a personal/resume website, the page looks how I intended it too before resizing the page, but after resizing to mobile some of the elements on my page don't occupy the entire width of the screen(I am using a single column on mobile).
I have a 2 column layout on desktop, which changes to a single column layout for mobile with a media query, the problem occurs after the breakpoint for the media query. I have added "width=100%" to all of the elements that are impacted, as well as tried to turn on and off each style rule, such as margin and padding, individually in chrome developer tools. After several days I'm sure I am just missing whatever the problem is, or have a fundamental misunderstanding.
Screenshot of mobie layout issue
My HTML
<div class="wrapper">
<div class="intro-box">
<h1>Who am I, and where am I going?</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
</div>
<div class="bio-box">
<div class="photo-box">
<h2>Thanks for discovering more about me</h2>
<img src="davidSized.jpg" alt="David's Photo">
</div>
</div>
<div class="content-wrapper">
<h1>Learn about me here...</h1>
<div class="selector-one selector">
<h2>My Resume</h2>
</div>
<div class="selector-two selector">
<h2>About Me</h2>
</div>
<div class="selector-three selector">
<h2>More stuff</h2>
</div>
<div class="content">
<p class="para-one"></p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
</div>
<div class="contact-info-box">
<h3>Reach out to me here....</h3>
<ul class="contact-info">
<li>david_jhall#yahoo.com</li>
<li>LinkedIn Profile</li>
<li>Facebook Profile</li>
<li>More ways to contact me....</li>
</ul>
</div>
</div>
My meta tag
<meta name="viewport" content="width=device-width, initial-scale=1.0">
the wrapper element before the media query
wrapper{
display: grid;
grid-template-columns: 30% auto;
grid-template-rows: repeat(5 , auto);
grid-gap: 15px;
}
the wrapper element after the media query
.wrapper{
grid-template-columns: auto;
justify-content: center;
}
the elements that don't span the whole page on mobile (before the mq)
.intro-box{
grid-column: 1/3;
margin: 0px;
background: linear-gradient(rgba(0, 0, 0, 0.4), rgba(0, 0, 0, 0.1)),border-box,url("road.jpg") no-repeat center center;
background-size: cover;
color: lightgrey;
min-height: 750px;
max-width: 100%;
padding: 0;
}
.bio-box{
margin: 10px;
border: 5px solid rgba(0, 0, 0, 0.25);
text-align: center;
border-radius: 10%;
min-height: 500px;
}
.content-wrapper{
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-template-rows: auto auto 50%;
text-align: center;
min-height: 500px;
grid-gap: 5px;
max-width: 100%;
justify-content: center;
}
.content{
background: linear-gradient(rgba(0, 0, 0, 0.3), rgba(0, 0, 0, 0.1)),border-box;
grid-column: 1/-1;
}
mq and the elemnts within it
#media screen and (max-width:700px){
.wrapper{
grid-template-columns: auto;
justify-content: center;
}
.intro-box > h1{
font-size: 3em;
padding: 20px;
}
.bio-box{
grid-row: 3/4;
grid-column: 1/3;
}
.content-wrapper{
margin: 0 auto;
grid-column: 1/3;
justify-self: center;
}
.content{
padding: 20px;
margin: 0 auto;
margin-bottom: 50px;
width: 100%;
}
}
Remember that padding is internal to the border of the column, so makes little difference here. Also remeber that classes are gonna be your best friend with this sort of thing, simple change some CSS of the single class in a media query and add this class to each column you want to change for mobile. That way you reduce how much code you chuck into each MQ.
Firstly, as a quick-fix (but ideally not permanent) try adding in the MQ, this CSS:
.your-div-class {
width: 100%;
right: 0;
}
Also, disable your x-overflow (of the body) to avoid any nasty side-scrollbars!
See whether the ' right: 0; ' property helps bring it fully to the right.
Here's what I would do:
Give each column the same class of "responsive-col" or something, then pop this into an MQ, and style it like so:
#media screen and (max-width:700px){
.responsive-col {
margin: 0;
right: 0;
width: 100%;
font-size: 22px;
display: block;
}
}
There's loads to say, but this would hopefully solve it and if you have another question I'll just answer that.
Kieron
Related
Using the HTML and CSS below, you'll notice that rather than shrinking to fit the browser window, the site gets a horizontal scroll bar when shrunk down to 189px width. I've gone through my code and I cannot seem to figure out why this is happening. Keep in mind I'm a newbie so I might very well have overlooked something.
Also, I have a bonus question if that is allowed: I want to shrink the menu height but it seems impossible. How would you go about it?
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="index.css">
<title></title>
</head>
<body>
<div class="wrapper">
<div class="header">
<h1>Title</h1>
</div>
<div class="menu">
about <br>
contact <br>
donate <br>
</div>
<div class="pic">
<img src="roshi.jpg" alt="roshi">
</div>
<div class="content">
<h1>Article</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<h1>Article</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
<div class="content2">
<h1>Article</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<h1>Article</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
<div class="footer">
Footer
</div>
</div>
</body>
</html>
html body {
margin: 0 auto;
font-family: "Raleway", sans-serif;
}
.wrapper {
margin: 0 auto;
display: grid;
grid-gap: 10px;
grid-template-areas:
"header"
"menu"
"pic"
"content"
"content2"
"footer";
}
.header {
grid-area: header;
background-color: lightgrey;
}
.header h1 {
margin-left: 0;
padding-left: 0;
}
.menu {
grid-area: menu;
padding: 0;
line-height: 2;
}
.menu a {
text-decoration: none;
}
.menu a:link {
color: black;
}
.pic {
grid-area: pic;
}
img {
width: 100%;
height: auto;
}
.content {
grid-area: content;
}
.content2 {
grid-area: content2;
}
.footer {
grid-area: footer;
background-color: lightgrey;
}
.wrapper > * {
margin: 0px 30px;
}
.header, .footer {
padding: 0px 30px;
}
#media screen and (min-width: 500px) {
.wrapper {
display: grid;
grid-gap: 10px;
grid-template-rows: 1fr 1fr;
grid-template-areas:
"header header"
"menu menu"
"pic pic"
"content content2"
"footer footer";
}
.menu {
display: flex;
flex-direction: row;
margin-left: auto;
}
.menu a {
padding-right: 10px;
}
}
JSFiddle link: https://jsfiddle.net/tzrqf5np/
I fixed your CSS as you wanted. You really should start making sure you get your spacings right. it has no direct influence in HTML and CSS but helps reading and is a good practise for other languages. There plently languages where spacings make a difference if a code works or not. But having it easier to read espacially with programs like Visual Studio Code the advantage is that you see which closing tags belong to which starting tag.
Please try to practice it for me "my little padawan" :P
Ok One change of formatting was to the media query:
#media only screen
and ...
and ... {
body {
random-code: xy;
}
}
espacilly if you use media query to adress screens use only screen. Even it works nearly always take it as a good habit same as getting your spacings right. Then get a new line with and... what every you want to use. you can combine that way many rules like min-width and max-width, orientation: landscape/portrait screen format...
then you used: grid-template-rows: 1fr 1fr; I switched it to grid-template-columns: 1fr 1fr; and added the grid-auto-rows: auto; and tada: its working. The menu is way smaller just like you wanted.
Next the picture got a width of auto. that way it shouldnt create a horizontal scrollbar. a width of 100% will as it will add the 100% to the margin and paddings on top and then the width is wider then the screen.
html body {
margin: 0 auto;
font-family: "Raleway", sans-serif;
}
.wrapper {
margin: 0 auto;
display: grid;
grid-auto-rows: auto;
grid-gap: 10px;
grid-template-areas:
"header"
"menu"
"pic"
"content"
"content2"
"footer";
}
.header {
grid-area: header;
background-color: lightgrey;
}
.header h1 {
margin-left: 0;
padding-left: 0;
}
.menu {
grid-area: menu;
padding: 0;
}
.menu a {
text-decoration: none;
}
.menu a:link {
color: black;
}
.pic {
grid-area: pic;
}
img {
width: 100%;
height: auto;
}
.content {
grid-area: content;
}
.content2 {
grid-area: content2;
}
.footer {
grid-area: footer;
background-color: lightgrey;
}
.wrapper > * {
margin: 0px 30px;
}
.header, .footer {
padding: 0px 30px;
}
#media only screen
and (min-width: 500px) {
.wrapper {
display: grid;
grid-gap: 10px;
grid-template-columns: 1fr 1fr;
grid-auto-rows: auto;
grid-template-areas:
"header header"
"menu menu"
"pic pic"
"content content2"
"footer footer";
}
.menu {
display: flex;
flex-direction: row;
margin-left: auto;
}
.menu a {
padding-right: 10px;
}
}
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="index.css">
<title></title>
</head>
<body>
<div class="wrapper">
<div class="header">
<h1>Title</h1>
</div>
<div class="menu">
about<br>
contact<br>
donate
</div>
<div class="pic">
<img src="roshi.jpg" alt="roshi">
</div>
<div class="content">
<h1>Article</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<h1>Article</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
<div class="content2">
<h1>Article</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<h1>Article</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
<div class="footer">Footer</div>
</div>
</body>
</html>
I asked a similar question already but haven't found an answer. I am now at a different section of my website but have the the issue here as well. The code is super basic, so I am hoping this will help to solve the issue.
Some context: My front page is sectioned in 3 container divs, each of them with 100vh, so they should take up the entire screen, even when someone resizes the browser. The second div in the code below (.showcase) should stick to the bottom of the Container div (that's why I added position: absolute and bottom: 0).
My issue is now that the two divs in the Container div 1, keep overlapping when I reduce the browser height for example. But I want them to 'push' each other away from each other, basically not giving space for the other div to overlap. So that when I, for example, would add a padding to the two divs, that the padding still shows on the page even if resizing the browser. And no matter what I added (display: block, Flexbox, even putting the divs into a table etc) all of this didn't help and the content of the two divs keeps overlapping.
Can anyone help me here? I literally don't know how to go from here...
Here is the code:
.Container1 {
overflow: hidden;
height: 100vh;
width: 100%;
margin: 0;
background: rgb(74, 105, 113);
background: linear-gradient(90deg, rgba(74, 105, 113, 1) 0%, rgba(129, 161, 170, 1) 60%, rgba(181, 207, 214, 1) 100%);
text-align: center;
display: block;
}
.hp_slogan {
padding-top: 20%;
padding-bottom: 3%;
}
.showcase {
position: absolute;
bottom: 0;
display: block;
}
<div class="Container1">
<div class="hp_slogan">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
<div class="showcase">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
</div>
I believe this will solve your problem If I understood correctly what you need.
.Container1 {
overflow:hidden;
height: 100vh;
width: 100%;
margin: 0;
background: rgb(74,105,113);
background: linear-gradient(90deg, rgba(74,105,113,1) 0%, rgba(129,161,170,1) 60%, rgba(181,207,214,1) 100%);
text-align: center;
display: flex;
flex-direction:column;
}
.hp_slogan {
padding-top: 20%;
margin-bottom:20px;
padding-bottom: 3%;
}
.showcase {
bottom: 0;
}
You can simulate it in JSFiddle with this link
See if this works for you. Used flexbox to distance two divs
.Container1 {
display: flex;
flex-direction: column;
justify-content: space-around;
align-items: center;
overflow: hidden;
height: 100vh;
width: 100%;
margin: 0;
background: rgb(74, 105, 113);
background: linear-gradient(90deg, rgba(74, 105, 113, 1) 0%, rgba(129, 161, 170, 1) 60%, rgba(181, 207, 214, 1) 100%);
text-align: center;
}
<div class="Container1">
<div class="hp_slogan">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
<div class="showcase">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
</div>
I'm working on revamping an intranet page that was built years ago, and I'm trying to figure out the most effective CSS to properly lay out a page with the following requirements:
The page should occupy the full height and width of the viewport and should be responsive to resizing.
There should be a status bar that should always be visible at the bottom and should only be as tall as its contents.
If the user increases the font size, the status bar should properly adjust so the text isn't cut off.
If the content is taller than than the available screen height, scrollbars should appear in the content area to allow it to scroll (again, keeping the status bar visible).
Here's a mockup of the expected result:
As far as browser requirements go, this will ONLY be seen by a very specific group of users that will access it via Internet Explorer 11. No Chrome, no Firefox, no Edge - nothing except IE 11.
I've been experimenting with the "100vh" heights and flex, and I think I'm getting close but I'm just having some trouble getting everything the way I want. My current attempt looks like this:
body {
height: 96vh;
min-height: 96vh;
width: 95vw;
min-width: 95vw;
display: flex;
flex-direction: column;
}
#content
{
padding: 20px;
max-height: 95vh;
overflow:auto;
flex: 1 0 0;
}
#statusbar
{
background-color: #000;
color: #fff;
padding: 20px;
}
<div id="content">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
<footer id="statusbar">Status bar</footer>
I appreciate whatever help can be provided! Thanks in advance!
Here is a solution using display:flex where the footer has variable height and the content adjusts accordingly. The content area is set to overflow:auto in order to scroll if necessary.
html,
body {
height: 100%;
margin: 0
}
.box {
display: flex;
flex-flow: column;
height: 100%;
}
.box .row {
border: 1px dotted grey;
}
.box .row.footer {
flex: 0 1 auto;
}
.box .row.content {
flex: 1 1 auto;
overflow:auto;
}
<div class="box">
<div class="row content">
<p>
<b>content</b>
(fills remaining space)
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
some overflowing text
</p>
</div>
<div class="row footer">
<p><b>footer</b> (variable height)</p>
</div>
</div>
This question already has answers here:
Why don't flex items shrink past content size?
(5 answers)
Closed 5 years ago.
I'm trying to make a web page with a 'header' div of fixed height then a 'content' div below it. Within that content div are several different divs with actual page content in them. In the actual project, the height of all of these elements may vary between different screens and users as their content is mostly generated by PHP.
Sorry if that explanation is unclear, but the following demonstrates what I have got so far:
https://codepen.io/anon/pen/ZJPgWm
(the code is poorly formatted and some of the values look a bit wierd because I've just thrown this together quickly as an imitation of my actual project).
#main {
width: 90%;
min-width: 400px;
max-width: 1200px;
height: calc(100vh - 10px);
margin-left: auto;
margin-right: auto;
position: relative;
overflow: hidden;
display: flex;
flex-direction: column;
}
#head {
background-color: blue;
font-size: 3vh;
}
#content {
background-color: red;
flex-grow: 1;
display: flex;
}
#left {
width: calc(16% - 6px);
float: left;
background-color: green;
}
#inner {
font-size: 10vh;
flex-grow: 1;
width: calc(84% - 6px);
float: left;
margin-left: 8px;
margin-bottom: 10px;
flex-grow: 1;
overflow-x: hidden;
overflow-y: auto;
background-color: yellow;
}
<body>
<div id="main">
<div id="head">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
<div id="content">
<div id="left">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
<div id="inner">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
</div
</div>
</div>
</body>
On chrome, a scroll bar is shown within the #inner div. This is what I want.
On firefox and MS Edge, the overflowing content of the #inner div is just cut off, so it is impossible to see that content (without a taller screen).
I should note that the reason for this seems to be that, in chrome, the #inner and #content divs have their height controlled such that their bounding boxes don't go outside the boundary of the #main div. However, in firefox, their bounding boxes extend to below the bottom of the page (shown by developer tools).
What I am looking for is a method which will make all browsers give the result which is currently given by chrome. Ideally, an explanation of which browser is 'correct' and why they are different would also be helpful.
Note that I want to avoid using JS if at all possible. Any help or advice is appreciated.
Flex item's has a min-height that defaults to auto, which means it doesn't shrink below its content's size, so when you nest them like this and put the overflow: auto on a flex item's child, you need to let it know it is allowed to shrink.
Add min-height: 0; to your content rule and they will behave similar.
#main {
width: 90%;
min-width: 935px;
max-width: 1600px;
height: calc(100vh - 90px);
margin-left: auto;
margin-right: auto;
position: relative;
overflow: hidden;
display: flex;
flex-direction: column;
}
#head {
background-color: blue;
font-size: 20px;
}
#content {
background-color: red;
flex-grow: 1;
display: flex;
min-height: 0;
}
#inner {
font-size: 60px;
flex-grow: 1;
overflow-y: auto;
}
<body>
<header>
</header>
<div id="main">
<div id="head">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
<div id="content">
<div id="inner">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
</div </div>
</div>
</body>
I'm trying to understand how I should use display: grid.
Here is my example:
https://jsfiddle.net/Lycuuu95/
<style>
body {
padding: 2em;
}
.wrapper {
display: grid;
grid-template-columns: 30% 70%;
grid-gap: 10px;
}
.sidebar {
grid-column: 1;
padding: 10px;
background-color: rgb(191,217,155);
}
.content {
grid-column: 2;
padding: 10px;
background-color: rgb(230,230,220);
}
</style>
<h1>Lorem Ipsum</h1>
<div class="wrapper">
<aside class="sidebar"><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p></aside>
<article class="content"><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p></article>
</div>
At the first glance, it looks good. However, if you look more thoroughly, you can see some problems. The "content" is outside of "wrapper" and also the distance to the edges of screen is a bit different.
It could be fixed very simply:
/* Before: */
grid-template-columns: 30% 70%;
/* After: */
grid-template-columns: 30% 1fr;
But I am still wondering is it the only proper way or I can somehow use percents, without the problems as shown above? I already tried to use box-sizing: border-box but it does not solve the problem.
Note:
display: grid currently does not work out of the box in stable versions of browsers.
(See http://caniuse.com/#feat=css-grid)
It could be enabled with this quick instruction:
https://igalia.github.io/css-grid-layout/enable.html
Also, in Chrome Canary it works out of the box.
The other way to get your result is to use fr units for both columns, in your case 3fr and 7fr (that will end up with 30% of the free space for the first, and so on)
I have added a shadow to show that now everything is where it should.
body {
padding: 2em;
}
.wrapper {
display: grid;
grid-template-columns: 3fr 7fr; /* fix: 30% 1fr; */
grid-gap: 10px;
box-shadow: 0px 0px 2px 2px red;
}
.sidebar {
grid-column: 1;
padding: 10px;
background-color: rgb(191, 217, 155);
}
.content {
grid-column: 2;
padding: 10px;
background-color: rgb(230, 230, 220);
}
<h1>Lorem Ipsum</h1>
<div class="wrapper">
<aside class="sidebar">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</aside>
<article class="content">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</article>
</div>