I'm building my portfolio site, and I have okay understanding of HTML and CSS. Right now I'm creating a horizontal scrolling page design for the first time, and I'm a bit stuck in this scenario where I want to have the heading stay fixed to the screen but have the content scroll horizontally.
I used fixed position on the header, but when I want to make the page responsive, the heading will most likely fall onto two or more lines, but since it is fixed, it is not pushing the content beneath it away. How can I achieve that a fixed div can push other content away? Should I not use fixed position, or can I target the scrolling in a different way maybe?
Screenshot of text on one line
Screenshot of the issue where the heading is not pushing away the content but overlaps, as it is fixed
.sub-page {
padding-left: 40px;
padding-top: 40px;
flex-direction: column;
}
.sub-page h2 {
margin-bottom: 16px;
position: fixed;
}
.scrolling-wrapper {
display: flex;
width: 100%;
height: auto;
flex-wrap: nowrap;
-webkit-overflow-scrolling: touch;
}
<div class="container">
<div class="page sub-page">
<h2>Selected works</h2>
<div class="scrolling-wrapper">
<div class="list">
<a class="list-item"><h3>Card</h3></a>
<a class="list-item"><h3>Card</h3></a>
<a class="list-item"><h3>Card</h3></a>
<a class="list-item"><h3>Card</h3></a>
<a class="list-item"><h3>Card</h3></a>
<a class="list-item"><h3>Card</h3></a>
<a class="list-item"><h3>Card</h3></a>
<a class="list-item"><h3>Card</h3></a>
<a class="list-item"><h3>Card</h3></a>
<a class="list-item"><h3>Card</h3></a>
<a class="list-item"><h3>Card</h3></a>
</div>
</div>
</div>
I've used this JS code for the horizontal scrolling:
https://codepen.io/nachitz/pen/LXmGzN
So what I think is happening is that the scrolling is targeting the whole page?
To make it easier I've uploaded my site so you can see it in real-time: cdn.thevoyageofdesign.com/selected-works.html
You can use position: sticky in place of position fixed it will push other content away from your header.
.sub-page {
padding-left: 40px;
padding-top: 40px;
flex-direction: column;
}
.sub-page h2 {
margin-bottom: 16px;
position: sticky;
top: 0;
background-color: #fff;
}
.scrolling-wrapper {
display: flex;
width: 100%;
height: auto;
flex-wrap: nowrap;
-webkit-overflow-scrolling: touch;
}
<div class="container">
<div class="page sub-page">
<h2>Selected works</h2>
<div class="scrolling-wrapper">
<div class="list">
<a class="list-item"><h3>Card</h3></a>
<a class="list-item"><h3>Card</h3></a>
<a class="list-item"><h3>Card</h3></a>
<a class="list-item"><h3>Card</h3></a>
<a class="list-item"><h3>Card</h3></a>
<a class="list-item"><h3>Card</h3></a>
<a class="list-item"><h3>Card</h3></a>
<a class="list-item"><h3>Card</h3></a>
<a class="list-item"><h3>Card</h3></a>
<a class="list-item"><h3>Card</h3></a>
<a class="list-item"><h3>Card</h3></a>
</div>
</div>
</div>
</div>
Related
So I have a header with a navbar and some links like this.
When I hover on a link I have a border around it that looks like this.
Now only the HOME and CONTACT links are working and showing the cursors as a pointer and displaying the borders on hover but the other four aren't working or even showing a cursor to indicate that it's a link. How to fix this? Thanks.
Here's my header code:
<header>
<div class="navbar" id="navbar">
<div class="link" id="link">
HOME
</div>
<div class="link" id="link">
ABOUT
</div>
<div class="link" id="link">
OUR SERVICES
</div>
<div class="link" id="link">
PORTFOLIO
</div>
<div class="link" id="link">
CLIENT ALBUMS
</div>
<div class="link" id="link">
CONTACT
</div>
</div>
<div class="burger-menu">
<a href="javascript:void(0);" class="burger-style" id="showNavs">
<i class="fa fa-bars" style="color: black;"></i>
</a>
</div>
</header>
And here's my CSS:
#media screen and (min-width: 600px) {
header > .navbar {
display: flex;
justify-content: space-between;
align-items: center;
padding: 1em;
padding-top: 1.2em;
margin-left: 3em;
margin-right: 3em;
}
#link {
text-align: center;
margin-left: calc(5px + 1vw);
padding: .5em;
border: 2px solid white;
}
#link:hover {
transition: .5s;
border: 2px solid black;
padding-top: .5em;
padding-bottom: .5em;
padding-left: 2.5em;
padding-right: 2.5em;
}
}
It doesn't work even though I already changed from classes to ids.
Here's my Jquery code but I don't think this is really relevant for this problem.
$(document).ready(function() {
var navbar = $("#navbar")
var showNavs = $("#showNavs")
$("#showNavs").click(function() {
navbar.toggle("slow")
})
var form = $("#contact-form")
var firstName = form.find("#firstName")
var lastName = form.find("#lastName")
var textarea = form.find("#textarea")
form.submit(function(e) {
e.preventDefault();
firstName.val('')
lastName.val('')
textarea.val('')
})
var newsletterForm = $("#newsletter-form")
newsletterForm.submit(function(e) {
e.preventDefault();
$(this).find("#email").val('')
})
})
Here's a full demo of my site.
Wedding Planner Website
The links are working fine when the browser isn't resized.
To Change the cursor to a pointer when you hover over something element add The Following In Your Styles:
cursor: pointer;
this will work regardless of the element when a user hovers over the element.
If It Works Please Mark As Correct!
Kamestart
(If It Does Not Work Please Share Your Code And Write In The Comments. It Will Help A lot.)
Edit: It Wont Work. If You Want To Stay On The Same Fir Testing Purposes Use # in the href attr. if it is empty it will not be recognised as a link.
I suggest you wrap your div's with anchor tag so the whole box will be clickable and also I looked at your site, there's a class="text-container" which is overlapping your Navbar when the window is resized, hope you'll know the reason now.
.navbar{
display:flex;
justify-content: space-evenly;
}
<header>
<div class="navbar" id="navbar">
<a href="">
<div class="link" id="link">
HOME
</div>
</a>
<a href="#about">
<div class="link" id="link">
ABOUT
</div>
</a>
<a href="">
<div class="link" id="link">
OUR SERVICES
</div>
</a>
<a href="#gallery">
<div class="link" id="link">
PORTFOLIO
</div>
</a>
<a href="">
<div class="link" id="link">
CLIENT ALBUMS
</div>
</a>
<a href="#contact">
<div class="link" id="link">
CONTACT
</div>
</a>
</div>
<div class="burger-menu">
<a href="javascript:void(0);" class="burger-style" id="showNavs">
<i class="fa fa-bars" style="color: black;"></i>
</a>
</div>
heres the image of the error I tried several methods on how to align the footer at the bottom but I haven't found any solution what method should I use to solve the problem?
<footer>
<div class="container">
<nav class="footer-nav">
<ul>
<li>About us</li>
<li>Contact</li>
</ul>
</nav>
<nav class="footer-nav">
<ul>
<li>
<a href="#" class="social-link">
<img src="/img/iconmonstr-facebook-2.svg" alt="" />
Facebook
</a>
</li>
<li>
<a href="#" class="social-link">
<img src="/img/iconmonstr-instagram-11.svg" />
Instagram
</a>
</li>
</ul>
</nav>
</div>
</footer>
Add style to the footer element:
style="position:absolute; bottom:0px"
You can use position: absolute as recommended by avi,
But I generally recommend against absolute where possible.
This can be also solved using flexbox.
set the flex-direction to column,
and set flex: 1 on the main part which you want to take all space (generally you don't want the header and footer to expand)
html, body {
height: 100%;
margin: 0;
}
body {
display: flex;
flex-direction: column;
}
header {
background-color: red;
}
main {
flex: 1;
background-color: green;
}
footer {
background-color: blue;
}
<header>Header<</header>
<main>Main</main>
<footer>Footer</footer>
NOTE: you must set the body and html height to 100% in order for that to work.
https://jsfiddle.net/jszht5xp/19/
Below is my current header structure. The page (root) component is implied.
As you see social-links block's geometry is currently handled by the header__social-links mix (absolute position relative to the header).
How do I properly extract social-links to the global (page) scope making it an independent block (fixed position on the page)?
If I introduce the site or page block wrapping the header then I can apply page__social-links mix to solve that. Should header then be transformed into the page__header?
<body>
<header class="header hero" role="banner">
<img class="header__logo" src="assets/logo.png" alt="">
<div class="social-links header__social-links">
<a class="link social-links__link" href="#">
<svg class="social-links__icon">...</svg>
</a>
...
<a class="link social-links__link social-links__link--last" href="#">
<svg class="social-links__icon">...</svg>
</a>
</div>
<div class="navbar header__navbar">
<nav class="site-links navbar__site-links">
<a class="link site-links__link" href="#">1</a>
<a class="link site-links__link" href="#">2</a>
<a class="link site-links__link" href="#">3</a>
<a class="link site-links__link" href="#">4</a>
</nav>
</div>
</header>
...
</body>
You should separate the two scopes header and social-links as parent / child. It is important that BEM blocks are isolated. When using two classes from different blocks on the same elements, we risks future interference, and regression, when we will update one block without checking the other one.
The separation is also important to be able to move the social-links block.
// Show the fixed header on scroll
var fixedHeader = document.querySelector('.page__social-links');
document.addEventListener('scroll', function() {
if (window.scrollY > 100) {
fixedHeader.classList.remove('page__social-links--hidden');
} else {
fixedHeader.classList.add('page__social-links--hidden');
}
});
body {
margin: 0;
height: 300vh;
}
.page__social-links {
position: fixed;
top: 0;
left: 0;
right: 0;
background: hotpink;
}
/* Hide the fixed header by default */
.page__social-links--hidden {
display: none;
}
.header {
border-bottom: 1px solid hotpink;
}
.social-links {
text-align: center;
}
.social-links__link {
padding: 0 0.5em;
line-height: 3em;
}
<div class="page">
<div class="page__header">
<header class="header hero" role="banner">
<img class="header__logo" src="assets/logo.png" alt="" />
<div class="header__social-links">
<div class="social-links">
<a class="link social-links__link" href="#">
twitter
</a>
<a class="link social-links__link social-links__link--last" href="#">
facebook
</a>
</div>
</div>
</header>
</div>
<div class="page__social-links page__social-links--hidden">
<div class="social-links">
<a class="link social-links__link" href="#">
twitter
</a>
<a class="link social-links__link social-links__link--last" href="#">
facebook
</a>
</div>
</div>
</div>
Cheers,
Thomas.
My footer when full screen adds space to the right and when i use for example mobile view a chunk of my footer disappears. I just want it to stay at the bottom and not cover any content. Even when it shrinks to mobile view.
[![De red line is the extra space im talking about][1]][1]
#footer {
position: absolute;
left: 0;
bottom: 0 !important;
width: 100%;
height: 2.5rem;
padding-right: 0;
background-color: black;
border-top: 4px solid #F2D380;
overflow: auto;
}
#footer a {
color: white;
text-decoration: none;
}
<div id="footer">
<div class="row text-center justify-content-center">
<div class="col-lg-2 ">
Company Information
</div>
<div class="col-lg-2">
Privacy Policy and User Agreement
</div>
<div class="col-lg-2">
About
</div>
<div class="col-lg-2">
©2019 Copyright claim
</div>
<div class="col-lg-2">
<a href="#">
<img src="images/linkedin.png" class=" socialIcon">
</a>
<a href="#">
<img src="images/instagram.png" class=" socialIcon">
</a>
<a href="#">
<img src="images/facebook.png" class=" socialIcon">
</a>
<a href="#">
<img src="images/youtube.png" class="socialIcon">
</a>
</div>
</div>
</div>
So the issue of why the space is added and it covers content is because of the absolute positioning. If you do not want it to cover content you have a couple options. Set the content wrapper to a set height and the footer to the rest of that height so the footer stays visible at the bottom and wont cover content.
If you just want it to act as a footer and be at the bottom on mobile I would just set it to be position relative.
It is hard to envision what you are going for without other content on the page.
By specifying height: 2.5rem, you have given the footer a fixed height and it won't scale according to the content you have provided in it. Try height: auto, or height: max-content, because it seems your content is larger than the footer itself.
Also put margin: 0 to ensure no space is added around it
I'm trying to make this navigation bar to work without that "jumpy" effect on Safari.
It works ok on all other browsers.
The problem is that hovering on the links make the bar jumps down.
You can check the code here
http://jsfiddle.net/kpady8hr/14/
<nav class="top-menu">
<div class="divider first"></div>
<a href="#" class="product">
<span class="hover">Link1</span>
<span class="link">Link1</span>
</a>
<div class="divider"></div>
<a href="#" class="product">
<span class="hover">Link2</span>
<span class="link">Link2</span>
</a>
<div class="divider"></div>
<a href="#" class="product">
<span class="hover">Link3</span>
<span class="link">Link3</span>
</a>
<div class="divider last"></div>
</nav>
Any suggestions?
Thanks in advance :)
You need to style the links with vertical-align and compensate in the divider.
For example:
.top-menu .divider.first {
background-position: left center; /* change this */
}
.top-menu .product {
display: inline-block;
position: relative;
height: 22px;
overflow: hidden;
cursor: pointer;
font-size: 18px;
font-weight: 500;
vertical-align: bottom; /* add this */
}