When I hover over search icon, div with class "forma" expands and pushes the list with links to the left. How can I prevent this? My guess is something to do with position, display or width, but I am not sure. This is probably not a complicated task, but I am not very good with CSS.
Here is HTML:
<nav>
<div class=logo>
<img src="images/logoicon.png" alt="sunce">
<img src="images/logotext.png" alt="outdoors" id="logotext"></a>
</div>
<ul class="nav-ul">
<li>Destinations</li>
<li>Travel style</li>
<li>Trabel deals</li>
<li>Gear</li>
</ul>
<div class="forma">
<input type="search" placeholder="search" class="pretraga">
<i class="fa fa-search"></i>
</div>
</nav>
Here is CSS:
nav {
background-color: steelblue;
display: flex;
align-items: center;
justify-content: space-between;
padding: 15px;
position: sticky;
top: 0;
z-index: 2;
}
.nav-ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
/* background-color: #333; */
}
.nav-ul li {
display: inline;
float: left;
}
.nav-ul li a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
.nav-ul li:last-child {
float: right;
}
.nav-ul li a:hover:not(.active) {
background-color: #111;
}
.forma {
position: relative;
top: 20px;
left: 20px;
transform: translate(0, -50%);
transition: all 1s;
width: 50px;
height: 50px;
background: white;
box-sizing: border-box;
border-radius: 25px;
border: 4px solid white;
padding: 5px;
}
input {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 40px;
line-height: 30px;
outline: 0;
border: 0;
display: none;
font-size: 1em;
border-radius: 20px;
padding: 0 20px;
}
.fa {
box-sizing: border-box;
padding: 10px;
width: 40px;
height: 40px;
position: absolute;
top: 0;
right: 0;
border-radius: 50%;
color: black;
text-align: center;
font-size: 1.2em;
transition: all 1s;
}
.forma:hover {
width: 200px;
cursor: pointer;
}
.forma:hover input {
display: block;
}
Try below CSS here I have changed little bit code
Your Code
.forma {
position: relative;
top: 20px;
left: 20px;
transform: translate(0, -50%);
transition: all 1s;
width: 50px;
height: 50px;
background: white;
box-sizing: border-box;
border-radius: 25px;
border: 4px solid white;
padding: 5px;
}
input {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 40px;
line-height: 30px;
outline: 0;
border: 0;
display: none;
font-size: 1em;
border-radius: 20px;
padding: 0 20px;
}
.forma:hover {
width: 200px;
cursor: pointer;
}
.forma:hover input {
display: block;
}
Updated Code
Add this link in your HTML page for icon
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
.forma {
height: 50px;
width: 250px;
position: relative;
top: 20px;
left: 20px;
transform: translate(0, -50%);
}
input {
position: absolute;
right: 21px;
width: 90px;
max-width: 350px;
transition: all 1s;
height: 50px;
background: white;
box-sizing: border-box;
border-radius: 25px;
border: 4px solid white;
padding: 5px;
outline: 0;
}
input:focus{
outline: 0;
}
input:hover{
width: 350px;
}
You can check Live preview
nav {
background-color: steelblue;
display: flex;
align-items: center;
justify-content: space-between;
padding: 15px;
position: sticky;
top: 0;
z-index: 2;
}
.nav-ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
/* background-color: #333; */
}
.nav-ul li {
display: inline;
float: left;
}
.nav-ul li a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
.nav-ul li:last-child {
float: right;
}
.nav-ul li a:hover:not(.active) {
background-color: #111;
}
.forma {
height: 50px;
width: 250px;
position: relative;
top: 20px;
left: 20px;
transform: translate(0, -50%);
}
input {
position: absolute;
right: 21px;
width: 90px;
max-width: 350px;
transition: all 1s;
height: 50px;
background: white;
box-sizing: border-box;
border-radius: 25px;
border: 4px solid white;
padding: 5px;
outline: 0;
}
.fa {
box-sizing: border-box;
padding: 10px;
width: 40px;
height: 40px;
position: absolute;
top: 5px;
right: 20px;
border-radius: 50%;
color: black;
text-align: center;
font-size: 1.2em;
transition: all 1s;
}
input:focus{
outline: 0;
}
input:hover{
width: 350px;
}
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<nav>
<div class=logo>
<img src="images/logoicon.png" alt="sunce">
<img src="images/logotext.png" alt="outdoors" id="logotext">
</div>
<ul class="nav-ul">
<li>Destinations</li>
<li>Travel style</li>
<li>Trabel deals</li>
<li>Gear</li>
</ul>
<div class="forma">
<input type="search" placeholder="search" class="pretraga">
<i class="fa fa-search"></i>
</div>
</nav>
you can check Here
NOTE : Better view on desktop you have to write code for mobile also with #media rule
Related
I have a horizontal navbar at the top of the screen and a vertical one in a side bar. How can I make the list elements lineup below eachother like this:
This is what I get using my code:
This is my code (the snippet sort of works but it should suffice and get the point across):
#import url('https://fonts.googleapis.com/css2?family=Poppins:wght#200;300;400;500&display=swap');
* {
box-sizing: border-box;
scroll-behavior: smooth;
font-family: 'Poppins', sans-serif;
}
body {
background: linear-gradient( to right,#ff0000,#0000ff);
margin: 0;
}
p {
color:#ffffff;
font-size:20px;
padding: 10px;
}
.heading {
margin: 20px;
font-size: 50px;
text-align: center;
color: black;
}
a {
text-decoration: none;
}
.favcolorcontainer {
border: 2px solid black;
border-radius: 4px;
width: auto;
padding: 5px;
background: white;
display: inline-flex;
}
.colorpicker {
border:none;
background: white;
display: inline-flex;
}
.favcolor {
font-family: verdana;
margin-top: 3px;
}
.slideshow-container {
display: block;
width: 80%;
position: relative;
margin: 10px;
margin-left: auto;
margin-right: auto;
}
.mySlides {
display: none;
}
.prev, .next {
cursor: pointer;
position: absolute;
top: 50%;
width: auto;
margin-top: -22px;
padding: 16px;
color: white;
font-weight: bold;
font-size: 18px;
transition: 0.6s ease;
border-radius: 0 3px 3px 0;
user-select: none;
}
.next {
right: 0;
border-radius: 3px 0 0 3px;
}
.prev:hover, .next:hover {
background-color: #a6a6a650;
}
.slide-name {
color: #f2f2f2;
font-size: 15px;
padding: 8px 12px;
position: absolute;
bottom: 8px;
width: 100%;
text-align: center;
}
.slide-number {
color: #f2f2f2;
font-size: 12px;
padding: 8px 12px;
position: absolute;
top: 0;
}
.fade {
animation-name: fade;
animation-duration: 1.5s;
}
#keyframes fade {
from {opacity: .4}
to {opacity: 1}
}
.progress-bar {
width: 100%;
border: none;
border-radius: 100px;
background-color: #FFFFFF;
padding: 3px;
}
.progress-tag {
color: #DDDDDD;
margin-left: 10px;
}
.fill-html {
width: 75%;
background-color: #FA3200;
border-radius: 100px;
}
.fill-css {
width: 60%;
background-color: #0000C8;
border-radius: 100px;
}
.fill-js {
width: 10%;
background-color: #C80000;
border-radius: 100px;
}
.fill-php {
width: 3%;
background-color: #00C832;
border-radius: 100px;
}
.fill-rwpd {
width: 100%;
background-color: #450099;
border-radius: 100px;
}
#return {
display: none;
position: fixed;
bottom: 30px;
right: 35px;
z-index: 99;
border: none;
outline: none;
background-color: #0000d1;
color: white;
cursor: pointer;
border-radius: 100px;
font-size: 45px;
width: 60px;
height: 60px;
}
#return:hover {
background-color: #0101bb;
}
.progress-container {
padding: 10px;
}
.header-logo {
margin: 10px;
float: left;
}
.header {
background-color: #303030;
overflow: hidden;
width: 100%;
}
.desktop-nav {
float: right;
margin-right: 20px;
}
.desktop-nav a {
margin: 20px 30px 0 30px;
padding: 0 0 20px;
display: block;
color: white;
}
.desktop-nav a:hover {
color: #b4b4b4;
transition: 0.2s all ease;
}
.desktop-nav li {
float: left;
list-style: none;
}
.menu-button {
display: block;
margin: 15px;
font-size:25px;
cursor:pointer;
color:white
}
.menu-button:hover {
cursor: pointer;
}
.copyright {
color: #b4b4b4;
font-size: 15px;
}
footer {
background: #303030;
padding: 25px 0;
text-align: center;
bottom: 0;
width: 100%;
height: auto;
display: block;
}
.hyperlink {
display: inline-block;
position: relative;
color: #b4b4b4;
}
.hyperlink:after {
content: '';
position: absolute;
width: 100%;
transform: scaleX(0);
height: 2px;
bottom: 15px;
left: 0;
background-color: #b4b4b4;
transform-origin: bottom right;
transition: transform 0.25s ease-out;
}
.hyperlink:hover:after {
transform: scaleX(1);
transform-origin: bottom left;
}
.sidenav {
height: 100%;
width: 0;
position: fixed;
z-index: 1;
top: 0;
right: 0;
background-color: #111111;
overflow-x: hidden;
transition: 0.5s;
padding-top: 60px;
}
.sidenav .closebtn {
position: absolute;
top: 0;
right: 25px;
font-size: 35px;
margin-left: 50px;
}
.recipe-container {
margin: 0px;
padding: 10px;
display: grid;
grid-template-columns: auto auto auto;
justify-content: center;
}
.recipe-window {
margin: 10px;
padding: 10px;
border: 1px solid #ffffff;
background-color: #ffffff;
word-break: break-word;
width: min-content;
border-radius: 10px;
}
.recipe-title {
color: black;
margin-top: 5px;
padding: 0px;
font-size: 25px;
}
:root {
color-scheme: dark;
}
.footer-links {
display: flex;
justify-content: center;
align-items: center;
}
.footer-links p {
margin: 0;
}
.footer-links a {
color: #ffffff;
}
.footer-links a:hover {
color: #b4b4b4;
}
.about {
text-align: center;
padding: 0 300px;
}
.aside-1 {
float: right;
margin-right: 300px;
}
.mobile-nav {
float: right;
margin-right: 20px;
}
.mobile-nav a {
margin: 20px 30px 0 30px;
padding: 0 0 20px;
color: white;
}
.mobile-nav a:hover {
color: #b4b4b4;
transition: 0.2s all ease;
}
.mobile-nav li {
float: right;
list-style: none;
}
<html>
<head>
<title>Home</title>
<link rel="icon" type="image/x-icon" href="./images/favicon.png">
<link rel="stylesheet" href="main.css">
<link href="https://fonts.googleapis.com/css?family=Poppins" rel="stylesheet">
</head>
<body>
<div class="header">
<img src="./images/logo.png" width="150px" title="Aeron" alt="logo" class="header-logo">
<ul class="desktop-nav">
<li>Home</li>
<li>Portfolio</li>
<li>Contact</li>
<li>About Us</li>
<li>Recipes</li>
<li>Progress</li>
<li>PC Setup Designer</li>
<li>Gallery</li>
<li><span class="menu-button" onclick="openNav()">☰</span></li>
</ul>
<div id="mySidenav" class="sidenav">
×
<br>
<ul class="mobile-nav">
<li>Home</li>
<li>Portfolio</li>
<li>Contact</li>
<li>About Us</li>
<li>Recipes</li>
<li>Progress</li>
<li>PC Setup Designer</li>
<li>Gallery</li>
</ul>
</div>
</div>
<h1 class="heading">Welcome to Aeron</h1>
<div style="height:100%"></div>
<footer>
<img src="./images/logo.png" width="150px" title="Aeron" alt="logo" class="footer-logo">
<p class="copyright">Copyright © 2022 Aeron Corporation</p>
<div class="footer-links">
About Us
<p>|</p>
Policy
<p>|</p>
Contact Us
</div>
</footer>
<button onclick="topFunction()" id="return" title="Return To Top">^</button>
<script>
let mybutton = document.getElementById("return");
window.onscroll = function() {scrollFunction()};
function scrollFunction() {
if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
mybutton.style.display = "block";
} else {
mybutton.style.display = "none";
}
}
function topFunction() {
document.body.scrollTop = 0;
}
function openNav() {
document.getElementById("mySidenav").style.width = "25%";
}
function closeNav() {
document.getElementById("mySidenav").style.width = "0";
}
</script>
</body>
</html>
How can I do this? Thanks very much.
You could just remove the float: right and add text-align: right to the .mobile-nav li selector like so:
#import url('https://fonts.googleapis.com/css2?family=Poppins:wght#200;300;400;500&display=swap');
* {
box-sizing: border-box;
scroll-behavior: smooth;
font-family: 'Poppins', sans-serif;
}
body {
background: linear-gradient( to right,#ff0000,#0000ff);
margin: 0;
}
p {
color:#ffffff;
font-size:20px;
padding: 10px;
}
.heading {
margin: 20px;
font-size: 50px;
text-align: center;
color: black;
}
a {
text-decoration: none;
}
.favcolorcontainer {
border: 2px solid black;
border-radius: 4px;
width: auto;
padding: 5px;
background: white;
display: inline-flex;
}
.colorpicker {
border:none;
background: white;
display: inline-flex;
}
.favcolor {
font-family: verdana;
margin-top: 3px;
}
.slideshow-container {
display: block;
width: 80%;
position: relative;
margin: 10px;
margin-left: auto;
margin-right: auto;
}
.mySlides {
display: none;
}
.prev, .next {
cursor: pointer;
position: absolute;
top: 50%;
width: auto;
margin-top: -22px;
padding: 16px;
color: white;
font-weight: bold;
font-size: 18px;
transition: 0.6s ease;
border-radius: 0 3px 3px 0;
user-select: none;
}
.next {
right: 0;
border-radius: 3px 0 0 3px;
}
.prev:hover, .next:hover {
background-color: #a6a6a650;
}
.slide-name {
color: #f2f2f2;
font-size: 15px;
padding: 8px 12px;
position: absolute;
bottom: 8px;
width: 100%;
text-align: center;
}
.slide-number {
color: #f2f2f2;
font-size: 12px;
padding: 8px 12px;
position: absolute;
top: 0;
}
.fade {
animation-name: fade;
animation-duration: 1.5s;
}
#keyframes fade {
from {opacity: .4}
to {opacity: 1}
}
.progress-bar {
width: 100%;
border: none;
border-radius: 100px;
background-color: #FFFFFF;
padding: 3px;
}
.progress-tag {
color: #DDDDDD;
margin-left: 10px;
}
.fill-html {
width: 75%;
background-color: #FA3200;
border-radius: 100px;
}
.fill-css {
width: 60%;
background-color: #0000C8;
border-radius: 100px;
}
.fill-js {
width: 10%;
background-color: #C80000;
border-radius: 100px;
}
.fill-php {
width: 3%;
background-color: #00C832;
border-radius: 100px;
}
.fill-rwpd {
width: 100%;
background-color: #450099;
border-radius: 100px;
}
#return {
display: none;
position: fixed;
bottom: 30px;
right: 35px;
z-index: 99;
border: none;
outline: none;
background-color: #0000d1;
color: white;
cursor: pointer;
border-radius: 100px;
font-size: 45px;
width: 60px;
height: 60px;
}
#return:hover {
background-color: #0101bb;
}
.progress-container {
padding: 10px;
}
.header-logo {
margin: 10px;
float: left;
}
.header {
background-color: #303030;
overflow: hidden;
width: 100%;
}
.desktop-nav {
float: right;
margin-right: 20px;
}
.desktop-nav a {
margin: 20px 30px 0 30px;
padding: 0 0 20px;
display: block;
color: white;
}
.desktop-nav a:hover {
color: #b4b4b4;
transition: 0.2s all ease;
}
.desktop-nav li {
float: left;
list-style: none;
}
.menu-button {
display: block;
margin: 15px;
font-size:25px;
cursor:pointer;
color:white
}
.menu-button:hover {
cursor: pointer;
}
.copyright {
color: #b4b4b4;
font-size: 15px;
}
footer {
background: #303030;
padding: 25px 0;
text-align: center;
bottom: 0;
width: 100%;
height: auto;
display: block;
}
.hyperlink {
display: inline-block;
position: relative;
color: #b4b4b4;
}
.hyperlink:after {
content: '';
position: absolute;
width: 100%;
transform: scaleX(0);
height: 2px;
bottom: 15px;
left: 0;
background-color: #b4b4b4;
transform-origin: bottom right;
transition: transform 0.25s ease-out;
}
.hyperlink:hover:after {
transform: scaleX(1);
transform-origin: bottom left;
}
.sidenav {
height: 100%;
width: 0;
position: fixed;
z-index: 1;
top: 0;
right: 0;
background-color: #111111;
overflow-x: hidden;
transition: 0.5s;
padding-top: 60px;
}
.sidenav .closebtn {
position: absolute;
top: 0;
right: 25px;
font-size: 35px;
margin-left: 50px;
}
.recipe-container {
margin: 0px;
padding: 10px;
display: grid;
grid-template-columns: auto auto auto;
justify-content: center;
}
.recipe-window {
margin: 10px;
padding: 10px;
border: 1px solid #ffffff;
background-color: #ffffff;
word-break: break-word;
width: min-content;
border-radius: 10px;
}
.recipe-title {
color: black;
margin-top: 5px;
padding: 0px;
font-size: 25px;
}
:root {
color-scheme: dark;
}
.footer-links {
display: flex;
justify-content: center;
align-items: center;
}
.footer-links p {
margin: 0;
}
.footer-links a {
color: #ffffff;
}
.footer-links a:hover {
color: #b4b4b4;
}
.about {
text-align: center;
padding: 0 300px;
}
.aside-1 {
float: right;
margin-right: 300px;
}
.mobile-nav {
float: right;
margin-right: 20px;
}
.mobile-nav a {
margin: 20px 30px 0 30px;
padding: 0 0 20px;
color: white;
}
.mobile-nav a:hover {
color: #b4b4b4;
transition: 0.2s all ease;
}
.mobile-nav li {
list-style: none;
text-align: right;
}
<html>
<head>
<title>Home</title>
<link rel="icon" type="image/x-icon" href="./images/favicon.png">
<link rel="stylesheet" href="main.css">
<link href="https://fonts.googleapis.com/css?family=Poppins" rel="stylesheet">
</head>
<body>
<div class="header">
<img src="./images/logo.png" width="150px" title="Aeron" alt="logo" class="header-logo">
<ul class="desktop-nav">
<li>Home</li>
<li>Portfolio</li>
<li>Contact</li>
<li>About Us</li>
<li>Recipes</li>
<li>Progress</li>
<li>PC Setup Designer</li>
<li>Gallery</li>
<li><span class="menu-button" onclick="openNav()">☰</span></li>
</ul>
<div id="mySidenav" class="sidenav">
×
<br>
<ul class="mobile-nav">
<li>Home</li>
<li>Portfolio</li>
<li>Contact</li>
<li>About Us</li>
<li>Recipes</li>
<li>Progress</li>
<li>PC Setup Designer</li>
<li>Gallery</li>
</ul>
</div>
</div>
<h1 class="heading">Welcome to Aeron</h1>
<div style="height:100%"></div>
<footer>
<img src="./images/logo.png" width="150px" title="Aeron" alt="logo" class="footer-logo">
<p class="copyright">Copyright © 2022 Aeron Corporation</p>
<div class="footer-links">
About Us
<p>|</p>
Policy
<p>|</p>
Contact Us
</div>
</footer>
<button onclick="topFunction()" id="return" title="Return To Top">^</button>
<script>
let mybutton = document.getElementById("return");
window.onscroll = function() {scrollFunction()};
function scrollFunction() {
if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
mybutton.style.display = "block";
} else {
mybutton.style.display = "none";
}
}
function topFunction() {
document.body.scrollTop = 0;
}
function openNav() {
document.getElementById("mySidenav").style.width = "25%";
}
function closeNav() {
document.getElementById("mySidenav").style.width = "0";
}
</script>
</body>
</html>
i made a slidermenu, but i failed some stuff. I dont know how to make it sticky. but the biggest problem is that it looks wheird when i add it to my main file. it works fine when i run the slidebar on a clear page but when i implemnt it into this file it looks crazy. the sysmbols r not infront of the text anymore.
can anyone tell me how i can add the slidermenu to this file right
<!doctype html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<script src="../js/jquery-3.5.1.min.js"></script>
<link rel="stylesheet" href="../css/stylesearch.css">
<link rel="icon" href="../images/logo.ico">
<link rel="stylesheet" href="../css/slidebar.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<title>Search</title>
</head>
<body>
<div id="background-box" onclick="tag()"></div>
<div class="container" id="tag-box">
<div><a class="close-box" onclick="tag(), getValue()">×</a></div>
<br>Selectable Tags:</br>
</div>
<nav>
<script src="../js/slidebar.js"></script>
<img class="image-size" src="../images/logo.png">
<div class="bars"><i class="fa fa-bars fa-4x" id="scale" onclick="slidebar()"></i></div>
<a><img class="image-size" src="../images/menu.png" onclick=""></a>
<button id="btnabout" onclick="tag()">Tags</button>
<div class="search_box"><input type="text" name="box" id="search_text" placeholder="Search by name" class="form-control" /></div>
<div id="background-boxtitle" onclick="tag()"></div>
</nav>
<section class="sec1">
<div class="slidebar" id="slidebar"><?php include '../db/slidebar.php'; echo $slidebarbutton;?></div>
</section>
<section class="sec2">
<script src="../js/search.js"></script>
<div id="result"></div>
<div style="clear:both"></div>
</section>
<section class="sec3">
</section>
</body>
</html>
:root {
--slidermenu-color: #303030;
}
#slidebar{
position:absolute;
left:-15%;
width: 15%;
height: 100%;
transition: .5s;
background: var(--slidermenu-color);
overflow: scroll;
overflow-x: hidden;
}
#slidebar.active{
left: 0%;
}
#slidebarlock{
position: absolute;
left: -100%;
width: 85%;
height: 100%;
background: transparent;
transition: .5s;
}
#slidebarlock.active{
left: 15%;
}
.slidebarbutton {
background-color: #303030;
border: none;
color: white;
text-align: left;
text-decoration: none;
display: inline-block;
font-size: 30px;
cursor: pointer;
padding: 20px 0px;
width: 100%;
}
.slidebarbutton:hover{
background-color: #494949;
}
.bars:hover{
cursor: pointer;
}
.slidebarbutton div i{
padding-left:20px;
padding-right: 40px;
}
#slidebar::-webkit-scrollbar {
width: 5px;
}
#slidebar::-webkit-scrollbar-track {
background: var(--slidermenu-color);
}
#slidebar::-webkit-scrollbar-thumb {
background: transparent;
}
#slidebar:hover::-webkit-scrollbar-thumb{
background: black;
opacity: .8;
border-radius: 30px;
}
body{
margin: 0;
padding: 0;
font-family: sans-serif;
background: #222;;
}
header{
padding: 10px 100px;
box-sizing: border-box;
}
section{
width: 100%;
height: 100vh;
}
section.sec1{
width: 100%;
height: 50px;
}
div.gallery:hover {
border: 2px solid #404040;
background: #404040;
}
div.gallery {
margin: 5px;
border: 2px solid #222;
float: left;
width: 215px;
height: 400px;
color: #fff;
}
div.gallery img {
width: 100%;
height: 80%;
}
div.desc {
padding: 15px;
text-align: center;
}
section.sec3{
padding: 100px;
box-sizing: border-box;
height: auto;
}
section.sec3 h2{
font-size: 3em;
margin:0;
padding: 0;
color: #fff;
}
nav{
width: 100%;
height: 120px;
background: url(../images/bg1.jpg);
position: sticky;
top: 0px;
}
nav ul{
display: flex;
}
.image-size{
position: absolute;
top: 10%;
right: 1%;
height: 40px;
}
.search_box{
position: absolute;
top: 20%;
left: 50%;
transform: translate(-150%, -50%);
height: 20px;
}
.search_box input[type="text"]{
width: 300%;
padding: 20px;
padding-right: 60px;
box-sizing: border-box;
background: rgba(0,0,0,0.3);
border: 2px solid #fff;
border-radius: 10px;
font-size: 18px;
color: #fff;
outline: none;
}
.fa-search{
position: absolute;
top: 50%;
transform: translateY(-50%);
right: 25px;
color: #fff;
font-size: 25px;
}
::-webkit-input-placeholder {
color: #fff;
}
::-moz-placeholder {
color: #fff;
}
:-ms-input-placeholder {
color: #fff;
}
#media screen and (max-width: 425px){
.search_box{
width: 95%;
}
}
#tag-box{
position: absolute;
top: -120%;
left: 20%;
width: 60%;
height: 500px;
background: #000;
transition: .5s;
opacity: 0.9;
border-radius: 30px;
}
#tag-box.active{
top: 25%;
}
.container{
max-width: 60%;
margin: 0 auto;
display: flex;
flex-wrap: wrap;
}
.container div{
margin: 5px;
}
.container div a{
font-size: 2em;
margin:0;
padding: 0;
color: #fff;
cursor: pointer;
}
.container div a:hover{
color: #f00;
}
.container div label{
cursor: pointer;
}
.container div label input[type="checkbox"]{
display: none;
}
.container div label span{
position: relative;
display: inline-block;
background: #424242;
color: #fff;
padding: 5px 10px;
color: 555;
text-shadow: 0 1px 4px rgba(0,0,0,.5);
border-radius: 15px;
font-size: 12px;
transition: 0.5s;
user-select: none;
overflow: hidden;
border: 2px solid #FFA500;
}
.container div label span:before{
content: '';
position: absolute;
top: absolute;
top: 0;
left: 0;
width: 100%;
height: 50%
}
.container div label input[type="checkbox"]:checked ~ span{
background: #FFA500;
color: #fff;
border: 2px solid #FFA500;
box-shadow: 0 2px 15px #FFA500;
}
#background-box {
position: absolute;
top: -120%;
left: 0%;
width: 100%;
height: 100%;
background: #000;
opacity: 0;
}
#background-box.active{
top: 0%;
}
#background-boxtitle {
position: absolute;
top: -120%;
left: 0%;
width: 100%;
height: 100%;
background: #000;
opacity: 0;
}
#background-boxtitle.active{
top: 0%;
}
#scale{
transition: .5s;
color:white;
transform: translate(22px, 16px);
}
#scale.active{
transition: .5s;
transform: translate(22px, 16px) rotate(90deg);
}
Ever since I added "position absoulte" to my div ".container" in my code below, my CSS animate code zooms in from the bottom then hiccups and positions itself to the center.
How can I make my animate zoom just zoom in right to the center without this hiccup where it goes down first then a second later it automatically moves to the center?
If I remove the position absolute from the .container div the animate zoom works just fine but it's not centered anymore vertically (just horizontally). The reason I used position absolute and left 0 and right 0 was to center it both ways.
Here is my code:
* {
box-sizing: border-box;
}
html,
body {
height: 100%;
margin: 0 auto;
color: white;
text-align: center;
font-family: 'Lato', serif;
background: linear-gradient(white 70px, #007580 70px);
-webkit-text-size-adjust: none;
}
header,
footer {
background: #007580
}
body,
main {
display: flex;
flex: 1;
}
body {
flex-flow: column;
}
header {
min-height: 35px;
}
footer {
min-height: 35px;
}
section {
margin: auto;
width: 95%;
height: 100%;
color: black;
background-color: white;
}
.categories {
position: relative;
top: 3px;
color: white;
font-size: 16px;
font-weight: 300;
word-spacing: 26px;
padding-bottom: 2px;
}
.categories a {
text-decoration: none;
color: inherit;
}
.legal {
position: absolute;
bottom: 0;
width: 100%;
height: 30px;
font-weight: 300;
word-spacing: 15px;
}
.legal a {
text-decoration: none;
font-size: 14px;
color: white;
}
.quote {
position: relative;
margin: auto;
font-size: 20px;
font-weight: 300;
bottom: 80px;
height: 0;
}
.searchcontainer {
position: relative;
height: 0;
bottom: 43px;
margin: auto;
width: 380px;
;
}
input[type=text] {
width: 100%;
display: inline-block;
border: 2px solid #ddd;
border-radius: 4px;
padding: 6px 0 7px 40px;
background-image: url('https://image.ibb.co/j9esac/searchicon.png');
background-position: 10px 6px;
background-repeat: no-repeat;
font-size: 16px;
background-color: white;
}
.innercircle {
height: 89px;
width: 89px;
border-radius: 50%;
background-color: white;
margin: auto;
position: relative;
bottom: 93px;
}
.outercircle {
height: 120px;
width: 120px;
border-radius: 50%;
background-color: #007580;
margin: auto;
position: relative;
top: 11px;
}
.D {
font-size: 100px;
font-weight: 100;
position: relative;
bottom: 196px;
right: 3px;
margin: auto;
color: #007580;
height: 0;
font-family: 'Amiri', serif;
letter-spacing: -10px;
}
.D a {
text-decoration: none;
color: inherit;
}
.R {
font-size: 55px;
font-weight: 100;
position: relative;
bottom: 173px;
right: 2px;
margin: auto;
color: #007580;
height: 0;
font-family: 'Amiri', serif;
letter-spacing: -10px;
}
.R a {
text-decoration: none;
color: inherit;
}
.ICONwhatsnew {
position: relative;
margin: auto;
bottom: 194px;
right: 191px;
width: 0;
display: block;
height: 0;
}
.ICONwhatsnew a {
text-decoration: none;
color: inherit;
}
.ICONworldlanguages {
position: relative;
margin: auto;
bottom: 190px;
right: 116px;
width: 0;
display: block;
height: 0;
}
.ICONworldlanguages a {
text-decoration: none;
color: inherit;
}
.ICONsignin {
position: relative;
margin: auto;
bottom: 192px;
left: 83px;
width: 0;
display: block;
height: 0;
}
.ICONsignin a {
text-decoration: none;
color: inherit;
}
.ICONcart {
position: relative;
margin: auto;
bottom: 192px;
left: 149px;
width: 0;
display: block;
height: 0;
}
.ICONcart a {
text-decoration: none;
color: inherit;
}
.container {
font-size: 17px;
font-weight: 400;
color: #007580;
top: 50%;
left: 0;
right: 0;
position: absolute;
}
input[type=unams] {
width: 80%;
padding: 12px 45px;
margin: 22px 0 0 0;
border: 1px solid #007580;
box-sizing: border-box;
border-radius: 0px;
-webkit-appearance: none;
font-size: 17px;
background-image: url('https://image.ibb.co/fZHHnc/signin.png');
background-position: 10px 8px;
background-repeat: no-repeat;
background-size: 25px;
}
input[type=password] {
width: 80%;
padding: 12px 45px;
/* first is how big you want the input box 2nd is positioning of word password */
margin: 22px 0 15px 0;
border: 1px solid #007580;
box-sizing: border-box;
border-radius: 0px;
-webkit-appearance: none;
font-size: 17px;
background-image: url('https://image.ibb.co/jC7gfx/lock.png');
background-position: 10px 8px;
background-repeat: no-repeat;
background-size: 25px;
}
.buttonlg {
background-color: #007580;
border: none;
color: white;
width: 25%;
font-size: 17px;
height: 38px;
margin: auto;
text-align: center;
}
.outerform {
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}
.innerform {
width: 90%;
height: 90%;
}
.box {
background-color: white;
border: 1px solid #007580;
height: 100%;
}
.animate {
-webkit-animation: animatezoom 0.6s;
animation: animatezoom 0.6s
}
#-webkit-keyframes animatezoom {
from {
-webkit-transform: scale(0)
}
to {
-webkit-transform: scale(1)
}
}
::-webkit-input-placeholder {
/* WebKit browsers */
color: lightgrey;
opacity: 1 !important;
}
.circlelogo1 {
background: #007580;
border-radius: 50%;
height: 30px;
width: 30px;
position: relative;
margin: auto;
/*
Child elements with absolute positioning will be
positioned relative to this div
*/
}
.circlelogo2 {
position: absolute;
background: white;
border-radius: 50%;
height: 18px;
width: 18px;
/*
Put top edge and left edge in the center
*/
top: 50%;
left: 50%;
margin: -9px 0px 0px -9px;
/*
Offset the position correctly with
minus half of the width and minus half of the height
*/
}
<div class="outercircle"></div>
<div class="innercircle"></div>
<div class="D">
D
</div>
<div class="R">
R
</div>
<div class="quote">
You will always be your greatest investment.
</div>
<div class="searchcontainer">
<form>
<input name="search" placeholder="Search all resources..." type="text">
</form>
</div>
<div class="ICONsignin">
<img height="37px" src="https://svgshare.com/i/5SR.svg">
</div>
<div class="ICONcart">
<img height="39px" src="https://svgshare.com/i/5SE.svg">
</div>
<div class="ICONworldlanguages">
<img height="34px" src="https://svgshare.com/i/5XW.svg">
</div>
<div class="ICONwhatsnew">
<img height="43px" src="https://svgshare.com/i/5aX.svg">
</div>
<header>
<div class="categories">
<b>Categories</b> Newest Popular Music Youth
</div>
</header>
<main>
<section>
<div class="outerform">
<div class="innerform">
<form class="animate box">
<div class="container">
<div class="circlelogo1">
<div class="circlelogo2">
</div>
</div>
<input type="unams" placeholder="Username" name="uname" required>
<input type="password" placeholder="Password" name="psw" required><br>
<button class="buttonlg" type="submit">Log In</button>
</div>
</form>
</div>
</div>
</section>
</main>
<footer>
<div class="legal">
Contact Privacy Terms Copyright About
</div>
</footer>
You are using position:absolute and the parent element is not set with relative so the form is not relative to the scaled container which is creating this issue. You need to set position:relative to the parent container and then adjust the centering:
.box {
...
position:relative; /*Added this*/
}
.container {
...
transform:translate(0,-50%); /*Added this*/
top: 50%;
...
}
Here is the full code:
* {
box-sizing: border-box;
}
html,
body {
height: 100%;
margin: 0 auto;
color: white;
text-align: center;
font-family: 'Lato', serif;
background: linear-gradient(white 70px, #007580 70px);
-webkit-text-size-adjust: none;
}
header,
footer {
background: #007580
}
body,
main {
display: flex;
flex: 1;
}
body {
flex-flow: column;
}
header {
min-height: 35px;
}
footer {
min-height: 35px;
}
section {
margin: auto;
width: 95%;
height: 100%;
color: black;
background-color: white;
}
.categories {
position: relative;
top: 3px;
color: white;
font-size: 16px;
font-weight: 300;
word-spacing: 26px;
padding-bottom: 2px;
}
.categories a {
text-decoration: none;
color: inherit;
}
.legal {
position: absolute;
bottom: 0;
width: 100%;
height: 30px;
font-weight: 300;
word-spacing: 15px;
}
.legal a {
text-decoration: none;
font-size: 14px;
color: white;
}
.quote {
position: relative;
margin: auto;
font-size: 20px;
font-weight: 300;
bottom: 80px;
height: 0;
}
.searchcontainer {
position: relative;
height: 0;
bottom: 43px;
margin: auto;
width: 380px;
;
}
input[type=text] {
width: 100%;
display: inline-block;
border: 2px solid #ddd;
border-radius: 4px;
padding: 6px 0 7px 40px;
background-image: url('https://image.ibb.co/j9esac/searchicon.png');
background-position: 10px 6px;
background-repeat: no-repeat;
font-size: 16px;
background-color: white;
}
.innercircle {
height: 89px;
width: 89px;
border-radius: 50%;
background-color: white;
margin: auto;
position: relative;
bottom: 93px;
}
.outercircle {
height: 120px;
width: 120px;
border-radius: 50%;
background-color: #007580;
margin: auto;
position: relative;
top: 11px;
}
.D {
font-size: 100px;
font-weight: 100;
position: relative;
bottom: 196px;
right: 3px;
margin: auto;
color: #007580;
height: 0;
font-family: 'Amiri', serif;
letter-spacing: -10px;
}
.D a {
text-decoration: none;
color: inherit;
}
.R {
font-size: 55px;
font-weight: 100;
position: relative;
bottom: 173px;
right: 2px;
margin: auto;
color: #007580;
height: 0;
font-family: 'Amiri', serif;
letter-spacing: -10px;
}
.R a {
text-decoration: none;
color: inherit;
}
.ICONwhatsnew {
position: relative;
margin: auto;
bottom: 194px;
right: 191px;
width: 0;
display: block;
height: 0;
}
.ICONwhatsnew a {
text-decoration: none;
color: inherit;
}
.ICONworldlanguages {
position: relative;
margin: auto;
bottom: 190px;
right: 116px;
width: 0;
display: block;
height: 0;
}
.ICONworldlanguages a {
text-decoration: none;
color: inherit;
}
.ICONsignin {
position: relative;
margin: auto;
bottom: 192px;
left: 83px;
width: 0;
display: block;
height: 0;
}
.ICONsignin a {
text-decoration: none;
color: inherit;
}
.ICONcart {
position: relative;
margin: auto;
bottom: 192px;
left: 149px;
width: 0;
display: block;
height: 0;
}
.ICONcart a {
text-decoration: none;
color: inherit;
}
.container {
font-size: 17px;
font-weight: 400;
color: #007580;
transform:translate(0,-50%);
top: 50%;
left: 0;
right: 0;
position: absolute;
}
input[type=unams] {
width: 80%;
padding: 12px 45px;
margin: 22px 0 0 0;
border: 1px solid #007580;
box-sizing: border-box;
border-radius: 0px;
-webkit-appearance: none;
font-size: 17px;
background-image: url('https://image.ibb.co/fZHHnc/signin.png');
background-position: 10px 8px;
background-repeat: no-repeat;
background-size: 25px;
}
input[type=password] {
width: 80%;
padding: 12px 45px;
/* first is how big you want the input box 2nd is positioning of word password */
margin: 22px 0 15px 0;
border: 1px solid #007580;
box-sizing: border-box;
border-radius: 0px;
-webkit-appearance: none;
font-size: 17px;
background-image: url('https://image.ibb.co/jC7gfx/lock.png');
background-position: 10px 8px;
background-repeat: no-repeat;
background-size: 25px;
}
.buttonlg {
background-color: #007580;
border: none;
color: white;
width: 25%;
font-size: 17px;
height: 38px;
margin: auto;
text-align: center;
}
.outerform {
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}
.innerform {
width: 90%;
height: 90%;
}
.box {
background-color: white;
border: 1px solid #007580;
height: 100%;
position:relative;
}
.animate {
-webkit-animation: animatezoom 0.6s;
animation: animatezoom 0.6s
}
#-webkit-keyframes animatezoom {
from {
-webkit-transform: scale(0)
}
to {
-webkit-transform: scale(1)
}
}
::-webkit-input-placeholder {
/* WebKit browsers */
color: lightgrey;
opacity: 1 !important;
}
.circlelogo1 {
background: #007580;
border-radius: 50%;
height: 30px;
width: 30px;
position: relative;
margin: auto;
/*
Child elements with absolute positioning will be
positioned relative to this div
*/
}
.circlelogo2 {
position: absolute;
background: white;
border-radius: 50%;
height: 18px;
width: 18px;
/*
Put top edge and left edge in the center
*/
top: 50%;
left: 50%;
margin: -9px 0px 0px -9px;
/*
Offset the position correctly with
minus half of the width and minus half of the height
*/
}
<div class="outercircle"></div>
<div class="innercircle"></div>
<div class="D">
D
</div>
<div class="R">
R
</div>
<div class="quote">
You will always be your greatest investment.
</div>
<div class="searchcontainer">
<form>
<input name="search" placeholder="Search all resources..." type="text">
</form>
</div>
<div class="ICONsignin">
<img height="37px" src="https://svgshare.com/i/5SR.svg">
</div>
<div class="ICONcart">
<img height="39px" src="https://svgshare.com/i/5SE.svg">
</div>
<div class="ICONworldlanguages">
<img height="34px" src="https://svgshare.com/i/5XW.svg">
</div>
<div class="ICONwhatsnew">
<img height="43px" src="https://svgshare.com/i/5aX.svg">
</div>
<header>
<div class="categories">
<b>Categories</b> Newest Popular Music Youth
</div>
</header>
<main>
<section>
<div class="outerform">
<div class="innerform">
<form class="animate box">
<div class="container">
<div class="circlelogo1">
<div class="circlelogo2">
</div>
</div>
<input type="unams" placeholder="Username" name="uname" required>
<input type="password" placeholder="Password" name="psw" required><br>
<button class="buttonlg" type="submit">Log In</button>
</div>
</form>
</div>
</div>
</section>
</main>
<footer>
<div class="legal">
Contact Privacy Terms Copyright About
</div>
</footer>
By the way it's better to consider another way than positioned element to center. You can do it with flex since you are already using it:
.box {
....
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
Then remove everything related to positionning from .container.
Here is the full code:
* {
box-sizing: border-box;
}
html,
body {
height: 100%;
margin: 0 auto;
color: white;
text-align: center;
font-family: 'Lato', serif;
background: linear-gradient(white 70px, #007580 70px);
-webkit-text-size-adjust: none;
}
header,
footer {
background: #007580
}
body,
main {
display: flex;
flex: 1;
}
body {
flex-flow: column;
}
header {
min-height: 35px;
}
footer {
min-height: 35px;
}
section {
margin: auto;
width: 95%;
height: 100%;
color: black;
background-color: white;
}
.categories {
position: relative;
top: 3px;
color: white;
font-size: 16px;
font-weight: 300;
word-spacing: 26px;
padding-bottom: 2px;
}
.categories a {
text-decoration: none;
color: inherit;
}
.legal {
position: absolute;
bottom: 0;
width: 100%;
height: 30px;
font-weight: 300;
word-spacing: 15px;
}
.legal a {
text-decoration: none;
font-size: 14px;
color: white;
}
.quote {
position: relative;
margin: auto;
font-size: 20px;
font-weight: 300;
bottom: 80px;
height: 0;
}
.searchcontainer {
position: relative;
height: 0;
bottom: 43px;
margin: auto;
width: 380px;
;
}
input[type=text] {
width: 100%;
display: inline-block;
border: 2px solid #ddd;
border-radius: 4px;
padding: 6px 0 7px 40px;
background-image: url('https://image.ibb.co/j9esac/searchicon.png');
background-position: 10px 6px;
background-repeat: no-repeat;
font-size: 16px;
background-color: white;
}
.innercircle {
height: 89px;
width: 89px;
border-radius: 50%;
background-color: white;
margin: auto;
position: relative;
bottom: 93px;
}
.outercircle {
height: 120px;
width: 120px;
border-radius: 50%;
background-color: #007580;
margin: auto;
position: relative;
top: 11px;
}
.D {
font-size: 100px;
font-weight: 100;
position: relative;
bottom: 196px;
right: 3px;
margin: auto;
color: #007580;
height: 0;
font-family: 'Amiri', serif;
letter-spacing: -10px;
}
.D a {
text-decoration: none;
color: inherit;
}
.R {
font-size: 55px;
font-weight: 100;
position: relative;
bottom: 173px;
right: 2px;
margin: auto;
color: #007580;
height: 0;
font-family: 'Amiri', serif;
letter-spacing: -10px;
}
.R a {
text-decoration: none;
color: inherit;
}
.ICONwhatsnew {
position: relative;
margin: auto;
bottom: 194px;
right: 191px;
width: 0;
display: block;
height: 0;
}
.ICONwhatsnew a {
text-decoration: none;
color: inherit;
}
.ICONworldlanguages {
position: relative;
margin: auto;
bottom: 190px;
right: 116px;
width: 0;
display: block;
height: 0;
}
.ICONworldlanguages a {
text-decoration: none;
color: inherit;
}
.ICONsignin {
position: relative;
margin: auto;
bottom: 192px;
left: 83px;
width: 0;
display: block;
height: 0;
}
.ICONsignin a {
text-decoration: none;
color: inherit;
}
.ICONcart {
position: relative;
margin: auto;
bottom: 192px;
left: 149px;
width: 0;
display: block;
height: 0;
}
.ICONcart a {
text-decoration: none;
color: inherit;
}
.container {
font-size: 17px;
font-weight: 400;
color: #007580;
}
input[type=unams] {
width: 80%;
padding: 12px 45px;
margin: 22px 0 0 0;
border: 1px solid #007580;
box-sizing: border-box;
border-radius: 0px;
-webkit-appearance: none;
font-size: 17px;
background-image: url('https://image.ibb.co/fZHHnc/signin.png');
background-position: 10px 8px;
background-repeat: no-repeat;
background-size: 25px;
}
input[type=password] {
width: 80%;
padding: 12px 45px;
/* first is how big you want the input box 2nd is positioning of word password */
margin: 22px 0 15px 0;
border: 1px solid #007580;
box-sizing: border-box;
border-radius: 0px;
-webkit-appearance: none;
font-size: 17px;
background-image: url('https://image.ibb.co/jC7gfx/lock.png');
background-position: 10px 8px;
background-repeat: no-repeat;
background-size: 25px;
}
.buttonlg {
background-color: #007580;
border: none;
color: white;
width: 25%;
font-size: 17px;
height: 38px;
margin: auto;
text-align: center;
}
.outerform {
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}
.innerform {
width: 90%;
height: 90%;
}
.box {
background-color: white;
border: 1px solid #007580;
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.animate {
-webkit-animation: animatezoom 0.6s;
animation: animatezoom 0.6s
}
#-webkit-keyframes animatezoom {
from {
-webkit-transform: scale(0)
}
to {
-webkit-transform: scale(1)
}
}
::-webkit-input-placeholder {
/* WebKit browsers */
color: lightgrey;
opacity: 1 !important;
}
.circlelogo1 {
background: #007580;
border-radius: 50%;
height: 30px;
width: 30px;
position: relative;
margin: auto;
/*
Child elements with absolute positioning will be
positioned relative to this div
*/
}
.circlelogo2 {
position: absolute;
background: white;
border-radius: 50%;
height: 18px;
width: 18px;
/*
Put top edge and left edge in the center
*/
top: 50%;
left: 50%;
margin: -9px 0px 0px -9px;
/*
Offset the position correctly with
minus half of the width and minus half of the height
*/
}
<div class="outercircle"></div>
<div class="innercircle"></div>
<div class="D">
D
</div>
<div class="R">
R
</div>
<div class="quote">
You will always be your greatest investment.
</div>
<div class="searchcontainer">
<form>
<input name="search" placeholder="Search all resources..." type="text">
</form>
</div>
<div class="ICONsignin">
<img height="37px" src="https://svgshare.com/i/5SR.svg">
</div>
<div class="ICONcart">
<img height="39px" src="https://svgshare.com/i/5SE.svg">
</div>
<div class="ICONworldlanguages">
<img height="34px" src="https://svgshare.com/i/5XW.svg">
</div>
<div class="ICONwhatsnew">
<img height="43px" src="https://svgshare.com/i/5aX.svg">
</div>
<header>
<div class="categories">
<b>Categories</b> Newest Popular Music Youth
</div>
</header>
<main>
<section>
<div class="outerform">
<div class="innerform">
<form class="animate box">
<div class="container">
<div class="circlelogo1">
<div class="circlelogo2">
</div>
</div>
<input type="unams" placeholder="Username" name="uname" required>
<input type="password" placeholder="Password" name="psw" required><br>
<button class="buttonlg" type="submit">Log In</button>
</div>
</form>
</div>
</div>
</section>
</main>
<footer>
<div class="legal">
Contact Privacy Terms Copyright About
</div>
</footer>
There's a few issues. In your .box styling you should add position: relative; this will force .container's absolute positioning to respect its parent, in this case .box's positioning and size. The second is the top: 50%; on .container. In certain scenarios that can seem to center the item but in others it does not. What you can do to center .container within .box is add transform: translate(0, -50%); which offsets top: 50% and centers the element. Same can be done horizontally with left: 50% and transform: translate(-50%, -50%);.
* {
box-sizing: border-box;
}
html,
body {
height: 100%;
margin: 0 auto;
color: white;
text-align: center;
font-family: 'Lato', serif;
background: linear-gradient(white 70px, #007580 70px);
-webkit-text-size-adjust: none;
}
header,
footer {
background: #007580
}
body,
main {
display: flex;
flex: 1;
}
body {
flex-flow: column;
}
header {
min-height: 35px;
}
footer {
min-height: 35px;
}
section {
margin: auto;
width: 95%;
height: 100%;
color: black;
background-color: white;
}
.categories {
position: relative;
top: 3px;
color: white;
font-size: 16px;
font-weight: 300;
word-spacing: 26px;
padding-bottom: 2px;
}
.categories a {
text-decoration: none;
color: inherit;
}
.legal {
position: absolute;
bottom: 0;
width: 100%;
height: 30px;
font-weight: 300;
word-spacing: 15px;
}
.legal a {
text-decoration: none;
font-size: 14px;
color: white;
}
.quote {
position: relative;
margin: auto;
font-size: 20px;
font-weight: 300;
bottom: 80px;
height: 0;
}
.searchcontainer {
position: relative;
height: 0;
bottom: 43px;
margin: auto;
width: 380px;
;
}
input[type=text] {
width: 100%;
display: inline-block;
border: 2px solid #ddd;
border-radius: 4px;
padding: 6px 0 7px 40px;
background-image: url('https://image.ibb.co/j9esac/searchicon.png');
background-position: 10px 6px;
background-repeat: no-repeat;
font-size: 16px;
background-color: white;
}
.innercircle {
height: 89px;
width: 89px;
border-radius: 50%;
background-color: white;
margin: auto;
position: relative;
bottom: 93px;
}
.outercircle {
height: 120px;
width: 120px;
border-radius: 50%;
background-color: #007580;
margin: auto;
position: relative;
top: 11px;
}
.D {
font-size: 100px;
font-weight: 100;
position: relative;
bottom: 196px;
right: 3px;
margin: auto;
color: #007580;
height: 0;
font-family: 'Amiri', serif;
letter-spacing: -10px;
}
.D a {
text-decoration: none;
color: inherit;
}
.R {
font-size: 55px;
font-weight: 100;
position: relative;
bottom: 173px;
right: 2px;
margin: auto;
color: #007580;
height: 0;
font-family: 'Amiri', serif;
letter-spacing: -10px;
}
.R a {
text-decoration: none;
color: inherit;
}
.ICONwhatsnew {
position: relative;
margin: auto;
bottom: 194px;
right: 191px;
width: 0;
display: block;
height: 0;
}
.ICONwhatsnew a {
text-decoration: none;
color: inherit;
}
.ICONworldlanguages {
position: relative;
margin: auto;
bottom: 190px;
right: 116px;
width: 0;
display: block;
height: 0;
}
.ICONworldlanguages a {
text-decoration: none;
color: inherit;
}
.ICONsignin {
position: relative;
margin: auto;
bottom: 192px;
left: 83px;
width: 0;
display: block;
height: 0;
}
.ICONsignin a {
text-decoration: none;
color: inherit;
}
.ICONcart {
position: relative;
margin: auto;
bottom: 192px;
left: 149px;
width: 0;
display: block;
height: 0;
}
.ICONcart a {
text-decoration: none;
color: inherit;
}
.container {
font-size: 17px;
font-weight: 400;
color: #007580;
top: 50%;
left: 0;
right: 0;
position: absolute;
transform: translate(0, -50%);
}
input[type=unams] {
width: 80%;
padding: 12px 45px;
margin: 22px 0 0 0;
border: 1px solid #007580;
box-sizing: border-box;
border-radius: 0px;
-webkit-appearance: none;
font-size: 17px;
background-image: url('https://image.ibb.co/fZHHnc/signin.png');
background-position: 10px 8px;
background-repeat: no-repeat;
background-size: 25px;
}
input[type=password] {
width: 80%;
padding: 12px 45px;
/* first is how big you want the input box 2nd is positioning of word password */
margin: 22px 0 15px 0;
border: 1px solid #007580;
box-sizing: border-box;
border-radius: 0px;
-webkit-appearance: none;
font-size: 17px;
background-image: url('https://image.ibb.co/jC7gfx/lock.png');
background-position: 10px 8px;
background-repeat: no-repeat;
background-size: 25px;
}
.buttonlg {
background-color: #007580;
border: none;
color: white;
width: 25%;
font-size: 17px;
height: 38px;
margin: auto;
text-align: center;
}
.outerform {
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}
.innerform {
width: 90%;
height: 90%;
}
.box {
position: relative;
background-color: white;
border: 1px solid #007580;
height: 100%;
}
.animate {
-webkit-animation: animatezoom 0.6s;
animation: animatezoom 0.6s
}
#-webkit-keyframes animatezoom {
from {
-webkit-transform: scale(0)
}
to {
-webkit-transform: scale(1)
}
}
::-webkit-input-placeholder {
/* WebKit browsers */
color: lightgrey;
opacity: 1 !important;
}
.circlelogo1 {
background: #007580;
border-radius: 50%;
height: 30px;
width: 30px;
position: relative;
margin: auto;
/*
Child elements with absolute positioning will be
positioned relative to this div
*/
}
.circlelogo2 {
position: absolute;
background: white;
border-radius: 50%;
height: 18px;
width: 18px;
/*
Put top edge and left edge in the center
*/
top: 50%;
left: 50%;
margin: -9px 0px 0px -9px;
/*
Offset the position correctly with
minus half of the width and minus half of the height
*/
}
<div class="outercircle"></div>
<div class="innercircle"></div>
<div class="D">
D
</div>
<div class="R">
R
</div>
<div class="quote">
You will always be your greatest investment.
</div>
<div class="searchcontainer">
<form>
<input name="search" placeholder="Search all resources..." type="text">
</form>
</div>
<div class="ICONsignin">
<img height="37px" src="https://svgshare.com/i/5SR.svg">
</div>
<div class="ICONcart">
<img height="39px" src="https://svgshare.com/i/5SE.svg">
</div>
<div class="ICONworldlanguages">
<img height="34px" src="https://svgshare.com/i/5XW.svg">
</div>
<div class="ICONwhatsnew">
<img height="43px" src="https://svgshare.com/i/5aX.svg">
</div>
<header>
<div class="categories">
<b>Categories</b> Newest Popular Music Youth
</div>
</header>
<main>
<section>
<div class="outerform">
<div class="innerform">
<form class="animate box">
<div class="container">
<div class="circlelogo1">
<div class="circlelogo2">
</div>
</div>
<input type="unams" placeholder="Username" name="uname" required>
<input type="password" placeholder="Password" name="psw" required><br>
<button class="buttonlg" type="submit">Log In</button>
</div>
</form>
</div>
</div>
</section>
</main>
<footer>
<div class="legal">
Contact Privacy Terms Copyright About
</div>
</footer>
I am designing a homepage template. When I finished with my center content I started making the footer. I quickly realized my footer is not at the bottom of the page but instead inside the center content and cannot figure out why.
HTML:
<!DOCTYPE html>
<head>
<meta charset="utf-8" />
<link rel="stylesheet" type="text/css" href="file://C:/Workspace/MyWeblogicWorkspace/Purify/WebContent/CSS/index.css">
<link href='https://fonts.googleapis.com/css?family=PT+Sans:400,700' rel='stylesheet' type='text/css'>
</head>
<body>
<div id="header">
<div id="navigationBar">
<ul id="navigationBarList">
<li><a id="test" href="http://www.google.com">Home</a></li>
<li>About</li>
<li>Services</li>
<li>Contact</li>
</ul>
</div><!-- end of navigationBar -->
</div><!-- end of header -->
<div id="center">
<p id="title">*******************</p>
<p id="slogan">*******************</p>
<div id="centerContent">
<div id="contentOneBox">
<p id="contentOneTitle">*******************</p>
<p id="contentOneText">*******************!</p>
</div><!-- end of contentOneBox -->
<div id="contentTwoBox">
<p id="contentTwoTitle">*******************</p>
<p id="contentTwoText">**************************************.</p>
</div><!-- end of contentTwoBox -->
<div id="contentThreeBox">
<p id="contentThreeTitle">*******************</p>
<p id="contentThreeText">**************************************.</p>
</div><!-- end of contentThreeBox -->
<div id="contentFourBox">
<p id="contentFourTitle">*******************</p>
<p id="contentFourText">**************************************.</p>
</div><!-- end of contentFourBox -->
</div><!-- end of centerContent -->
</div><!-- end of center -->
<div id="footer">
<p id="contact">*******************</p>
<p id="copyright">*******************</p>
</div><!-- end of footer -->
</body>
</html>
CSS:
* {
padding: 0;
margin: 0;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
body {
font-size: 62.5%;
font-family: 'PT Sans', sans-serif;
color: #221F51;
}
#header {
display: block;
position: relative;
top: 0;
right: 0;
left: 0;
z-index: 9999;
margin: 0;
width: 100%;
min-width: 1024px;
height: 48px;
max-height: 44px;
background: #333;
background: rgba(0,0,0,0.8);
font-size: 18px;
-webkit-user-select: none;
}
#navigationBar {
display: block;
margin: 0 auto;
padding: 0 auto;
position: relative;
text-align: center;
}
#navigationBar ul li {
display: inline-block;
margin: 0 auto;
padding: 10px;
padding-left: 20px;
padding-right: 20px;
}
#navigationBar ul li a {
color: white;
margin: 0 auto;
padding: 0 auto;
text-decoration: none;
}
#navigationBar ul li a:hover {
color: gray;
}
#center {
display: block;
font-size: 18px;
position: relative;
}
#title {
display: block;
font-size: 48px;
letter-spacing: 3px;
margin-top: 25px;
padding: 25px;
position: relative;
text-align: center;
}
#slogan {
display: block;
font-size: 22px;
margin: 0 auto;
padding: 0 auto;
position: relative;
text-align: center;
}
#centerContent {
display: block;
font-size: 22px;
margin: 0 auto;
padding: 0 auto;
position: relative;
width: 990px;
}
#contentOneBox {
border: 1px solid black;
border-radius: 15px;
display: block;
float: left;
margin: 50px;
padding: 0px;
position: relative;
width: 350px;
}
#contentOneTitle {
background: #333;
background: rgba(0,0,0,0.8);
border-top-left-radius: 15px;
border-top-right-radius: 15px;
color: white;
display: block;
letter-spacing: 2px;
margin: 0;
padding: 2px;
position: relative;
text-align: center;
}
#contentOneText {
border-bottom-left-radius: 15px;
border-bottom-right-radius: 15px;
display: block;
height: 97px;
padding: 5px;
position: relative;
text-align: center;
}
#contentTwoBox {
border: 1px solid black;
border-radius: 15px;
display: block;
float: right;
margin: 50px;
padding: 0px;
position: relative;
width: 350px;
}
#contentTwoTitle {
background: #333;
background: rgba(0,0,0,0.8);
border-top-left-radius: 15px;
border-top-right-radius: 15px;
color: white;
display: block;
letter-spacing: 2px;
margin: 0;
padding: 2px;
position: relative;
text-align: center;
}
#contentTwoText {
border-bottom-left-radius: 15px;
border-bottom-right-radius: 15px;
display: block;
height: 97px;
padding: 5px;
position: relative;
text-align: center;
}
#contentThreeBox {
border: 1px solid black;
border-radius: 15px;
display: block;
float: left;
margin: 50px;
padding: 0px;
position: relative;
width: 350px;
}
#contentThreeTitle {
background: #333;
background: rgba(0,0,0,0.8);
border-top-left-radius: 15px;
border-top-right-radius: 15px;
color: white;
display: block;
letter-spacing: 2px;
margin: 0;
padding: 2px;
position: relative;
text-align: center;
}
#contentThreeText {
border-bottom-left-radius: 15px;
border-bottom-right-radius: 15px;
display: block;
height: 97px;
padding: 5px;
position: relative;
text-align: center;
}
#contentFourBox {
border: 1px solid black;
border-radius: 15px;
display: block;
float: right;
margin: 50px;
padding: 0px;
position: relative;
width: 350px;
}
#contentFourTitle {
background: #333;
background: rgba(0,0,0,0.8);
border-top-left-radius: 15px;
border-top-right-radius: 15px;
color: white;
display: block;
letter-spacing: 2px;
margin: 0;
padding: 2px;
position: relative;
text-align: center;
}
#contentFourText {
border-bottom-left-radius: 15px;
border-bottom-right-radius: 15px;
display: block;
height: 97px;
padding: 5px;
position: relative;
text-align: center;
}
#footer {
background-color: #f2f2f2;
display: block;
position: relative;
margin: 0;
width: 100%;
min-width: 1024px;
font-size: 14px;
-webkit-user-select: none;
}
#contact {
display: block;
position: relative;
text-align: center;
}
#copyright {
display: block;
position: relative;
text-align: center;
}
Here's fiddle : https://jsfiddle.net/c74dy9dj/
Try to add clear: both; to footer CSS:
#footer {
background-color: #f2f2f2;
display: block;
position: relative;
margin: 0;
width: 100%;
min-width: 1024px;
font-size: 14px;
-webkit-user-select: none;
border: 1px gray dotted;
background-color: rgba(120,120,120,.5);
clear: both; /* <-- check this out! */
}
You're using floats which causes elements after a floating element to flow around it.
Here is a good explanation
https://css-tricks.com/almanac/properties/c/clear/
You can fix this by adding "clear: both" to #footer
#footer {
clear:both;
}
I'm trying to make a timeline in pure CSS however I seem to be running into some problems.
When I try to set the timeline div as overflow-x: scroll it still scrolls on the y access.
This is what I've got:
#timeline {
height: 500px;
width: auto;
margin: 0;
background: red;
}
.event {
height: 500px;
}
.founded {
width: 400px;
float: left;
background: blue;
}
.grant {
width: 800px;
background: yellow;
}
<ol id="timeline">
<li class="event founded"></li>
<li class="event grant"></li>
</ol>
I just want each additional entry to follow the previous one and for it all be scroll-able horizontally. If anyone could point me in the right direction that would be amazing.
Thanks.
I literally JUST had to make one of these. This is what I came up with:
body {
padding: 25px;
font-family: sans-serif;
}
.timeline {
white-space: nowrap;
overflow-x: scroll;
padding: 30px 0 10px 0;
position: relative;
}
.entry {
display: inline-block;
vertical-align: top;
background: #13519C;
color: #fff;
padding: 10px;
font-size: 12px;
text-align: center;
position: relative;
border-top: 4px solid #06182E;
border-radius: 3px;
min-width: 200px;
max-width: 500px;
}
.entry img {
display: block;
max-width: 100%;
height: auto;
margin-bottom: 10px;
}
.entry:after {
content: '';
display: block;
background: #eee;
width: 7px;
height: 7px;
border-radius: 6px;
border: 3px solid #06182E;
position: absolute;
left: 50%;
top: -30px;
margin-left: -6px;
}
.entry:before {
content: '';
display: block;
background: #06182E;
width: 5px;
height: 20px;
position: absolute;
left: 50%;
top: -20px;
margin-left: -2px;
}
.entry h1 {
color: #fff;
font-size: 18px;
font-family: Georgia, serif;
font-weight: bold;
margin-bottom: 10px;
}
.entry h2 {
letter-spacing: .2em;
margin-bottom: 10px;
font-size: 14px;
}
.bar {
height: 4px;
background: #eee;
width: 100%;
position: relative;
top: 13px;
left: 0;
}
<div class="bar"></div>
<div class="timeline">
<div class="entry">
<h1>1990</h1>
<h2>Entry Title</h2>
<img src="http://dummyimage.com/300x200/000/fff" /> Here's the info about this date
</div>
<div class="entry">
<h1>1995</h1>
Here's the info about this date
</div>
<div class="entry">
<h1>2000</h1>
Here's the info about this date
</div>
<div class="entry">
<h1>2005</h1>
Here's the info about this date
</div>
<div class="entry">
<h1>2010</h1>
Here's the info about this date
</div>
</div>
You can refer the below link also
#import url(https://fonts.googleapis.com/css?family=Dosis:500);
body{
background: #F1F1F1;
}
.container{
width: 1200px;
margin: auto;
}
.timeline{
counter-reset: year 2016;
position: relative;
}
.timeline li{
list-style: none;
float: left;
width: 33.3333%;
position: relative;
text-align: center;
text-transform: uppercase;
font-family: 'Dosis', sans-serif;
}
ul:nth-child(1){
color: #4caf50;
}
.timeline li:before{
counter-increment: year;
content: counter(year);
width: 50px;
height: 50px;
border: 3px solid #4caf50;
border-radius: 50%;
display: block;
text-align: center;
line-height: 50px;
margin: 0 auto 10px auto;
background: #F1F1F1;
color: #000;
transition: all ease-in-out .3s;
cursor: pointer;
}
.timeline li:after{
content: "";
position: absolute;
width: 100%;
height: 1px;
background-color: grey;
top: 25px;
left: -50%;
z-index: -999;
transition: all ease-in-out .3s;
}
.timeline li:first-child:after{
content: none;
}
.timeline li.active{
color: #555555;
}
.timeline li.active:before{
background: #4caf50;
color: #F1F1F1;
}
.timeline li.active + li:after{
background: #4caf50;
}
<h1>DevelopersTips</h1>
<div class="container">
<ul class="timeline">
<li class="active">Bacon</li>
<li>Rib</li>
<li>Sausage</li>
</ul>
</div>