Vertical and Horizontal Scrolling Website - html

I am working on a website (one pager) which is built after a cross. The vertical scroll works well and is solved with CSS (scroll-snap-type etc.) The problem is in the horizontal scroll and namely the problem is that if you scroll horizontally and then scroll vertically logically comes a blank page. How to solve this problem best (as explained in the sketch (arrow 1)) that the page info is called. Every "page" has a vh 100. The vertical Scroll is with vh 100 and vw200 (2 Pages)
EDIT: If you run the code snipped you can see, that if you use the horizontal slide the second slide is blocked if you scroll down. This is my Problem. I want to jump to the site infos / (subscription-container)
*{
margin: 0px;
padding: 0px;
box-sizing: border-box;
color: white;
}
h1{
font-weight: normal;
}
#font-face {
font-family: 'besom_extendedregular';
src: url('../src/webfonts/besom-extended-webfont.woff2') format('woff2'),
url('../src/webfonts/besom-extended-webfont.woff') format('woff');
font-weight: normal;
font-style: normal;
}
.main-container{
scroll-snap-type: y mandatory;
overflow-y: scroll;
overflow-x: hidden;
height: 100vh;
scroll-behavior: smooth;
}
.navi{
position: fixed;
}
.hero{
height: 100vh;
background-color: beige;
background-position: center;
background-size: cover;
scroll-snap-align: start;
}
.logo-section{
justify-content: center;
display: flex;
padding: 150px;
/* height: 100vh; */
}
.logo-section img{
/* position: absolute; */
max-width: 70%;
max-height: 270px;
}
.content-container{
height: 100vh;
width: 400vw;
background-color: black;
scroll-snap-align: start;
flex-direction: row;
display: flex;
}
.content-container .first{
width: 100vw;
height: 100vh;
display: flex;
justify-content: space-between;
align-items: center;
padding: 0 8em;
background-color: brown;
}
.content-container .story{
width: 100vw;
height: 100vh;
display: flex;
justify-content: space-between;
align-items: center;
padding: 0 8em;
background-color: red;
}
.subscription-container{
height: 100vh;
background-color: black;
scroll-snap-align: start;
padding-top: 80px;
padding-left: 150px;
padding-right: 150px;
}
.bottom-container{
height: 100vh;
background-color: black;
scroll-snap-align: start;
padding-top: 80px;
}
.footer-nav-main{
float: left;
display: flex;
list-style-type: none;
font-family: Arial, Helvetica, sans-serif;
font-style: italic;
margin-left: 35px;
margin-right: 35px;
}
.footer-main{
margin-top: 80vh;
}
<div class="main-container">
<section class="hero">
<div class="logo-section">
<img class="logo" src="" alt="Logo">
</div>
<div class="announcement-head">
<p>
Title
</p>
</div>
<div class="announcement-text">
<p>
Subtitle
</p>
</div>
</section>
<div id="content-container" class="content-container">
<section id="first" class="first">
<div>
<h1>First</h1>
Story
</div>
</section>
<section id="story" class="story">
<div>
<h1>Story 1</h1>
First
</div>
</section>
</div>
<section class="subscription-container">
<div class="main-head">
<h1>Dream with us !</h1>
</div>
<div class="main-text">
<p>
text section
</p>
</div>
</section>
<section class="bottom-container">
<div><h1>Bottom Container</h1></div>
<div class="footer-main">
<ul class="footer-nav-main">
<li>Foot1</li>
<p>/</p>
<li>Foot2</li>
<p>/</p>
<li>Foot3</li>
</ul>
<p class="bottom-text-copyright">© </p>
</div>
</section>
</div>

to block horizontally scrolling you can use overflow-y css property.add this code into your css file:
.body{
overflow-y: hidden;
overflow-x: auto;
}
this code automaticly removes horizontal scrool bar.

Related

Display Flex Items Align Center

I am trying to make it so the second section or the first section will align center with the top.
What I don't understand is the relationship between items with display flex vs items that have display block.
First Question: Is there a way with flex so the top logo doesn't look "off" center compared to the centered text in the second section?
Link To Pen: https://codepen.io/skella1/pen/vYZLdVN
<div class="header">
<img src="https://via.placeholder.com/100x50" alt="">
<p>Text Goes Here</p>
</div>
<div class="secHeader">
<h1>Welcome</h1>
<p>This is a page to login</p>
</div>
<div class="content">
<div class="login">
<p style="padding-right: 10px;">Login</p>
<input type="text">
<button>Login</button>
</div>
</div>
body {
margin: 0px;
padding: 0px;
}
.header {
height: 50px;
display: flex;
justify-content: space-between;
align-items: center;
padding: 0px;
img {
margin: 0 auto;
}
}
.secHeader {
background-color: #ddd;
text-align: center;
display: block;
line-height: 0px;
padding: 20px;
h1 {
text-transform: uppercase;
font-weight: 900;
}
}
.content{
background: url("http://www.placebear.com/500/300") center center no-repeat;
background-size: cover;
width: 100%;
height: 100vh;
position: relative;
.login {
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0px;
justify-content: center;
flex-direction: row;
align-items: center;
display: flex;
}
}
Center the image using justify-content: center on the flex parent element and then set the P elements position to absolute and position it using the top/right properties.
Right now you have two elements that are taking up space in the flex parent elements width. The image and the P tags content. Using justify-content: space-between will place the remainder of the width the elements do not use, between them. In turn skewing the look of the image from being in the center regardless of your margin set to 0 auto, as that only places it in the center of the space it takes up from the parent.
body {
margin: 0px;
padding: 0px;
}
.header {
height: 50px;
display: flex;
justify-content: center;
align-items: center;
padding: 0px;
}
.header p {
position: absolute;
top: 0;
right: 20px;
}
.secHeader {
background-color: #ddd;
text-align: center;
display: block;
line-height: 0px;
padding: 20px;
}
.secHeader h1 {
text-transform: uppercase;
font-weight: 900;
}
.content {
background: url("http://www.placebear.com/500/300") center center no-repeat;
background-size: cover;
width: 100%;
height: 100vh;
position: relative;
}
.content .login {
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0px;
justify-content: center;
flex-direction: row;
align-items: center;
display: flex;
}
<div class="header">
<img src="https://via.placeholder.com/100x50" alt="">
<p>Text Goes Here</p>
</div>
<div class="secHeader">
<h1>Welcome</h1>
<p>This is a page to login</p>
</div>
<div class="content">
<div class="login">
<p style="padding-right: 10px;">Login</p>
<input type="text">
<button>Login</button>
</div>
</div>
Answer to Question 1) A really quick fix to this was using the transform property in CSS to center the image with respect to the current position
Answer to Question 2) Simply set the max-width property on the .content class to prevent the scrolling you talked about
body {
margin: 0px;
padding: 0px;
}
.header {
height: 50px;
width:100%;
display: flex;
justify-content: space-around;
align-items: center;
padding: 0px;
img {
margin: 0 auto;
transform:translate(50%,0%); /* MODIFIED CODE HERE */
}
}
.secHeader {
background-color: #ddd;
text-align: center;
display: block;
line-height: 0px;
padding: 20px;
h1 {
text-transform: uppercase;
font-weight: 900;
}
}
.content{
background: url("http://www.placebear.com/500/300") center center no-repeat;
background-size: cover;
height: 100vh;
max-width:100vw; /* MODIFIED CODE HERE */
position: relative;
.login {
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0px;
justify-content: center;
flex-direction: row;
align-items: center;
display: flex;
}
}
If you're insisting on using flexbox for the header, what you can do is the following:
<div class="header">
<div>
</div>
<div class="text-center">
<img src="https://via.placeholder.com/100x50" alt="">
</div>
<div class="text-right">
<p>Text Goes Here</p>
</div>
</div>
.header {
height: 50px;
display:flex;
padding: 0px;
justify-content: space-between;
div {
flex:1;
}
div.text-center {
text-align:center;
}
div.text-right{
text-align:right;
}
}
Please note that this is just a workaround, flexbox is not the only solution here. You might use position:absolute for this.

CSS half page sticky half scroll not working correctly

I am trying to recreate this layout but for some reason my code won't work correctly. The image sticks for a second but then continues to scroll like a normal webpage. I have tried to recreate the website but with multiple sticky images as you scroll down. One problem is that instead of the text scrolling, it now overflows:
This is my code:
section {
display: flex;
flex-direction: row;
}
section:nth-child(even) {
flex-direction: row-reverse;
}
section div.sectionText {
width: 50%;
height: 100vh;
vertical-align: middle;
margin: auto;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
padding: 1em;
}
.sectionContainer {
height: 100vh;
}
section div.stickyContainer {
height: 92vh;
background-color: lavender;
background-size: cover;
background-position: center;
position: sticky;
position: -webkit-sticky;
top: 8vh;
width: 50vw;
margin: 0;
display: flex;
justify-content: center;
align-items: center;
}
section div.img-2 {
background-color: lavenderblush;
}
.stickyImg {
width: 90%;
height: auto;
display: block;
margin-right: auto;
margin-left: auto;
margin: auto;
vertical-align: middle;
border-radius: 30px;
}
.title {
font-size: 2em;
padding-bottom: 2vw;
}
.subtitle {
font-size: 17px;
padding-top: 0.5em;
text-align: center;
padding-bottom: 10vh;
}
<section>
<div class="sectionText" style="margin-top: 8vh; height: 92vh;">
<p class="title bold">Title Page</p>
</div>
<div class="stickyContainer">
<img src="MainImgCrop.jpeg" class="stickyImg" />
</div>
</section>
<section>
<div class="sectionText">
Lorem ipsum dolor sit amet...
</div>
<div class="stickyContainer img-2"></div>
</section>
Any help would be appreciated, thank you.
So I have found my error by commenting lines of the code and seeing what is affected. I originally had height: 100vh; in section div.sectionText but removing this fixes it completely.

One element inside <div> is much wider than the others while using flex. How can I make the separation even?

I'm learning how to create a website using flexbox and I'm having some trouble creating a header.
Basically, one <a> element that wraps around an <img> element takes up much more width than the other elements even though the picture itself isn't nearly as wide.
This is what it looks like: https://i.imgur.com/nEpI4xW.png
Here is my HTML code:
<body>
<div class="main-container">
<div class="header">
Home
Order
<img src="./images/logo.svg" alt="logo">
Checkout
Contact us
</div>
<div class="flowers-inventory">
Flowers Inventory
</div>
<div class="tools-inventory">
Tools Inventory
</div>
<div class="footer">
Footer
</div>
</div>
Here is the CSS code:
*{
margin: 0;
padding: 0;
box-sizing: border-box;
}
.main-container{
min-height: 100vh;
display: flex;
flex-direction: column;
}
.header{
display: flex;
background-color: #f4f4f4;
align-items: center;
text-align: center;
justify-content: space-evenly;
flex-wrap: nowrap;
}
.header a{
white-space: nowrap;
text-decoration: none;
font-family: Roboto;
text-transform: uppercase;
font-size: 16px;
color: rgb(224, 170, 205);
}
.header img{
width: 22%;
}
.header .logo{
margin: 0 -40em;
}
You can use flex: 1 0 0; in your flex-items (here: .header a selector)
*{
margin: 0;
padding: 0;
box-sizing: border-box;
}
.main-container{
min-height: 100vh;
display: flex;
flex-direction: column;
}
.header{
display: flex;
background-color: #f4f4f4;
align-items: center;
text-align: center;
justify-content: space-evenly;
flex-wrap: nowrap;
}
.header a{
white-space: nowrap;
text-decoration: none;
font-family: Roboto;
text-transform: uppercase;
font-size: 16px;
flex: 1 0 0;
color: rgb(224, 170, 205);
}
.header img{
width: 22%;
}
.header .logo{
margin: 0 -40em;
}
<body>
<div class="main-container">
<div class="header">
Home
Order
<img src="https://cdn.clipart.email/2a1b0b49218f3d58c2b6df1630b609d9_free-rectangle-cliparts-download-free-clip-art-free-clip-art-on-_618-361.jpeg" alt="logo">
Checkout
Contact us
</div>
<div class="flowers-inventory">
Flowers Inventory
</div>
<div class="tools-inventory">
Tools Inventory
</div>
<div class="footer">
Footer
</div>
</div>

Flexbox grow div to take up remaining height

versions of this have been asked before and these questions helped me so far as to have a flex item that grows in height. However, it grows too much :)
Please see the code pen or the code here
https://codepen.io/surf-n-code/pen/wvwrbKW
Basically I have this Code
html,
body {
height: 100%;
}
.container {
height: 100%;
min-height: 100%;
display: flex;
flex-direction: column;
}
.box {
text-align: center;
color: white;
font-family: sans-serif;
font-size: 36px;
padding: 20px;
display: flex;
flex-direction: column;
justify-content: center;
}
.box-1 {
background-color: green;
height: 60px;
}
.box-2 {
background-color: blue;
flex: 1;
}
.box-3 {
background-color: red;
height: 60px;
}
<body>
<header>
<div class="box box-0">Header - sticks to top</div>
</header>
<main class="full-height">
<div class="nd_container">
<div class="box box-1">content</div>
<div class="box box-2">Flex grow</div>
</div>
</main>
<footer>
<div class="box box-4">Footer - stick to bottom</div>
</footer>
</body>
I would expect the box-2 to increase in size just enough such that the footer sticks exactly to the bottom of the page. I do not want any scrolling due to the created whitespace.
Any help is much appreciated :)
I hope this is what you expecting check out my answer.
NOTE:CHECK OUT MY ANSWER IN FULL SCREEN MODE
box-2 to increase in size just enough such that the footer sticks exactly to the bottom of the page.
html,
body {
height: 100%;
margin: 0;
height: 100vh;
display: flex;
flex-flow: column;
}
.nd_container {
height: 100%;
min-height: 100%;
display: flex;
flex-flow: column;
}
.nd_container .box {
text-align: center;
color: white;
font-family: sans-serif;
font-size: 36px;
padding: 20px;
justify-content: center;
}
.nd_container .box-1 {
background-color: green;
flex: 0 1 60px;
}
.nd_container .box-2 {
background-color: red;
flex: 1 1 auto;
}
.box {
text-align: center;
color: white;
font-family: sans-serif;
font-size: 36px;
display: flex;
flex-direction: column;
justify-content: center;
}
.box.box-0 {
background-color: #03a9f4;
height: 100%;
}
.box.box-4 {
background-color: #0c5460;
height: 100%;
}
header {
flex: 0 1 155px;
}
main {
flex: 1 1 auto;
}
footer {
flex: 0 1 155px;
}
<body>
<header>
<div class="box box-0">Header - sticks to top</div>
</header>
<main class="full-height">
<div class="nd_container">
<div class="box box-1">content</div>
<div class="box box-2">Flex grow</div>
</div>
</main>
<footer>
<div class="box box-4">Footer - stick to bottom</div>
</footer>
</body>

Prevent flexbox items from overflowing into siblings

I am trying to make a one-pager site, which is working quite well. I have three sections that need to be fullscreen, that works. But when I resize the window to 500px width and make the height also shorter, the title from the second page comes up on the first page. Same thing happens with the title on the third page, this one displays on the second page.
Here is the codepen: http://codepen.io/anon/pen/jWaxMK
HTML:
<section>
<h2>Title 1</h2>
<div class="box">
</div>
<div class="box">
</div>
</section>
<section>
<h2 class="blue">Title 2</h2>
<div class="box circle"></div>
<div class="box circle"></div>
<div class="box circle"></div>
</section>
<section>
<h2 class="white">Title 3</h2>
</section>
CSS:
html,
body,main {
height: 100%;
margin: 0;
padding: 0;
}
section {
position: relative;
width: 100%;
height: 100%;
color: #ececec;
text-align: center;
display: flex; /* default: row nowrap */
flex-flow:row wrap;
justify-content: center;
align-items: center;
align-content: center;
}
section:nth-child(1) {
background: #06a2cb;
}
section:nth-child(2) {
background: #ececec;
}
section:nth-child(3) {
background: #F5E5D8;
}
h2{
margin-top:0;
font-family: 'Lobster';
margin: 1em;
flex: 0 0 100%;
color: black;
}
.box{
width: 250px;
height: 250px;
display: inline-block;
background-color: #ececec;
border-radius: 10px;
flex: 0 0 250px;
}
.circle{
border-radius: 50%;
background-color: white;
}
Any help is appreciated, thanks!
You can solve the problem by making all the section elements flex items, and giving them a minimum height.
Add this to your CSS:
body {
display: flex;
flex-direction: column;
}
section {
min-height: 100%; /* alternatively, try `min-height: 100vh` */
flex-shrink: 0;
}
Revised Codepen