Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed last month.
Improve this question
I am facing the problem with height 100vh , it gives vertical scrollbar.
I am embedding the external content in widger-holder div which has height 100vh. But content in widget-holder exceeds parent div and gives vertical scroll bar.
If I remove the fixed header, I am not seeing a vertical scroll bar. But I can't remove this.
And if I reduce the height in the widget-holder div, some content is not visual. So I am not able to reduce the height.
I need a solution to fit widget-holder content exactly with the parent height.
html {
--banner-menu-width: 250px;
--ps-facets-width: 280px;
--left-column-width: 349px;
--main-column-width: 890px;
--right-column-width: 0px;
}
* {
box-shadow: none;
margin: 0;
padding: 0;
border: 0;
}
body {
caret-color: #4181af;
font-size: 12px;
line-height: 142%;
margin: 0;
overflow-y: scroll;
background-color: #f3f3f4;
font-family: "open sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 13px;
height: 100%;
}
#app {
display: grid;
grid-template-columns: 0 250px auto;
grid-template-rows: auto;
}
#app-content {
background-color: #f3f3f4;
grid-column: 3;
display: grid;
grid-template-columns: 100%;
/* height: 100vh; */
}
#fixed-header {
display: grid;
grid-template-columns: 100%;
background-color: antiquewhite;
top: 0;
position: sticky;
z-index: 400;
height: 60px;
}
#app #dynamic-style {
visibility: hidden;
grid-column: 1;
}
#app #banner {
grid-column: 2;
grid-row-start: 1;
grid-row-end: -1;
min-height: 100vh;
max-height: 5000px;
display: flex;
justify-content: stretch;
position: fixed;
width: var(--banner-menu-width);
z-index: 450;
}
#app #banner .banner-background {
background: #223645;
z-index: 500;
align-self: stretch;
width: 100%;
}
.dashboard-container {
height: 100%;
}
.widget-holder {
display: flex;
flex-direction: column;
height: 100vh;
font-family: Arial, sans-serif;
background: aqua;
}
<div id="app" class="grid-container">
<div id="dynamic-style"></div>
<div id="banner">
<div class="banner-background"></div>
</div>
<div id="app-content" class="regular-workspace">
<div id="fixed-header"></div>
<div class="dashboard-container">
<div class="widget-holder"></div>
</div>
</div>
</div>
Is this what you're looking for?
I basically just subtracted the banner height from the screen height.
.dashboard-container {
height: calc(100vh - 60px);
}
.widget-holder {
display: flex;
flex-direction: column;
height: 100%;
font-family: Arial, sans-serif;
background: aqua;
}
You set your header sticky so that it occupies some space and change the top point of the page for the rest of its siblings. You can extract header's height from widget-holder's height.
.widget-holder {
display: flex;
flex-direction: column;
height: calc(100vh - 60px);
font-family: Arial, sans-serif;
background: aqua;
}
In my experiments this fixed the issue.
Or you can use Grid in the right way, like
#app-content {
background-color: #f3f3f4;
grid-column: 3;
display: grid;
grid-template-columns: 100%;
grid-template-rows: 60px 1fr;
height: 100vh;
}
.widget-holder {
display: flex;
flex-direction: column;
height: 100%;
font-family: Arial, sans-serif;
background: aqua;
}
Related
I want my fixed-position text to be visible no matter the background. I considered using mix-blend-mode or adding clipping mask to the text, which would be invisible on the website but visible only "through" the text, but I don't know how to do that. My mix-blend-mode doesn't seem to work either.
body {
font-family: 'Roboto', sans-serif;
overflow-x: hidden;
margin: 0;
}
.header {
display: flex;
justify-content: center;
align-items: center;
position: fixed;
width: 100vw;
top: 10vh;
z-index: 1;
mix-blend-mode: difference;
}
.fp-container-1 {
display: flex;
justify-content: center;
top: 0vh;
height: 100vh;
width: 100vw;
background-color: white;
}
.fp-container-2 {
display: flex;
justify-content: center;
top: 0vh;
height: 100vh;
width: 100vw;
background-color: blue;
}
<div class="blending-group">
<h1 class="header">Header</h1>
<div class="fp-container-1"></div>
<div class="fp-container-2"></div>
</div>
You need to set a background-color on the element you set the mix-blend-mode. Otherwise, the container will have a background-color of transparent by default and therefore have nothing against which to calculate the difference (or whatever mode you chose).
* {
margin: 0;
}
body {
font-family: 'Roboto', sans-serif;
}
.header {
position: fixed;
width: 100%;
top: 0;
mix-blend-mode: difference;
background: cadetblue;
}
.fp-container-1 {
height: 100vh;
}
.fp-container-2 {
height: 100vh;
background-color: cadetblue;
}
<div class="blending-group">
<h1 class="header">Header</h1>
<div class="fp-container-1"></div>
<div class="fp-container-2"></div>
</div>
Here is the JSfiddle complete code link:
CODE
my clock code output
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
body {
background: #0b172a;
font-family: sans-serif;
}
#container {
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
padding: 5rem;
color: white;
text-transform: uppercase;
}
.clock-ctr {
position: relative;
border: 2px solid white;
height: 80vh;
width: 80vw;
padding: 10px;
display: flex;
justify-content: center;
align-items: center;
}
.hour-ctr {
grid-area: hour;
}
.min-ctr {
grid-area: min;
}
.sec-ctr {
grid-area: sec;
}
.ampm {
grid-area: ampm;
background: #bc4123;
}
.time-ctr {
position: absolute;
height: 70%;
width: 90%;
display: grid;
grid-template-columns: 1fr 1fr 1fr;
grid-template-rows: auto;
gap: 10px;
grid-template-areas: "hour min sec" "ampm ampm ampm";
}
h1 {
margin-bottom: 1rem;
letter-spacing: 8px;
font-size: 2.5rem;
}
.time-box {
background: #bc4123;
border-radius: 10px;
display: grid;
justify-items: center;
align-items: center;
height: auto;
text-align: center;
font-weight: bold;
font-size: 28px;
}
<div id="container">
<h1 class="clock-title">Clock</h1>
<div class="clock-ctr">
<div class="time-ctr">
<div class="hour-ctr time-box">
<p class="hour-value">00</p>
<p class="hour-title">Hour</p>
</div>
<div class="min-ctr time-box">
<p class="min-value">00</p>
<p class="min-title">Minute</p>
</div>
<div class="sec-ctr time-box">
<p class="sec-value">00</p>
<p class="sec-title">Second</p>
</div>
<p class="ampm time-box">AM</p>
</div>
</div>
</div>
Can any one tell me how to improve this code
I tried to make is completely responsive but it is not not working,
I tired to use flex to make the element appear in center of page.
Then I use grid to create the clock layout and i didn't knew how to align the cells so I used grid again in them. I was using rem and em to make responsive code but it didn't work out well. please review my code.
This is because of the font-size of the time-box div that is not responsive (28px whatever the device size), To make it responsive I added media queries to change the font depending on the device width, As presented in this example:
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
body {
background: #0b172a;
font-family: sans-serif;
}
#container {
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
padding: 5rem;
color: white;
text-transform: uppercase;
}
.clock-ctr {
position: relative;
border: 2px solid white;
height: 80vh;
width: 80vw;
padding: 10px;
display: flex;
justify-content: center;
align-items: center;
}
.hour-ctr {
grid-area: hour;
}
.min-ctr {
grid-area: min;
}
.sec-ctr {
grid-area: sec;
}
.ampm {
grid-area: ampm;
background: #bc4123;
}
.time-ctr {
position: absolute;
height: 70%;
width: 90%;
display: grid;
grid-template-columns: 1fr 1fr 1fr;
grid-template-rows: auto;
gap: 10px;
grid-template-areas: "hour min sec" "ampm ampm ampm";
}
h1 {
margin-bottom: 1rem;
letter-spacing: 8px;
font-size: 2.5rem;
}
.time-box {
background: #bc4123;
border-radius: 10px;
display: grid;
justify-items: center;
align-items: center;
height: auto;
text-align: center;
font-weight: bold;
}
#media (min-width:768px) {
.time-box {
font-size: 18px;
}
}
#media (min-width:1024px) {
.time-box {
font-size: 22px;
}
}
#media (min-width:1280px) {
.time-box {
font-size: 28px;
}
}
<div id="container">
<h1 class="clock-title">Clock</h1>
<div class="clock-ctr">
<div class="time-ctr">
<div class="hour-ctr time-box">
<p class="hour-value">00</p>
<p class="hour-title">Hour</p>
</div>
<div class="min-ctr time-box">
<p class="min-value">00</p>
<p class="min-title">Minute</p>
</div>
<div class="sec-ctr time-box">
<p class="sec-value">00</p>
<p class="sec-title">Second</p>
</div>
<p class="ampm time-box">AM</p>
</div>
</div>
</div>
You can as well use calc() function, so you can calculate your font size relative to the screen width like this:
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
body {
background: #0b172a;
font-family: sans-serif;
}
#container {
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
padding: 5rem;
color: white;
text-transform: uppercase;
}
.clock-ctr {
position: relative;
border: 2px solid white;
height: 80vh;
width: 80vw;
padding: 10px;
display: flex;
justify-content: center;
align-items: center;
}
.hour-ctr {
grid-area: hour;
}
.min-ctr {
grid-area: min;
}
.sec-ctr {
grid-area: sec;
}
.ampm {
grid-area: ampm;
background: #bc4123;
}
.time-ctr {
position: absolute;
height: 70%;
width: 90%;
display: grid;
grid-template-columns: 1fr 1fr 1fr;
grid-template-rows: auto;
gap: 10px;
grid-template-areas: "hour min sec" "ampm ampm ampm";
}
h1 {
margin-bottom: 1rem;
letter-spacing: 8px;
font-size: 2.5rem;
}
.time-box {
background: #bc4123;
border-radius: 10px;
display: grid;
justify-items: center;
align-items: center;
height: auto;
text-align: center;
font-weight: bold;
font-size: calc(18px + 0.390625vw);
}
<div id="container">
<h1 class="clock-title">Clock</h1>
<div class="clock-ctr">
<div class="time-ctr">
<div class="hour-ctr time-box">
<p class="hour-value">00</p>
<p class="hour-title">Hour</p>
</div>
<div class="min-ctr time-box">
<p class="min-value">00</p>
<p class="min-title">Minute</p>
</div>
<div class="sec-ctr time-box">
<p class="sec-value">00</p>
<p class="sec-title">Second</p>
</div>
<p class="ampm time-box">AM</p>
</div>
</div>
</div>
the issue with the CSS code in the Stack Overflow question is that the left and right values for the #nav element are set to 0. This causes the element to take up the full width of its parent element, which is likely not the intended behavior.
To fix this issue, you can try setting the left and right values to auto like this:
#nav {
position: fixed;
top: 0;
left: auto;
right: auto;
width: 100%;
height: 60px;
background-color: white;
box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.2);
z-index: 1000;
}
With this change, the #nav element will no longer take up the full width of its parent element and will instead be positioned at the top of the page with its width set to 100%.
When I resize (shrink) the browser, the header elements will move onto the white space. I want them to stay within the blue background color regardless of resizing the browser.
body,
html {
height: 100vh;
}
body {
margin: 0;
display: grid;
grid-template-columns: 15%;
grid-template-rows: auto;
}
aside {
grid-row: 1 / 5;
background-color: blue;
}
.sidebar {
display: flex;
flex-direction: column;
text-align: center;
position: fixed;
margin-left: 0.5rem;
}
<aside>
<div class="sidebar">
<h3>Home</h3>
<h3>About</h3>
<h3>Recent Projects</h3>
</div>
</aside>
I edited your CSS, and I clarified the dimensions. Hopefully this works :)
body,
html {
height: 100vh;
}
body {
margin: 0;
display: grid;
grid-template-columns: 15%;
grid-template-rows: auto;
}
aside {
grid-row: 1 / 5;
background-color: blue;
width: 150px;
}
.sidebar {
display: flex;
flex-direction: column;
text-align: center;
position: fixed;
margin-left: 0.5rem;
}
.sidebar h3 {
width: 130px;
}
Don't use % as a value. Otherwise, it scales to that percentage.
ie; grid-template-columns: 15%; means 15% of the available window size.
You are best setting static widths as opposed to percentage widths.
You can have a width set on your aside CSS to override the percentage, example;
aside {
grid-row: 1 / 5;
background-color: blue;
width: 160px;
}
Use minmax() and remove the position:fixed
body,
html {
height: 100vh;
}
body {
margin: 0;
display: grid;
grid-template-columns: minmax(max-content,15%);
grid-template-rows: auto;
}
aside {
grid-row: 1 / 5;
background-color: blue;
}
.sidebar {
display: flex;
flex-direction: column;
text-align: center;
margin-left: 0.5rem;
}
<aside>
<div class="sidebar">
<h3>Home</h3>
<h3>About</h3>
<h3>Recent Projects</h3>
</div>
</aside>
For my #l-splash image, I'm having issues with the height: 100vh expanding past the viewpoint.
I have tried changing the overflow and different max-heights. I want my width to take up 100% of the left grid so it exactly takes up half of the screen. I suspect the problem is how my nav bar is stickied but I ideally need it to continue sticking to the top of the screen. Thanks for the help
https://jsfiddle.net/mtgcosxd/1/
header {
display: flex;
justify-content: center;
align-items: center;
flex-direction: row;
background: #fffaf0;
position: sticky;
width: 100%;
top: 0;
font-family: 'Montserrat', sans-serif;
/*font-family: 'Gotham-Light', gotham;*/
font-weight: 300;
font-size: 1vw;
}
body {
max-width: 100%;
overflow-x: hidden;
padding: 0px;
margin: 0px;
color: #fffaf0;
font-family: 'Work Sans', sans-serif;
font-weight: 300;
}
.nav {
position: -webkit-sticky;
position: sticky;
top: 0%;
color: #80985d;
}
.navLink {
padding: 0 10px;
font-weight: 300;
text-transform: uppercase;
cursor: pointer;
text-align: center;
}
#logo {
margin-top: 4px;
margin-bottom: 4px;
width: 4%;
height: 4%;
cursor: pointer;
}
.container {
display: grid;
grid-template-columns: [content] 1fr [images] 1fr
}
.content {
grid-column: content;
background: #2f6e84;
}
#l-splash {
width: 100%;
height: 100vh;
overflow: auto;
}
<div class="nav">
<header>
<div class="navLink" id="story-scroll">Our Story</div>
<div class="navLink" id="menu-scroll">Menu</div>
<img src="https://placekitten.com/200/300" id="logo" lt="logo">
<div class="navLink" id="press-scroll">Press</div>
<div class="navLink" id="contact-scroll">Contact</div>
</header>
</div>
<div class="container">
<div class="content">
<div id="splash container">
<img id="l-splash" src="https://images.unsplash.com/photo-1526069631228-723c945bea6b?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=934&q=80">
</div>
You don't need to set height: 100vh on the image - as you are already having flexboxes and grids in your layout, you can inherit the heights using a column flexbox wrapper on body- here are the changes:
made you body a column flexbox and gave 100vh height,
allow the container to fill the remaining space left by the nav using flex: 1 on the container,
add height: 100% to the container of the img,
fill the image in its container using height: 100% and using object-fit,
body {
max-width: 100%;
overflow-x: hidden;
padding: 0px;
margin: 0px;
color: #fffaf0;
font-family: 'Work Sans', sans-serif;
font-weight: 300;
/* made a flexbox */
display: flex;
flex-direction: column;
height: 100vh; /* full-height */
}
header {
display: flex;
justify-content: center;
align-items: center;
flex-direction: row;
background: #fffaf0;
position: sticky;
width: 100%;
top: 0;
font-family: 'Montserrat', sans-serif;
/*font-family: 'Gotham-Light', gotham;*/
font-weight: 300;
font-size: 1vw;
}
.nav {
position: -webkit-sticky;
position: sticky;
top: 0%;
color: #80985d;
}
.navLink {
padding: 0 10px;
font-weight: 300;
text-transform: uppercase;
cursor: pointer;
text-align: center;
}
#logo {
margin-top: 4px;
margin-bottom: 4px;
width: 4%;
height: 4%;
cursor: pointer;
}
.container {
display: grid;
grid-template-columns: [content] 1fr [images] 1fr;
flex: 1; /* added */
}
.content {
grid-column: content;
background: #2f6e84;
}
.content > div {
height: 100%; /* added */
}
#l-splash {
width: 100%;
/*height: 100vh;*/
height: 100%;
object-fit: cover; /* added */
overflow: auto;
display: block; /* remove inline element whitespace */
}
<div class="nav">
<header>
<div class="navLink" id="story-scroll">Our Story</div>
<div class="navLink" id="menu-scroll">Menu</div>
<img src="https://placekitten.com/200/300" id="logo" lt="logo">
<div class="navLink" id="press-scroll">Press</div>
<div class="navLink" id="contact-scroll">Contact</div>
</header>
</div>
<div class="container">
<div class="content">
<div id="splash container">
<img id="l-splash" src="https://images.unsplash.com/photo-1526069631228-723c945bea6b?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=934&q=80">
</div>
But you still have overflow - what now?
Add min-height: 0 to container so that you override the default min-height: auto for flex items in column direction,
You can see some examples of why you need to do this below:
Flexbox affects overflow-wrap behavior
Flexbox resize and scrollable overflow
Why don't flex items shrink past content size?
Similarly min-height: auto for a grid item can be overridden using min-height: 0 on the content element
You can see some examples of why you need to do this below:
css-grid creates an imaginary column
How to make images stay within the rows of a css grid container?
See demo below:
body {
max-width: 100%;
overflow-x: hidden;
padding: 0px;
margin: 0px;
color: #fffaf0;
font-family: 'Work Sans', sans-serif;
font-weight: 300;
/* made a flexbox */
display: flex;
flex-direction: column;
height: 100vh; /* full-height */
}
header {
display: flex;
justify-content: center;
align-items: center;
flex-direction: row;
background: #fffaf0;
position: sticky;
width: 100%;
top: 0;
font-family: 'Montserrat', sans-serif;
/*font-family: 'Gotham-Light', gotham;*/
font-weight: 300;
font-size: 1vw;
}
.nav {
position: -webkit-sticky;
position: sticky;
top: 0%;
color: #80985d;
}
.navLink {
padding: 0 10px;
font-weight: 300;
text-transform: uppercase;
cursor: pointer;
text-align: center;
}
#logo {
margin-top: 4px;
margin-bottom: 4px;
width: 4%;
height: 4%;
cursor: pointer;
}
.container {
display: grid;
grid-template-columns: [content] 1fr [images] 1fr;
flex: 1; /* added */
min-height: 0; /* added */
}
.content {
grid-column: content;
background: #2f6e84;
min-height: 0; /* added */
}
.content > div {
height: 100%; /* added */
}
#l-splash {
width: 100%;
/*height: 100vh;*/
height: 100%;
object-fit: cover; /* added */
overflow: auto;
display: block; /* remove inline element whitespace */
}
<div class="nav">
<header>
<div class="navLink" id="story-scroll">Our Story</div>
<div class="navLink" id="menu-scroll">Menu</div>
<img src="https://placekitten.com/200/300" id="logo" lt="logo">
<div class="navLink" id="press-scroll">Press</div>
<div class="navLink" id="contact-scroll">Contact</div>
</header>
</div>
<div class="container">
<div class="content">
<div id="splash container">
<img id="l-splash" src="https://images.unsplash.com/photo-1526069631228-723c945bea6b?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=934&q=80">
</div>
You can subtract the height of the nav/header from the height of the #l-splash div. E.g.
header {
...
height: 50px;
max-height: 50px;
}
#l-splash {
...
height: calc(100vh - 50px);
}
If your nav or other divs have margins, you may need to include those in your height calculation. E.g.
header {
...
height: 50px;
margin-bottom: 5px;
}
#l-splash {
...
height: calc(100vh - 55px);
}
I have a simple page layout with a vertical centered content box using flex.
I use min-height: 70vh; to stretch the container height to allow the content-box to vertical center.
I also have a footer which height gap is stretched to the bottom of the page using flex: 1;.
https://jsfiddle.net/Lvod41L2/
Problem
If the content-box has enough content that makes it taller than the page the footer is not pushed to the bottom and scrolls with the page. Example: height: 2000px;
If I remove min-height: 70vh; the footer is pushed to the bottom of the page as it should look.
HTML/CSS
<!DOCTYPE html>
<html>
<head>
<style>
html, body {
height: 100%;
margin: 0;
padding: 0;
}
body {
display: flex;
flex-direction: column;
}
.header {
min-height: 40px;
padding: 0.8em 2em;
background: black;
color: white;
}
.flex-container {
display: flex;
align-items: center;
min-height: 70vh;
padding: 2em;
background: gray;
}
.content-box {
width: 300px;
height: 300px;
margin: auto;
padding: 2em;
text-align: center;
background: black;
color: white;
}
.footer {
z-index: 100;
position: relative;
flex: 1;
padding: 2em;
background: black;
color: white;
}
</style>
</head>
<body>
<div class="header">
Header
</div>
<div class="flex-container">
<div class="content-box">
Content Box
</div>
</div>
<div class="footer">
Footer
</div>
</body>
</html>
SOLUTION - JSFIDDLE
Add flex: 0 0 auto; to the container
.flex-container {
display: flex;
align-items: center;
min-height: 70vh;
padding: 2em;
background: gray;
flex: 0 0 auto; /* Added rule */
}
I hope that solves the issue.