I'm working on a project in React and ran into a problem that has me stumped.
I want to add footer component but its not working properly.
so here is my code and i am not able to figure out how to keep footer at bottom of my page when ever i scroll down.
if any one have some solution it will be really great if you help me
when i load my page footer componet look like this at bottom of my page
but when i scroll up then it look like this
i am wirting this code in different page (footer.jsx) with footer.module.css and calling in my app.js
Footer.jsx
import React from "react";
import footerStyles from "../styles/Footer.module.css";
import { FaTwitter, FaFacebook, FaInstagram } from "react-icons/fa";
function Footer() {
return (
<div id={footerStyles.copyright}>
<p>
© Team NexT LeVeL. All rights reserved. | Design by Team NexT
LeVeL
</p>
<ul className={footerStyles.contact}>
<li>
<a href="/#">
<FaTwitter size="2em" color="cyan" />
</a>
</li>
<li>
<a href="/#">
<FaFacebook size="2em" color="#00acee" />
</a>
</li>
<li>
<a href="/#">
<FaInstagram size="2em" className={footerStyles.insta} />
</a>
</li>
</ul>
</div>
);
}
export default Footer;
my footer.module.css look like this
#copyright {
margin: 0;
width: 100%;
border-top: 20px solid rgba(255, 255, 255, 0.08);
text-align: center;
background: #333333;
position: absolute;
left: 0;
bottom: 0;
right: 0;
bottom: 0;
display: flex;
flex-wrap: wrap;
justify-content: space-evenly;
flex: 0 0 25%;
}
#copyright p {
display: inline;
letter-spacing: 1px;
font-size: 16px;
color: white;
}
#copyright a {
text-decoration: none;
color: white;
}
/*footer icon*/
ul.contact {
list-style: none;
}
ul.contact li {
display: inline;
font-size: 1em;
padding: 10px;
}
ul.contact li span {
margin: 20px;
}
ul.contact li a {
color: white;
}
ul.contact li a:before {
display: inline;
background: #4c93b9;
line-height: 40px;
text-align: center;
color: rgba(255, 255, 255, 1);
}
.insta {
border-radius: 10px;
background: radial-gradient(
circle at 30% 107%,
#fdf497 0%,
#fdf497 5%,
#fd5949 45%,
#d6249f 60%,
#285aeb 90%
);
}
Try using
position: fixed;
instead of
position: absolute;
Also, I would suggest floating the element to make sure that the rest of the page isn't moving out of it's way incorrectly:
float: left;
And then add a padding to the bottom of your body tag with a height taller than your footer, to ensure you don't totally cover anything up
body {
padding-bottom: 100px;
}
Follow this structure.
const App = () => (
<div style={{paddingBottom: 50}}>
<p>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Voluptas, molestiae. Magni quibusdam doloremque optio rerum ex assumenda mollitia suscipit praesentium, exercitationem ea perspiciatis aut, voluptatum necessitatibus numquam totam. Commodi distinctio nisi non? Voluptas exercitationem nemo aut rem sint? Recusandae nam quisquam maiores sapiente ratione deleniti, corrupti impedit laboriosam voluptatibus repudiandae qui cumque voluptatem labore necessitatibus sed quidem nemo cum, vitae consequatur rem corporis quibusdam non voluptates quia. Amet ipsum ex, dolore quaerat omnis animi placeat totam alias suscipit eveniet voluptate doloremque nisi repellendus sit incidunt, voluptates ratione ea autem esse maiores, qui quasi? Possimus, velit quibusdam! Natus accusantium voluptatem asperiores.Lorem ipsum dolor, sit amet consectetur adipisicing elit. Voluptas, molestiae. Magni quibusdam doloremque optio rerum ex assumenda mollitia suscipit praesentium, exercitationem ea perspiciatis aut, voluptatum necessitatibus numquam totam. Commodi distinctio nisi non? Voluptas exercitationem nemo aut rem sint? Recusandae nam quisquam maiores sapiente ratione deleniti, corrupti impedit laboriosam voluptatibus repudiandae qui cumque voluptatem labore necessitatibus sed quidem nemo cum, vitae consequatur rem corporis quibusdam non voluptates quia. Amet ipsum ex, dolore quaerat omnis animi placeat totam alias suscipit eveniet voluptate doloremque nisi repellendus sit incidunt, voluptates ratione ea autem esse maiores, qui quasi? Possimus, velit quibusdam! Natus accusantium voluptatem asperiores.
</p>
<Footer/>
</div>
)
function Footer() {
return (
<div style={{
display:"flex",
position:"fixed",
width:"100%",
height: 50,
backgroundColor: "grey",
bottom: 0,
}}>
<p>
© Team NexT LeVeL. All rights reserved. | Design by Team NexTLeVeL
</p>
<ul style={{display:"flex"}}>
<li>
<a href="/#">
Twitter
</a>
</li>
<li>
<a href="/#">
Facebook
</a>
</li>
<li>
<a href="/#">
Instagram
</a>
</li>
</ul>
</div>
);
}
ReactDOM.render(<App />, document.getElementById("react"));
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.8.4/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.8.4/umd/react-dom.production.min.js"></script>
<div id="react"></div>
Related
I have a problem with my footer. My footer is under the right section but I want that it will be under the main section on the full-width container.
* {
margin: 0;
padding: 0;
font-family: sans-serif;
}
body {
background-color: #1F0057;
}
.container {
width: 1400px;
margin-left: 15%;
float: left;
}
nav ul li img {
width: 25px;
padding-left: 5%;
}
nav ul {
list-style: none;
}
nav ul li {
display: inline;
}
nav ul li a {
vertical-align: middle;
padding-left: 5px;
color: #DAA520;
text-decoration: none;
text-transform: uppercase;
font-size: 1.2rem;
/* border: 1px solid yellow; */
}
nav {
background-color: #1F0057;
width: 100%;
height: 1em;
/* border: 1px solid yellow; */
}
.header {
font-size: 4rem;
color: white;
background-color: rgb(220, 189, 222);
width: 100%;
}
.title {
text-align: center;
color: #696969;
}
main article section {
float: left;
height: 60vh;
}
#first {
/* background-image: url(); */
background-image: url("gimp/cpu1.png");
/* usun "color" */
color: white;
width: 20%;
/* width: 300px; */
}
#second {
padding: 2%;
width: 60%;
height: auto;
background-color: #fff;
background-color: #4800CF;
/* width: 900px; */
}
#third {
width: 16%;
background-color: #5600F5;
height: auto;
/* width: 188px; */
}
main article section header {
font-size: 1.8em;
font-weight: bold;
padding: 2%;
}
main article section figure {
font-size: 1.2rem;
font-weight: bold;
margin-top: 3%;
box-shadow: 2px 2px 5px black;
}
main article section figcaption {
font-size: 1.1rem;
text-indent: 1.5em;
padding-top: 2.5%;
text-align: justify;
}
.secondmainmargin {
/* margin: 2%; */
}
.footer {
background-color: white;
font-family: 'Robocot';
font-size: 1.4rem;
text-align: center;
color: #fff;
float: right;
}
.link {
padding: 2%;
}
<div class="container">
<header class="header">
<div class="title">
Podstawowe podzespoły i parametry sprzętu komputerowego
</div>
<nav class="navbar">
<ul>
<li><img src="img/house.png" alt="domek"></li>
<li>Obudowa</li>
<!-- !!!!!przy "strony nie może być "/" czyli "/strony.obudowa.html"!!!!! -->
<li>Płyta główna</li>
<li>Procesor</li>
<li>Karty rozszerzeń</li>
<li>Pamięć Operacyjna</li>
<li>Pamięci masowe</li>
<li>Zasilacz</li>
<li>Inne</li>
</nav>
</header>
<main class="main">
<article>
<section id="first">
<img src="gimp/cpu1.png" alt="procesor" width="100%;">
</section>
<section id="second">
<header>
Nagłówek sekcji
</header>
<div class="secondmainmargin">
<figure>Podtytuł pierwszy</figure>
<figcaption>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aut dolore laborum explicabo beatae dignissimos consectetur, asperiores quod, culpa velit expedita vitae, id hic voluptatem soluta eius alias. Animi sequi deserunt dolorem incidunt iure laudantium
laborum nemo quia ullam blanditiis, voluptatem ea a odit quae, repellendus dicta consequuntur provident ab exercitationem itaque molestias, dolor. Et, ipsa, iusto. Deserunt labore provident ad adipisci sed aliquid natus nihil.
</figcaption>
<figure>Podtytuł drugi</figure>
<figcaption>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dignissimos modi laborum repudiandae error temporibus ullam consectetur in molestiae exercitationem quos, expedita cum, odit voluptatum quod illo vitae. Dolorum aperiam unde ducimus maxime aut
iusto distinctio ipsum nisi eveniet illo atque tempore, eius error ex, cupiditate! Provident doloribus voluptatibus dignissimos, sed!
</figcaption>
<figure>Podtytuł trzeci</figure>
<figcaption>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ea facilis ducimus beatae doloribus possimus fugiat iste aliquid, laudantium ab omnis veniam porro nemo explicabo. Inventore totam consequuntur expedita, distinctio exercitationem, eaque sint accusantium
libero voluptas sunt eligendi. Dolorum enim, consectetur perferendis veritatis impedit adipisci quo optio maiores odit accusantium tempora eaque blanditiis explicabo eligendi nam dolore placeat natus pariatur?dawdawdadawd Lorem ipsum dolor
sit amet, consectetur adipisicing elit. Amet, eveniet. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Earum ipsa pariatur a, sequi provident id dolor cupiditate dolorum consectetur, ea aliquid sint nesciunt nobis perspiciatis vitae
deserunt, molestiae odit fugit. Tempore quae natus enim reprehenderit aspernatur ratione illo neque assumenda, beatae nihil, ipsa incidunt minima, qui? Delectus animi velit quam distinctio est rem, itaque tempore placeat odio tenetur ipsam
iure consequuntur ex dolorum nulla sunt provident quibusdam harum fugiat et. Ex praesentium sunt, est qui distinctio. Laboriosam quo molestias neque numquam autem suscipit impedit, quaerat optio dolores veritatis sint sequi dolorem necessitatibus
molestiae, ex, incidunt modi porro eius natus perspiciatis!
</figcaption>
</div>
</section>
<section id="third">
<div class="link">
<header>Linki</div>
</header>
</section>
</article>
</main>
<footer class="footer">
Made by: Filip
</footer>
</div>
code with css: https://codepen.io/FilipoV/pen/jOyyNxR
add this to your .footer-class:
.footer{
display:block;
clear:both;
}
and remove
float:right;
I am trying to create a web page where I have a margin of 50px fixed left and right where the page images have an index that makes it closer to the screen and the margin looks farther off.I also want to achieve a fixed footer like I have for the navigation bar.I tried setting margin left and right to 50px and setting them to a fixed position and tried using the wrapper class to add to the sections both did not yield desired result.
Here is my code below
HTML CODE:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Archers</title>
<link rel="stylesheet" href="arch.css">
</head>
<body>
<section id="main">
<div class="bg1">
<header>
<div id="navbar">
<nav class="nav-list">
<ul class="ul-style ">
<li>OUR PORTFOLIO</li>
<li>OUR PROCESS</li>
<li>ABOUT</li>
<li>HOME</li>
</ul>
</div>
</header>
</div>
</div>
</section>
<section id="about">
<div class="bg1">
<div class="about_us">
<a name="#about">
<p>
<h1>ABOUT US</h1>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Minima ducimus officia vero, animi dicta magni tenetur praesentium quisquam, iusto itaque distinctio quis blanditiis. Ad quos, voluptate labore aut aspernatur vitae nostrum quaerat
quasi nulla earum incidunt facere dolorum ipsam necessitatibus ex illum hic voluptatibus! Suscipit laborum consectetur numquam neque ratione ullam asperiores adipisci quidem, totam praesentium nisi quisquam at tempora autem earum iste,
itaque
minima. Modi repellendus laudantium quas odio tempora hic similique molestias quia sapiente saepe nobis, vel, nemo impedit delectus. Voluptatum suscipit est, autem laborum, maiores ad nesciunt necessitatibus in neque sunt, ipsam dolorem
rem.
Sit, illum, non.
</p>
</a>
</div>
</div>
</div>
</section>
<section id="process">
<div class="bg1>
<div class=" our_process">
<a name="#process">
<p>
<h1>OUR PROCESS</h1>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Minima ducimus officia vero, animi dicta magni tenetur praesentium quisquam, iusto itaque distinctio quis blanditiis. Ad quos, voluptate labore aut aspernatur vitae nostrum quaerat
quasi nulla earum incidunt facere dolorum ipsam necessitatibus ex illum hic voluptatibus! Suscipit laborum consectetur numquam neque ratione ullam asperiores adipisci quidem, totam praesentium nisi quisquam at tempora autem earum iste,
itaque
minima. Modi repellendus laudantium quas odio tempora hic similique molestias quia sapiente saepe nobis, vel, nemo impedit delectus. Voluptatum suscipit est, autem laborum, maiores ad nesciunt necessitatibus in neque sunt, ipsam dolorem
rem.
Sit, illum, non.
</p>
</a>
</div>
</div>
</div>
</section>
<section id="portfolio">
<div class="bg1">
<div class="our_portfolio">
<a name="#portfolio">
<p>
<h1>OUR PORTFOLIO</h1>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Minima ducimus officia vero, animi dicta magni tenetur praesentium quisquam, iusto itaque distinctio quis blanditiis. Ad quos, voluptate labore aut aspernatur vitae nostrum quaerat
quasi nulla earum incidunt facere dolorum ipsam necessitatibus ex illum hic voluptatibus! Suscipit laborum consectetur numquam neque ratione ullam asperiores adipisci quidem, totam praesentium nisi quisquam at tempora autem earum iste,
itaque
minima. Modi repellendus laudantium quas odio tempora hic similique molestias quia sapiente saepe nobis, vel, nemo impedit delectus. Voluptatum suscipit est, autem laborum, maiores ad nesciunt necessitatibus in neque sunt, ipsam dolorem
rem.
Sit, illum, non.
</p>
</a>
</div>
</div>
</div>
</section>
</section>
<section id="footer">
<footer>
2020 DeborahPalmTree
</footer>
</section>
<script src="index.js" charset="utf-8"></script>
</body>
</html>
CSS CODE
* {
padding: 0;
margin: 0;
}
body {
width: 100%;
height: 100vh;
}
#navbar {
width: 100%;
height: 50px;
background-color: rgba(219, 219, 219, 1.0);
position: fixed;
}
nav ul li {
list-style: none;
float: right;
margin: 20px;
}
li a {
text-decoration: none;
color: #ffffff;
}
.bg1 {
background-color:rgba(255,255,255, 0.5);
width:100%;
height:100%;
}
/*.wrapper{
width:50px;
position:fixed;
height:100%;
background-color:rgba(255,255,255,1.0);
opacity:0;
z-index:1;}
}*/
#main {
height: 100%;
width: 100%;
background-image: url('structural-images/img_house_trees.jpg');
background-size: cover;
background-position: bottom;
}
#about {
height: 100%;
width: 100%;
background-image: url('structural-images/img_construction_site.jpg');
background-size: cover;
background-position: bottom;
}
#process {
height: 100%;
width: 100%;
background-image: url('structural-images/img_arc_plan.jpg');
background-size: cover;
background-position: bottom;
}
#portfolio {
height: 100%;
width: 100%;
background-image: url('structural-images/img-structure-garden-car-park.jpg');
background-size: cover;
background-position: bottom;
}
#fixed{
position: fixed;
height :50px;
width:100%;
background-color: rgba(219,219,219,1.0);
}
You did not use the id selector to reference the footer section in your css page, probably you referenced #fixed in place of footer instead, at the bottom of your CSS file.
// use this instead
#footer{
position: fixed;
bottom: 0;
left: 0;
height :50px;
width:100%;
background-color: transparent;
}
You used the same selector on your menu nav, sections and subdivs (#portfiolio),you need to learn how to create layout properly and make use of css selectors properly. you can learn for free on udemy introduction to web design. Their explanation is very good, and also Kenvin Powell introduction to css course on Youtube.
For a quick fix
Get one parent div with 2 children
<div class="parentDiv">
<div class="bgDiv"></div>
<div class="contentDiv></div>
</div>
you can play with the units to get your desired output, assuming the current screen size is 746px
.parentDiv{
width: 646px;
max-width: 100%;
position: relative;
max-width: 100%;
margin: auto;
perspective: 500px;
height: 100%;
}
.bgDiv{
box-shadow: inset -3px -70px 8px 6vw rgba(255, 255, 255, 0.8);
background-image: linear-gradient(rgba(245, 242, 242, 0.44), rgba(255,
255, 255, 0.5)), url(https://placebear.com/500/300);
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-repeat: no-repeat;
z-index: -999;
background-size: cover;
}
.contentDiv{
position: absolute;
z-index: 999;
top: 20px;
left: 50px;
transform: translate3d(25px, 25px, 50px);
padding: 4rem;
}
I have started learning HTML/css about 2 weeks ago and (among others) this is one of the pages I came up with, but I can't make the image to resize when I shrink down the window. Most of the lessons until now have been about HTML and CSS only and how to make the document easy to read for screen readers and I wanted to do some practice with whatever knowledge I had. Any ideas why the image doesn't shrink down along with the text and why?
Thank you very much!
HTML:
#import url('https://fonts.googleapis.com/css?family=Kelly+Slab&display=swap');
body {
margin: 0;
padding: 0;
background-color: #d89cf6;
}
.top {
position: relative;
padding: 1em 2em 1em 2em;
height: 3em;
background-color: #3e206d;
margin: auto;
overflow: hidden;
border-top: solid 6px;
border-bottom: solid 1px;
}
.top h1 {
position: absolute;
display: flex;
float: left;
margin: 0;
padding: 0;
margin-top: .3em;
font-family: 'Kelly Slab', cursive;
font-size: 2.4em;
color: #f0e3ff;
}
.top ul {
list-style-type: none;
display: flex;
float: right;
margin: 0;
padding: 0;
margin-top: 1.43em;
}
.top li {
padding: 0 0.3em;
margin: auto;
margin-top: .5em;
position: relative;
}
.top a {
text-decoration: none;
color: #f0e3ff;
font-family: 'Kelly Slab', cursive;
font-size: 1.2em;
}
.main {
padding: 1.5em 4.7em 2em;
color: #000000;
font-family: 'Kelly Slab', cursive;
}
.main h2 {
font-size: 1.8rem;
}
.main p {
font-size: 1.3rem;
}
.main img {
min-width: auto;
width: auto;
max-height: 29em;
min-height: 25%;
}
.text_picture {
float:right;
width: auto;
margin: auto;
}
.thank_you {
padding: 1.5em 4.7em 2em;
color: #000000;
font-family: 'Kelly Slab', cursive;
}
footer {
font-size: 1.2rem;
margin: auto;
text-align: center;
padding: 1.5em 4.7em 2em;
color: #000000;
font-family: 'Kelly Slab', cursive;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Skeleton</title>
<link rel="stylesheet" href="style/main.css" type="text/css">
</head>
<body>
<header>
<div class="top">
<h1>Arghhhh</h1>
<nav class="internal_nav">
<ul>
<li>Home</li>
<li>Contact</li>
</ul>
</nav>
</div>
</header>
<section class="main">
<article>
<h2>Lorem, ipsum</h2>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Excepturi dolore vero natus libero labore! Voluptas, culpa cum animi, explicabo laudantium fuga rem hic fugiat deleniti eveniet ad dignissimos minus! Nisi cumque dolore illo corrupti quo recusandae possimus aliquam officiis blanditiis, inventore veritatis. Cum itaque molestiae iusto dolorem esse illo saepe ipsam dolor cupiditate neque velit, dolore error earum eveniet tempora!
</p>
<div id="text_picture_container">
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Reprehenderit ab magni officiis eos rem in aperiam tenetur quidem maiores, tempore enim, id sapiente velit pariatur ducimus. Velit vero consequuntur possimus quam culpa voluptatum officia est voluptate eum, labore facilis assumenda rerum harum ipsam facere quas cupiditate. Itaque facilis voluptas cupiditate eos? Commodi odit tempore nihil blanditiis, excepturi quidem vero. Nam nesciunt corporis minima alias aperiam voluptate neque quidem consequatur ab sed, mollitia nulla labore expedita? Laboriosam atque error, similique temporibus eius, sunt quaerat nobis vero maxime corrupti quis ipsam. Aliquam rem id harum culpa nesciunt facere sit atque provident neque!
</p>
<div class="text_picture">
<figure>
<img src="images/wallpaper-364615676716148alamn2ffq.jpg" alt="lone tree in a field with a orange/magenta sunset in the background">
<br>
<figcaption>A lonely tree in the middle of a field, with a really colorful sunset background.
</figcaption>
</figure>
</div>
</div>
<p>Lorem ipsum dolor sit amet consectetur, adipisicing elit. Incidunt earum assumenda praesentium dolor et veritatis libero. Eveniet quasi fugiat, consectetur error possimus natus? Quasi explicabo deserunt quisquam necessitatibus hic aspernatur totam tenetur eveniet accusamus! Voluptate reprehenderit sunt repellat aut adipisci temporibus provident vitae amet cum doloribus dolorum tempora, perferendis voluptas aperiam libero similique distinctio quam corrupti consequatur vero magnam commodi. Enim, consequuntur. Quod maiores laudantium nesciunt doloremque, voluptatem dolorum amet. Tempore, vel dignissimos, veniam magni recusandae saepe ab labore itaque eum officiis, quaerat quae eveniet? Placeat nemo aperiam similique earum, tempore dicta totam atque. Perspiciatis, aut. Ea distinctio iure minima, id doloremque quisquam quidem expedita nemo. Facere dignissimos, architecto similique repellendus aliquid dicta deserunt et esse voluptate nulla ipsum quod earum voluptas nobis consectetur expedita quas, non itaque. Optio incidunt dolor distinctio, ducimus beatae doloribus magni ut aliquam a facere laborum ipsam ratione voluptatem. Dolore modi error nemo impedit recusandae?
</p>
<div class="first_survey">
<form class="survey">
<fieldset>
<legend>Chose what impressed you the most:</legend>
<label for="style">The styling</label>
<input type="checkbox" id="style" name="survey_choice" value="style">
<label for="writing">The writing</label>
<input type="checkbox" id="writing" name="survey_choice" value="writing">
<label for="pictures">The pictures</label>
<input type="checkbox" id="writing" name="survey_choice" value="pictures">
<div class="button">
<button type="submit">Submit</button>
</div>
</fieldset>
</form>
</section>
<div href="#" class="thank_you">
<h2>Thank you for taking your time to browse my webpage!
</h2>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Deserunt quisquam commodi sapiente quos ut unde consectetur alias culpa veniam, quasi perspiciatis expedita esse accusantium quas enim quam soluta, quibusdam sit? Quisquam placeat, iure possimus cupiditate libero non esse quasi facere deserunt debitis delectus reiciendis aliquid magnam a blanditiis, eaque officia.
<p>
</div>
</article>
</body>
<footer>
<h6>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ipsum, dolore?</h6>
</footer>
</html>
You can always use VH unit which stands for viewport width.
Responsive Text
However, I suggest using REM and EM units instead, of course, this depends on your needs.
REM and EM units
Feel free to read this article which explains this topic in depth.
CSS Font Sizing: Pixels vs Em vs Rem vs Percent vs Viewport Units
Now, regarding responsive image sizing, you can simply add a class with these properties and set it to the image you want.
.responsive {
width: 100%;
height: auto;
}
As I said before, read the Medium article, you can use REM, EM, PX, % units on images as well.
I'm trying to create a sticky nav with css but I must be missing something.
I've found the process on here. But I've tried adding it to the .nav class, the .item class, both, and doesn't do a thing.
I tried adding extra padding below the body, thinking it's an issue of not scrolling down far enough, but still no go.
* {
font-family: arial, sans-serif;
box-sizing: border-box;}
html, body {
margin: 0;
padding: 0;
}
a {
text-decoration: none;
color: black;
}
.nav {
position: -webkit-sticky;
position: sticky;
top: 0;
margin-top: 65px;
left:0;
background-color: rgba(255,255,255,.8);
border-radius: 0px;
border: none;
width: 100%;
margin: 0;
padding: 10px 0;
flex-direction: row;
display: flex;
align-items: center;
justify-content: space-evenly;
}
.item {
color: black;
font-weight: bold;
text-transform: capitalize;
width: 25%;
text-align: center;
}
.submenu {
display: none;
flex-wrap: wrap;
align-items: center;
align-text: center;
position: absolute;
padding-top: 107px;
padding: 10px;
left: 0;
right: 0;
text-transform: uppercase;
z-index: 1;
background-color: #2F4F4F;
color: white;
justify-content: space-evenly;
}
.submenu li {
margin-left: 6%;
width: 19%;
padding: 5px;
}
<nav>
<a class="logo" href="index.html">
<img src="../Images/Navigation/Intak Logo 25px High.png" alt="Home"/>
</a>
<ul class="nav">
<li class="item">
<a href="index.html">
<img src="../Images/Navigation/Intak Nav Mark -01.png" alt="Home"/>
</a>
</li>
<li class="item" style="color:#4D4D4D;">Printing
</li>
<li class="item">Graphic Design
</li>
<li class="item has-children">Chinese Calendars
<ul class="submenu">
<li>Cane Wallscroll Calendars</li>
<li>Wall Calendars</li>
<li>Mini Calendars</li>
<li>Desk Calendars</li>
<li>Special Desk Calendars</li>
<li>Red Packet</li>
<li>More Calendars</li>
</ul>
</li>
<li class="item">Contact Us</li>
</ul>
</nav>
I'm expecting it to scroll relative, then become fixed when it passes the main image. Now it's just scrolling relative
You need to set the sticky positioning on nav, not .nav:
nav {
position: -webkit-sticky;
position: sticky;
top: 0;
}
Here's a working demo.
* {
font-family: arial, sans-serif;
box-sizing: border-box;
margin: 0;
}
h1 {
background-color: gray;
font-size: 100px;
padding: 40px 20px;
}
html,
body {
margin: 0;
padding: 0;
}
a {
text-decoration: none;
color: black;
}
nav {
position: -webkit-sticky;
position: sticky;
top: 0;
}
.nav {
margin-top: 65px;
left: 0;
background-color: rgba(255, 255, 255, .8);
border-radius: 0px;
border: none;
width: 100%;
margin: 0;
padding: 10px 0;
flex-direction: row;
display: flex;
align-items: center;
justify-content: space-evenly;
}
.item {
color: black;
font-weight: bold;
text-transform: capitalize;
width: 25%;
text-align: center;
}
.submenu {
display: none;
flex-wrap: wrap;
align-items: center;
align-text: center;
position: absolute;
padding-top: 107px;
padding: 10px;
left: 0;
right: 0;
text-transform: uppercase;
z-index: 1;
background-color: #2F4F4F;
color: white;
justify-content: space-evenly;
}
.submenu li {
margin-left: 6%;
width: 19%;
padding: 5px;
}
<h1>Huge title</h1>
<nav>
<a class="logo" href="index.html">
<img src="../Images/Navigation/Intak Logo 25px High.png" alt="Home" />
</a>
<ul class="nav">
<li class="item">
<a href="index.html">
<img src="../Images/Navigation/Intak Nav Mark -01.png" alt="Home" />
</a>
</li>
<li class="item" style="color:#4D4D4D;">Printing
</li>
<li class="item">Graphic Design
</li>
<li class="item has-children">Chinese Calendars
<ul class="submenu">
<li>Cane Wallscroll Calendars</li>
<li>Wall Calendars</li>
<li>Mini Calendars</li>
<li>Desk Calendars</li>
<li>Special Desk Calendars</li>
<li>Red Packet</li>
<li>More Calendars</li>
</ul>
</li>
<li class="item">Contact Us</li>
</ul>
</nav>
<p><span>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Autem ipsa voluptas accusamus consectetur, ex, itaque animi expedita cum mollitia dicta. Ullam totam, enim aliquid quo eveniet assumenda possimus ratione maxime!</span>
<span>Omnis cum tempore facere, nobis ullam iure dolorem error, alias aut iste nisi sed autem consequatur. Optio quisquam neque eligendi ab distinctio hic, ea culpa quia atque, deserunt, repudiandae aperiam!</span>
<span>Nihil quia, odit dolores voluptas ea, distinctio eveniet, quasi quidem quae deserunt deleniti ipsa qui saepe libero neque! Ipsam suscipit ipsa consequatur nulla laudantium aspernatur repellat laboriosam, quibusdam. Fuga, aliquam.</span>
<span>Sed assumenda asperiores doloremque eos quam vel tempore cumque facere libero, sequi. Reprehenderit voluptatem tempore itaque velit quibusdam ex, culpa repudiandae amet pariatur dolorem veniam autem voluptatum, perferendis, quasi doloremque.</span>
<span>Animi quae optio amet fuga id architecto ipsum possimus nostrum similique, voluptatibus excepturi totam eius sapiente illo, error laboriosam sed eum nihil eos, perferendis ex natus sequi. Veritatis soluta, neque.</span>
<span>Assumenda repudiandae, est rem, qui repellat odio asperiores doloremque amet autem temporibus, laudantium quibusdam ratione. Voluptates nihil, neque dolorem dolor rem cupiditate deserunt sint dolores distinctio. Officia totam officiis soluta.</span>
<span>Adipisci explicabo, aspernatur assumenda quibusdam ullam aliquid beatae quidem totam repellat voluptate odit numquam molestiae eligendi nisi soluta quaerat consectetur placeat fuga blanditiis, quos non quam recusandae pariatur. Omnis, sunt.</span>
<span>Minima, aspernatur, modi! Temporibus esse minus labore repellendus fugit obcaecati qui laudantium officia impedit. Consequatur vel aliquam earum alias, nam ex consectetur? Ipsum, ea. Officiis quia odio consequatur quo iusto.</span>
<span>Excepturi saepe a, minus earum omnis nisi recusandae ut, repellendus doloremque labore vel, ea id quisquam doloribus rerum beatae deserunt placeat esse. Architecto a sit sed, magnam vero recusandae ullam.</span>
<span>Eaque nihil magnam voluptates fuga iure ipsum excepturi hic fugit quisquam consectetur dicta dolorem velit architecto, rem id porro, tempora inventore ipsam accusamus illum eius suscipit eligendi earum corporis. Ullam.</span>
<span>Molestias, voluptate, velit. Recusandae quas harum asperiores ipsum maiores reprehenderit praesentium ipsam explicabo eius impedit totam beatae atque rerum modi laboriosam id, nemo nisi! Corrupti provident esse deserunt voluptatibus atque.</span>
<span>Distinctio, odit deserunt nam numquam similique provident commodi modi hic nobis, atque ipsum fuga, quidem repellat ea mollitia fugit quasi nulla, voluptatibus consequuntur. Odit incidunt nesciunt vero placeat, assumenda delectus?</span>
<span>Amet hic a optio, error molestiae, iure neque, temporibus pariatur voluptatibus incidunt aspernatur in nobis nesciunt alias fugiat ratione harum porro consequuntur deserunt consequatur sint? Dicta aperiam velit unde iusto?</span>
<span>Ipsum doloribus, deserunt modi tempore. Nobis sequi saepe aliquam vitae neque accusantium necessitatibus dolores natus nostrum, id. Natus reprehenderit temporibus quod doloribus rem hic at fugiat totam sint, expedita incidunt.</span>
<span>Ipsa omnis voluptas dicta perferendis officia temporibus dignissimos quisquam non pariatur, blanditiis eum, accusamus consectetur. Earum voluptatibus iure iste ipsum, porro commodi maiores eos eaque. Repudiandae eius repellat iste, cupiditate.</span>
<span>Delectus fugiat adipisci commodi vel ea accusamus, praesentium veritatis explicabo in exercitationem. Reprehenderit cupiditate ullam temporibus veniam adipisci non dicta quas nisi atque assumenda, ipsam facere error vel debitis odio.</span>
<span>Aliquid amet quo quam. Id saepe ab accusamus non fugit soluta totam explicabo beatae. Enim sapiente veniam blanditiis a vel modi, maiores, placeat obcaecati, quia molestiae deleniti. Optio, quos, porro.</span>
<span>Sapiente voluptatum deleniti, natus reiciendis animi consectetur molestiae eos assumenda explicabo error totam iure obcaecati voluptas qui tempora ipsum mollitia hic magni praesentium quas sint nam facilis enim voluptates nobis!</span>
<span>Aut illo quos ab obcaecati sit maiores optio beatae omnis numquam cumque alias laudantium, temporibus, molestias nesciunt quae vitae soluta nemo quisquam est earum quasi provident qui recusandae. Quod, libero?</span>
<span>Explicabo molestiae adipisci pariatur distinctio, minus rerum, sunt officia aspernatur consectetur eos dolores voluptas itaque saepe dolor ad, nemo perferendis nesciunt repellendus, perspiciatis deserunt quis. Sint deserunt iusto corrupti sapiente!</span></p>
jsFiddle
I think you can use something like the approach below:
window.onscroll = function() {myFunction()};
var navbar = document.getElementById("navbar");
var sticky = navbar.offsetTop;
function myFunction() {
if (window.pageYOffset >= sticky) {
navbar.classList.add("sticky")
} else {
navbar.classList.remove("sticky");
}
}
nav {
overflow: hidden;
background-color: #333;
}
nav a {
float: left;
display: block;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}
nav a:hover {
background-color: #ddd;
color: black;
}
nav a.active {
background-color: #4CAF50;
color: white;
}
.content {
padding: 16px;
}
.sticky {
position: fixed;
top: 0;
width: 100%;
}
.sticky + .content {
padding-top: 60px;
}
html, body {
margin: 0;
padding: 0;
}
a {
text-decoration: none;
color: black;
}
.nav {
position: -webkit-sticky;
position: sticky;
top: 0;
margin-top: 65px;
left:0;
background-color: rgba(255,255,255,.8);
border-radius: 0px;
border: none;
width: 100%;
margin: 0;
padding: 10px 0;
flex-direction: row;
display: flex;
align-items: center;
justify-content: space-evenly;
}
.item {
color: black;
font-weight: bold;
text-transform: capitalize;
width: 25%;
text-align: center;
}
.submenu {
display: none;
flex-wrap: wrap;
align-items: center;
align-text: center;
position: absolute;
padding-top: 107px;
padding: 10px;
left: 0;
right: 0;
text-transform: uppercase;
z-index: 1;
background-color: #2F4F4F;
color: white;
justify-content: space-evenly;
}
.submenu li {
margin-left: 6%;
width: 19%;
padding: 5px;
}
<!DOCTYPE html>
<html>
<body>
<div class="header">
<h2>Scroll Down</h2>
<p>Scroll down to see the sticky effect.</p>
</div>
<nav id="navbar">
<a class="logo" href="index.html">
<img src="../Images/Navigation/Intak Logo 25px High.png" alt="Home"/>
</a>
<ul class="nav">
<li class="item">
<a href="index.html">
<img src="../Images/Navigation/Intak Nav Mark -01.png" alt="Home"/>
</a>
</li>
<li class="item" style="color:#4D4D4D;">Printing
</li>
<li class="item">Graphic Design
</li>
<li class="item has-children">Chinese Calendars
<ul class="submenu">
<li>Cane Wallscroll Calendars</li>
<li>Wall Calendars</li>
<li>Mini Calendars</li>
<li>Desk Calendars</li>
<li>Special Desk Calendars</li>
<li>Red Packet</li>
<li>More Calendars</li>
</ul>
</li>
<li class="item">Contact Us</li>
</ul>
</nav>
<div class="content">
<h3>Sticky Navigation Example</h3>
<p>The navbar will stick to the top when you reach its scroll position.</p>
<p>Some text to enable scrolling.. Lorem ipsum dolor sit amet, illum definitiones no quo, maluisset concludaturque et eum, altera fabulas ut quo. Atqui causae gloriatur ius te, id agam omnis evertitur eum. Affert laboramus repudiandae nec et. Inciderint efficiantur his ad. Eum no molestiae voluptatibus.</p>
</div>
</body>
</html>
<!-- begin snippet: js hide: false console: true babel: false -->
I have a PSD which I have to convert to html. I have a problem with some elements, to be more precise I have no idea how to create it, furthermore I don't know how to name it to find examples in google. Looking for your advices. Those arrows should be responsive(become longer or shorter)
I would give the background the dashed lines. Then I would position the icons along with their arrow heads at the top, bottom, and middle using css. Then as the element grows and shrinks the icons move with the sizing and cover the dashed lines in the background.
Here, I got you started...
.container {
box-sizing: border-box;
width: 80%;
display: flex;
flex-wrap: wrap;
flex-direction: column;
}
.top-dash {
position: relative;
width: 100%;
height: 30px;
margin-bottom: 1em;
background-color: black;
display: flex;
align-items: center;
justify-content: space-between;
}
.top-dash:before {
content: "";
position: absolute;
left: 0;
top: 13px;
width: 100%;
border-top: 5px dashed orange;
}
[class*="word"] {
display: block;
padding-right: 1em;
background-color: black;
color: orange;
font-size: 18px;
font-weight: bold;
z-index: 5;
}
[class*="word"]:first-child {
padding-left: 1em;
}
[class*="word"]:nth-child(n+2):before {
content: ">";
padding-right: 1em;
}
.content {
position: relative;
box-sizing: border-box;
width: 100%;
padding: 0 2em;
border-left: 60px solid blue;
}
.side-dash {
position: absolute;
left: -60px;
top: 0;
width: 60px;
height: 100%;
overflow: hidden;
display: flex;
}
.side-dash:before {
content: "";
position: absolute;
left: 28px;
top: 0;
height: 100%;
border-left: 5px dashed white;
}
<div class="container">
<div class="top-dash">
<span class="word-left">ONE</span>
<span class="word-mid">TWO</span>
<span class="word-right">THREE</span>
</div>
<div class="content">
<div class="side-dash">
<span class="icon-top"></span>
<span class="icon-mid"></span>
<span class="icon-bot"></span>
</div>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Iusto, cupiditate, explicabo! Voluptatibus placeat quod magnam soluta, fuga molestiae consectetur doloribus distinctio ipsum voluptas labore delectus reprehenderit rem voluptate, beatae nesciunt.</p>
<p>Nisi excepturi nobis ipsam perferendis nemo ipsa! Aspernatur quaerat ad, harum sapiente? Adipisci, ea. Aperiam exercitationem unde reiciendis obcaecati dolorem sit vitae animi, ut at quisquam corporis ratione voluptatum modi!</p>
<p>Assumenda explicabo voluptatum ea porro unde quo at praesentium temporibus quae optio, laudantium ab minus vero quas, repellat nihil. Laudantium, facere. Tempora adipisci earum voluptatem deserunt atque eos fugiat debitis.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Iusto, cupiditate, explicabo! Voluptatibus placeat quod magnam soluta, fuga molestiae consectetur doloribus distinctio ipsum voluptas labore delectus reprehenderit rem voluptate, beatae nesciunt.</p>
<p>Nisi excepturi nobis ipsam perferendis nemo ipsa! Aspernatur quaerat ad, harum sapiente? Adipisci, ea. Aperiam exercitationem unde reiciendis obcaecati dolorem sit vitae animi, ut at quisquam corporis ratione voluptatum modi!</p>
<p>Assumenda explicabo voluptatum ea porro unde quo at praesentium temporibus quae optio, laudantium ab minus vero quas, repellat nihil. Laudantium, facere. Tempora adipisci earum voluptatem deserunt atque eos fugiat debitis.</p>
</div>
</div>