I've been putting a website portfolio together for myself and I just got my home page done. I will say this because it pertains to my problem, I put a div after the header which includes my vertical navigation on the right side, a paragraph that I wanted next to the nav and a background image(id=background).I did this because I only wanted the image to cover the space between the header and the bottom of the page. I noticed every time the paragraph(p) went next to the nav, it would push the nav down. I got a tip from a different post to make the position absolute, which worked. I am now trying to make my home page a responsive web page for tablet and mobile and ran into a problem. I changed the nav to horizontal navigation below the header when changing the position of p to absolute, it stretches the nav space.(as you can see if you resize the page). Is there a way I can move the paragraph out of the div but still keep it in the same place on the regular page?
Here is my code:-
#import url('https://fonts.googleapis.com/css?family=Fjalla+One');
#import url('https://fonts.googleapis.com/css?family=Titillium+Web');
#import url('https://fonts.googleapis.com/css?family=Fira+Sans');
#import url('https://fonts.googleapis.com/css?family=Lobster');
#import url('https://fonts.googleapis.com/css?family=Overlock');
* {
margin: 0;
padding: 0;
}
#wrapper {
margin: 0 auto;
padding: 0;
}
#background {
display: block;
background-image: url(images/Untitled-1.jpg);
background-repeat: no-repeat;
background-size: contain;
overflow: auto;
height: 100%;
width: 100%;
}
header {
background: rgb(115, 78, 116);
width: auto;
padding: 1%;
}
p {
width: 20%;
font-size: 20px;
color: antiquewhite;
padding: 0;
margin: 0 auto;
position: absolute;
margin-left: 50%;
font-family: 'Overlock', sans-serif;
font-style: normal;
margin-top: 15%;
}
.icon {
list-style-type: none;
display: inline;
}
.list {
display: inline-block;
font-family: 'Fira Sans', sans-serif;
margin-right: 1%;
}
i {
display: inline;
}
body {
background-color: black;
margin: 0;
padding: 0;
}
footer {
color: antiquewhite;
margin: 0;
padding: 0;
}
.h1 {
font-family: 'Fjalla One', sans-serif;
color: floralwhite;
font-size: 300%;
display: inline;
padding-right: 300px;
font-weight: bolder;
}
.name {
font-family: 'Lobster', sans-serif;
color: floralwhite;
display: inline;
font-weight: normal;
}
nav {
float: right;
}
.stretch {
list-style-type: none;
padding: 20px;
margin: 20px 0px;
border-radius: 50px 0px 0px 50px;
width: 250px;
height: 50px;
text-align: center;
text-shadow: 2px 2px black;
font-size: 150%;
font-family: 'Fjalla One', sans-serif;
background-color: rgb(40, 31, 17);
position: relative;
-webkit-transform: perspective(1px) translateZ(0);
transform: perspective(1px) translateZ(0);
box-shadow: 0 0 1px transparent;
-webkit-transition-property: color;
transition-property: color;
-webkit-transition-duration: 0.5s;
transition-duration: 0.5s;
}
.stretch:before {
content: "";
position: absolute;
z-index: -1;
top: 0;
left: 0;
right: 0;
bottom: 0;
border-radius: 50px 0px 0px 50px;
background: rgb(91, 56, 29);
-webkit-transform: scaleX(0);
transform: scaleX(0);
-webkit-transform-origin: 100% 50%;
transform-origin: 100% 50%;
-webkit-transition-property: transform;
transition-property: transform;
-webkit-transition-duration: 0.5s;
transition-duration: 0.5s;
-webkit-transition-timing-function: ease-out;
transition-timing-function: ease-out;
}
a:link,
a:visited,
a:hover,
a:active {
text-decoration: none;
color: antiquewhite;
}
.stretch:hover:before,
.stretch:focus:before,
.stretch:active:before {
-webkit-transform: scaleX(1);
transform: scaleX(1);
-webkit-transition-timing-function: cubic-bezier(0.52, 1.64, 0.37, 0.66);
transition-timing-function: cubic-bezier(0.52, 1.64, 0.37, 0.66);
}
/* ----------- phone ----------- */
/* Portrait and Landscape */
#media screen and (min-width: 320px) and (max-width: 640px) {}
/* ----------- tablet ----------- */
#media only screen and (min-width: 768px) and (max-width: 1024px) {
/*changing nav to horizontal postion*/
nav,
nav ul,
nav li,
nav a {
display: inline;
float: none;
width: 100%;
margin: 0px auto;
padding: 0px;
text-align: center;
}
.stretch {
display: inline-block;
list-style-type: none;
padding: 10px;
margin: 0px 0px 0px 0px;
border-radius: 0px 0px 0px 0px;
width: auto;
height: auto;
text-align: center;
text-shadow: 2px 2px black;
font-size: 100%;
font-family: 'Fjalla One', sans-serif;
background-color: rgb(40, 31, 17);
position: static;
/* removing nav animation*/
-webkit-transform: none;
transform: none;
-webkit-transform-origin: none;
transform-origin: none;
-webkit-transition-property: none;
transition-property: none;
-webkit-transition-duration: none;
transition-duration: none;
-webkit-transition-timing-function: none;
transition-timing-function: none;
}
.stretch:hover:before,
.stretch:focus:before,
.stretch:active:before {
-webkit-transform: none;
transform: none;
-webkit-transition-timing-function: none;
transition-timing-function: none;
}
#background {
background-color: rgb(40, 31, 17);
width: 100%;
background-image: none;
}
/*trying to get the background to display correctly*/
body {
background-image: url(images/Profile_2.jpg);
background-size: auto;
background-repeat: no-repeat;
margin: 0;
padding: 0;
}
/*moving the paragraph to the left since image will not display*/
p {
width: 20%;
font-size: 40px;
color: antiquewhite;
padding: 0;
margin-top: 10%;
margin-right: 40%;
font-family: 'Overlock', sans-serif;
font-style: normal;
position: static;
}
}
<div id="wrapper">
<header>
<ul class="icon">
<li class="h1">Tavyon <span class="name">Richardson</span>
</li>
<li class="list">TavyonRichardson#yahoo.com<i class="material-icons">mail_outline</i>
</li>
<li class="list">989-285-5133<i class="material-icons">call</i>
</li>
<li class="list">Alma, Michigan<i class="material-icons">location_on</i>
</li>
</ul>
</header>
<div id="background">
<p><span>Hey!</span>Welcome to my webiste. Here, you can see everything from my life story, to my my recent projects and resume.</p>
<nav id="navbar">
<ul class="nav">
<li class="stretch">About me
</li>
<li class="stretch">Courses
</li>
<li class="stretch">Projects
</li>
<li class="stretch">Blog
</li>
<li class="stretch">Resume
</li>
</ul>
</nav>
</div>
</div>
Related
I am having an issue with my navbar, once I make the browser tab smaller, the text stays the same size but the logo gets smaller and smaller and disappears. How can I make it so everything gets smaller? If any more information is needed I will provide them. Here are some examples of my problem.
100% width page vs Page made smaller for smaller screens for example
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Poppins', sans-serif;
}
/* custom scroll bar */
::-webkit-scrollbar {
width: 10px;
}
::-webkit-scrollbar-track {
background: #f1f1f1;
}
::-webkit-scrollbar-thumb {
background: #888;
}
::selection {
background: rgb(0, 123, 255, 0.3);
}
.content {
max-width: 1250px;
margin: auto;
padding: 0 30px;
}
/* Nav start*/
.navbar {
position: fixed;
width: 100%;
z-index: 2;
padding: 25px 0;
transition: all 0.3s ease;
background-color: black;
}
.navbar.sticky {
background: black;
padding: 10px 0;
box-shadow: 0px 3px 5px 0px rgba(0, 0, 0, 0.1);
}
.navbar .content {
display: flex;
align-items: center;
justify-content: space-between;
}
.navbar .logo a {
color: #fff;
font-size: 30px;
font-weight: 600;
text-decoration: none;
}
.navbar .menu-list {
display: inline-flex;
}
.menu-list li {
list-style: none;
}
.menu-list li a {
color: #fff;
font-size: 18px;
font-weight: 500;
margin-left: 20px;
text-decoration: none;
transition: all 0.3s ease;
}
.menu-list li a:hover {
color: #007bff;
}
.banner {
height: 100vh;
background-position: center;
background-attachment: fixed;
}
.about {
padding: 30px 0;
}
.about .title {
font-size: 38px;
font-weight: 700;
}
.about p {
padding-top: 20px;
text-align: justify;
}
.icon {
color: #fff;
font-size: 20px;
cursor: pointer;
display: none;
}
.menu-list .cancel-btn {
position: absolute;
right: 30px;
top: 20px;
}
#media (max-width: 1230px) {
.content {
padding: 0 60px;
}
}
#media (max-width: 1100px) {
.content {
padding: 0 40px;
}
}
#media (max-width: 900px) {
.content {
padding: 0 30px;
}
}
#media (max-width: 868px) {
body.disabled {
overflow: hidden;
}
.icon {
display: block;
}
.icon.hide {
display: none;
}
.navbar .menu-list {
position: fixed;
height: 100vh;
width: 100%;
max-width: 400px;
left: -100%;
top: 0px;
display: block;
padding: 40px 0;
text-align: center;
background: #222;
transition: all 0.3s ease;
}
.navbar.show .menu-list {
left: 0%;
}
.navbar .menu-list li {
margin-top: 45px;
}
.navbar .menu-list li a {
font-size: 23px;
margin-left: -100%;
transition: 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}
.navbar.show .menu-list li a {
margin-left: 0px;
}
}
#media (max-width: 380px) {
.navbar .logo a {
font-size: 27px;
}
}
.cta {
padding: 9px 25px;
background-color: rgba(0, 136, 169, 1);
border: none;
border-radius: 50px;
cursor: pointer;
transition: background-color 0.3s ease 0s;
}
.cta:hover {
background-color: rgba(0, 136, 169, 0.8);
}
/* Nav end*/
<nav class="navbar">
<div class="content">
<div class="logo">
<img src="images/logo-villa-dor.jpg" width="100%">
</div>
<ul class="menu-list">
<div class="icon cancel-btn">
<i class="fas fa-times"></i>
</div>
<li>Fireplaces</li>
<li>Floorings</li>
<li>IronWorks</li>
<li>Ornaments</li>
<li>Woodwork</li>
<li>Radiators</li>
<li>Luminary</li>
<li>Miscellaneous</li>
</ul>
<div class="icon menu-btn">
<i class="fas fa-bars"></i>
</div>
</div>
</nav>
I think you're using #media wrong.
#media (max-width: 868px)
indicates that these styles will be applied when it has a max width of 868px. So for small screens you need to decrease the font-size in there.
#media (max-width: 868px) {
.navbar .menu-list li a{
font-size: 16px; // for example
margin-left: -100%;
transition: 0.6s cubic-bezier(0.68, -0.55, 0.265,
1.55);
}
}
I see some issues in your styles that have proven to be problematic for your design. For sake of demonstrating the media-queries behavior, I have deleted all your media queries and made just one that points to your <ul> and your logo, which appears to be the focal point in this example.
Please see the CSS changes I made between /* Media Start & /* Media End */. Also, my suggestion, if you are flexing the navbar, would be to use display: flex; instead of inline-flex. Then you can add justify-content: space-between; to properly align your nav components. Next, this is just out of preference, but I wouldn't suggest spacing your li's with margin-left because then you get left margin on your "Fireplaces" <li> which is just unnecessary margin. I used gap: 10px; as an alternative.
Please see the changes to the logo as well. With this correct structure for your media-queries, I believe it will be much easier for you to manipulate. Without being able to see your image or the size of it, it's challenging to give you an exact height & width so adjust the 25px around as necessary. Finally, setting font-sizes on logos or images won't be useful, unless there is a text element within the containing parent div of the image or logo.
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Poppins', sans-serif;
}
/* custom scroll bar */
::-webkit-scrollbar {
width: 10px;
}
::-webkit-scrollbar-track {
background: #f1f1f1;
}
::-webkit-scrollbar-thumb {
background: #888;
}
::selection{
background: rgb(0,123,255,0.3);
}
.content{
max-width: 1250px;
margin: auto;
padding: 0 30px;
}
/* Nav start*/
.navbar{
position: fixed;
width: 100%;
z-index: 2;
padding: 25px 0;
transition: all 0.3s ease;
background-color: black;
}
.navbar.sticky{
background: black;
padding: 10px 0;
box-shadow: 0px 3px 5px 0px rgba(0,0,0,0.1);
}
.navbar .content{
display: flex;
align-items: center;
justify-content: space-between;
}
.navbar .logo a{
color: #fff;
font-size: 30px;
font-weight: 600;
text-decoration: none;
}
.navbar .menu-list{
display: flex;
justify-content: space-between;
gap: 10px;
}
.menu-list li{
list-style: none;
}
.menu-list li a{
color: #fff;
font-size: 18px;
font-weight: 500;
text-decoration: none;
transition: all 0.3s ease;
}
.menu-list li a:hover{
color: #007bff;
}
.banner{
height: 100vh;
background-position: center;
background-attachment: fixed;
}
.about{
padding: 30px 0;
}
.about .title{
font-size: 38px;
font-weight: 700;
}
.about p{
padding-top: 20px;
text-align: justify;
}
.icon{
color: #fff;
font-size: 20px;
cursor: pointer;
display: none;
}
.menu-list .cancel-btn{
position: absolute;
right: 30px;
top: 20px;
}
.cta {
padding: 9px 25px;
background-color: rgba(0, 136, 169, 1);
border: none;
border-radius: 50px;
cursor: pointer;
transition: background-color 0.3s ease 0s;
}
.cta:hover {
background-color: rgba(0, 136, 169, 0.8);
}
/* Nav end*/
/* Media Start */
#media only screen and (max-width: 800px) {
ul.menu-list li a {
font-size: 10px;
}
.logo {
width: 25px;
height: 25px;
}
}
/* Media End */
<nav class="navbar">
<div class="content">
<div class="logo">
</div>
<ul class="menu-list">
<div class="icon cancel-btn">
<i class="fas fa-times"></i>
</div>
<li>Fireplaces</li>
<li>Floorings</li>
<li>IronWorks</li>
<li>Ornaments</li>
<li>Woodwork</li>
<li>Radiators</li>
<li>Luminary</li>
<li>Miscellaneous</li>
</ul>
<div class="icon menu-btn">
<i class="fas fa-bars"></i>
</div>
</div>
</nav>
EDIT:
.navbar .content {
display: flex;
align-items: baseline;
justify-content: space-between;
align-content: center;
}
Then I would add two media queries like so :
#media only screen and (max-width: 1060px) {
.menu-list li a {
font-size: 13px;
}
}
#media only screen and (max-width: 945px) {
.menu-list li a {
font-size: 11.5px;
}
}
so here is my problem. I have managed to put the image which is the logo at the left hand side of the header for both tablet and mobile version, however when I display it in the desktop version the logo is the left but not in the corner like I want it. I tried putting a right margin to it, but I think there is a better way to do it instead of doing that. the same thing happens with my ul list. it's in the right corner on both tablet and mobile but it is not in the desktop version. this is my code:
<!DOCTYPE html>
<html>
<link href='https://fonts.googleapis.com/css?family=Montserrat|Cardo' rel='stylesheet' type='text/css'>
<link href='style.css' rel='stylesheet' type='text/css'>
<script type="text/javascript" src="https://code.jquery.com/jquery-1.9.1.js"></script>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
.main_h {
position: fixed;
top: 0px;
max-height: 70px;
z-index: 999;
width: 100%;
padding-top: 17px;
background: none;
overflow: hidden;
-webkit-transition: all 0.3s;
transition: all 0.3s;
opacity: 0;
top: -100px;
padding-bottom: 6px;
font-family: "Montserrat", sans-serif;
}
#media only screen and (max-width: 766px) {
.main_h {
padding-top: 25px;
}
}
.open-nav {
max-height: 400px !important;
}
.open-nav .mobile-toggle {
transform: rotate(-90deg);
-webkit-transform: rotate(-90deg);
}
.sticky {
background-color: rgba(255, 255, 255, 0.93);
opacity: 1;
top: 0px;
border-bottom: 1px solid gainsboro;
}
.logo {
width: 150px;
font-size: 25px;
color: #8f8f8f;
text-transform: uppercase;
float: left;
display: block;
margin-top: 0;
line-height: 1;
margin-bottom: 10px;
}
#media only screen and (max-width: 766px) {
.logo {
float: none;
}
}
nav {
float: right;
width: 60%;
}
#media only screen and (max-width: 766px) {
nav {
width: 100%;
}
}
nav ul {
list-style: none;
overflow: hidden;
text-align: center;
float: right;
}
#media only screen and (max-width: 766px) {
nav ul {
padding-top: 10px;
margin-bottom: 22px;
float: left;
text-align: center;
width: 100%;
}
}
nav ul li {
display: inline-block;
margin-left: 35px;
line-height: 1.5;
text-align: center;
}
#media only screen and (max-width: 766px) {
nav ul li {
width: 100%;
padding: 7px 0;
margin: 0;
text-align: center;
}
}
nav ul a {
color: #000;
text-transform: uppercase;
font-size: 12px;
text-align: center;
}
.mobile-toggle {
display: none;
cursor: pointer;
font-size: 20px;
position: absolute;
right: 22px;
top: 0;
width: 30px;
-webkit-transition: all 200ms ease-in;
-moz-transition: all 200ms ease-in;
transition: all 200ms ease-in;
}
#media only screen and (max-width: 766px) {
.mobile-toggle {
display: block;
}
}
.mobile-toggle span {
width: 30px;
height: 4px;
margin-bottom: 6px;
border-radius: 1000px;
background: #8f8f8f;
display: block;
}
.row {
width: 100%;
max-width: 940px;
margin: 0 auto;
position: relative;
padding: 0 2%;
}
* {
box-sizing: border-box;
}
body {
color: #8f8f8f;
background: white;
font-family: "Cardo", serif;
font-weight: 300;
-webkit-font-smoothing: antialiased;
}
a {
text-decoration: none;
}
h1 {
font-size: 30px;
line-height: 1.8;
text-transform: uppercase;
font-family: "Montserrat", sans-serif;
}
p {
margin-bottom: 20px;
font-size: 17px;
line-height: 2;
}
.content {
padding: 50px 2% 250px;
}
.hero {
position: relative;
background: url(http://www.philippefercha.com/cd/toggle-menu-bg.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
background-size: cover;
text-align: center;
color: #fff;
padding-top: 110px;
min-height: 500px;
letter-spacing: 2px;
font-family: "Montserrat", sans-serif;
}
.hero h1 {
font-size: 50px;
line-height: 1.3;
}
.hero h1 span {
font-size: 25px;
color: #e8f380;
border-bottom: 2px solid #e8f380;
padding-bottom: 12px;
line-height: 3;
}
.mouse {
display: block;
margin: 0 auto;
width: 26px;
height: 46px;
border-radius: 13px;
border: 2px solid #e8f380;
position: absolute;
bottom: 40px;
position: absolute;
left: 50%;
margin-left: -26px;
}
.mouse span {
display: block;
margin: 6px auto;
width: 2px;
height: 2px;
border-radius: 4px;
background: #e8f380;
border: 1px solid transparent;
-webkit-animation-duration: 1s;
animation-duration: 1s;
-webkit-animation-fill-mode: both;
animation-fill-mode: both;
-webkit-animation-iteration-count: infinite;
animation-iteration-count: infinite;
-webkit-animation-name: scroll;
animation-name: scroll;
}
#-webkit-keyframes scroll {
0% {
opacity: 1;
-webkit-transform: translateY(0);
transform: translateY(0);
}
100% {
opacity: 0;
-webkit-transform: translateY(20px);
transform: translateY(20px);
}
}
#keyframes scroll {
0% {
opacity: 1;
-webkit-transform: translateY(0);
-ms-transform: translateY(0);
transform: translateY(0);
}
100% {
opacity: 0;
-webkit-transform: translateY(20px);
-ms-transform: translateY(20px);
transform: translateY(20px);
}
}
</style>
<body>
<header class="main_h">
<div class="row">
<img src = "logo.png" class="logo" href="#"></a>
<div class="mobile-toggle">
<span></span>
<span></span>
<span></span>
</div>
<nav>
<ul>
<li>Home</li>
<li>Abous Us</li>
<li>Contact Us</li>
</ul>
</nav>
</div> <!-- / row -->
</header>
<script>
// Sticky Header
$(window).scroll(function() {
if ($(window).scrollTop() > 100) {
$('.main_h').addClass('sticky');
} else {
$('.main_h').removeClass('sticky');
}
});
// Mobile Navigation
$('.mobile-toggle').click(function() {
if ($('.main_h').hasClass('open-nav')) {
$('.main_h').removeClass('open-nav');
} else {
$('.main_h').addClass('open-nav');
}
});
$('.main_h li a').click(function() {
if ($('.main_h').hasClass('open-nav')) {
$('.navigation').removeClass('open-nav');
$('.main_h').removeClass('open-nav');
}
});
// navigation scroll lijepo radi materem
$('nav a').click(function(event) {
var id = $(this).attr("href");
var offset = 70;
var target = $(id).offset().top - offset;
$('html, body').animate({
scrollTop: target
}, 500);
event.preventDefault();
});
</script>
</body>
</html>
sorry to tell you that but I don't like your CSS, and opacity 0 on the entire page? float everywhere, I don't get it ^^ first of all try to put CSS in a CSS file and JS in a JS file
I did not understand what the span things were for, I removed them for the structure
now for the code
I can recommend using a structure, would be easier
something like this:
HTML:
body{
padding: 0;
margin: 0;
}
.col1x3{
width: 33%;
}
.col1x2{
width: 50%;
}
.element{
margin-right: -0.25em;
display: inline-block;
}
<div class="row">
<div class="container">
<div class="element col1x2">
<img src = "https://www.magknit.co.uk/staging/1365/wp-content/uploads/2020/10/descarga-1-1.png" class="logo" href="#"></a>
</div>
<div class="element col1x2">
<nav>
<ul>
<li class="element col1x3">Home</li>
<li class="element col1x3">Abous Us</li>
<li class="element col1x3">Contact Us</li>
</ul>
</nav>
</div>
</div>
</div>
I found out it is the max-width in the .row that is causing the problem. i had it set up to 960px so the row would not be longer than that. I just had to set it to whatever screen size I wanted and that is it.
I created some background images in a div with slideshow and some content displaying on that, and now I'm trying to add a section right below my background image but anything I add after my background div in my html, locates behind my background image and top of my window as if I've had created no content in my webpage before this section except a navbar with sticky position. I put my codes here for better perception.
I'm trying to create content just after my background image as different, separated parts of my webpage, does anyone have an idea?
P.S: My main focus is running this web on full screen windows so please excuse my cluttered code result in non-full-screen windows.
*,
*::before,
*::after{
padding: 0;
margin: 0;
box-sizing: border-box;
}
body{
background-color: aqua;
}
header{
z-index: 999999999;
overflow: hidden;
position: sticky;
top: -31px;
}
header .header_main{
background-color: rgba(255,255,255,0.98);
}
header div.header_meta{
font-family: 'Open Sans', sans-serif;
font-weight: bold;
font-size: 11px;
border-bottom: 1px solid rgba(224, 224, 224, 0.56);
}
header div.container{
line-height: 30px;
width: 90%;
margin: auto;
padding: 0 50px;
}
header div.container nav ul{
line-height: 30px;
margin: 0 auto;
float: right;
}
header div.container nav ul li{
float: right;
list-style: none;
}
header div.container nav ul li a{
text-decoration: none;
float: right;
padding: 0 10px;
color: #ffffff;
}
header div.container nav ul li a:hover{
text-decoration: underline;
color: #E6E6E6;
}
header .header_meta .header_contact{
margin: auto;
line-height: 30px;
color: #ffffff;
}header .header_main{
box-shadow: 0 3px 4px -4px rgba(138, 138, 138, 0.65);
}
header .header_main .container_logo_nav{
width: 90%;
height: 60px;
line-height: 60px;
margin: 0 auto;
padding: 0 4%;
}
header .header_main .container_logo_nav img{
height: 100%;
width: 216px;
float: left;
}
header .header_main .container_logo_nav ul{
float: right;
padding-right: 1%;
}
header .header_main .container_logo_nav ul li{
float: right;
list-style: none;
}
header .header_main .container_logo_nav ul li a{
text-decoration: none;
font-family: 'Open Sans', sans-serif;
font-weight: bolder;
font-size: 14px;
color: #6E6E6E;
padding: 0 13px;
transition: 300ms;
}
header .header_main .container_logo_nav ul li a.search{
font-size: 11px;
}
header .header_main .container_logo_nav ul li a:hover{
color: #000000;
}
.container_slider{
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 82vh;
animation: animate 35s ease-in-out infinite;
background-size: cover;
background: no-repeat center;
clear: both;
display: block;
}
.container_slider::before{
width: 100%;
height: 100%;
content:"";
background-color: rgba(22,22,22,0.2);
position: absolute;
top: 0;
}
#keyframes animate{
0%,100%{
background-image: url("Background_Image1");
}
20%{
background-image: url("Background_Image2");
}
40%{
background-image: url("Background_Image3");
}
60%{
background-image: url("Background_Image4");
}
80%{
background-image: url("Background_Image5");
}
}
.container_slider .outer{
width: 100%;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50% , -50%);
text-align: center;
}
.container_slider .outer .details{
}
.container_slider .outer .details h1{
font-family: 'Finger Paint', cursive;
font-weight: lighter;
color: #ffffff;
font-size: 70px;
line-height: 77px;
padding: 15px 0;
animation: caption 600ms ease-in-out 1;
}
#keyframes caption {
0%{
transform: translate(0, -20px);
opacity: 0;
}
100%{
transform: translate(0, 0);
opacity: 1;
}
}
.container_slider .outer .details span{
font-family: 'Open Sans';
font-weight: 600;
font-size: 16px;
color: #ffffff;
display: block;
animation: ltlspan 600ms linear 1;
}
#keyframes ltlspan {
0%{
transform: translate(0, 20px);
opacity: 0;
}
100%{
transform: translate(0, 0);
opacity: 1;
}
}
.container_slider .outer .buttons{
width: 100%;
margin-top: 40px;
}
.container_slider .outer a{
background-color: #f8f8f8;
width: 152px;
height: 46px;
line-height: 23px;
border-radius: 100px;
padding: 10px 20px;
margin: 0 10px;
text-decoration: none;
font-family: 'Open Sans', sans-serif;
font-size: 12px;
font-weight: bold;
display: inline-block;
text-align: center;
transition: 300ms;
color: #666666;
animation: abuttons 1300ms ease-in 1;
}
#keyframes abuttons {
0%{
transform: translate(0, -20px);
opacity: 0;
}
100%{
transform: translate(0, 0);
opacity: 1;
}
}
.container_slider .outer a:first-child{
background-color: #109bc5;
color: #ffffff;
border-bottom: 1px solid #0079a3;
}
.container_slider .outer a:first-child:hover{
background-color: rgba(16, 156, 198, 0.9);
}
.container_slider .outer a:nth-child(2):hover{
background-color: rgba(255, 255, 255, 0.86);
color: black;
}
div.box{
width: 100px;
height: 100px;
background-color: blue;
/* I want this box to be displayed below my background image */
}
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Open+Sans:wght#300&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Open+Sans+Condensed:wght#700&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Finger+Paint&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/css/all.min.css">
<link href="https://fonts.googleapis.com/css2?family=Open+Sans:wght#600&display=swap" rel="stylesheet">
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<header>
<div class="header_meta">
<div class="container">
<nav>
<ul>
<li> Registration </li>
<li> Customer Login </li>
</ul>
</nav>
<div class="header_contact"> <span>Call us now: 555-147-5643</span> </div>
</div>
</div>
<div class="header_main">
<div class="container_logo_nav">
<span class="logo"> <img src="images/logo-large.png" alt=""> </span>
<nav class="main_menu">
<ul>
<li><a class="search" href="#"><i class="fa fa-search"></i></a></li>
<li>News</li>
<li>Contact</li>
<li>About</li>
<li>Deals</li>
<li>Destinations</li>
<li>Welcome</li>
</ul>
</nav>
</div>
</div>
</header>
<div class="container_slider">
<div class="outer">
<div class="details">
<h1>To Travel is to live</h1>
<h2>
<span>Want to make a journey? We got the destinations!</span>
</h2>
</div>
<div class="buttons">
ALL DESTINATIONS
LATEST OFFERS
</div>
</div>
</div>
<div class="box"></div>
</body>
</html>
You have set your wrapper to position absolute together with inner. I have changed the .container_slider to relative to wrap properly your slider and box.
[screenshot of the result][1]
here is a screenshot: https://i.stack.imgur.com/8hTNT.jpg
*,
*::before,
*::after {
padding: 0;
margin: 0;
box-sizing: border-box;
}
body {
background-color: aqua;
}
header {
z-index: 999999999;
overflow: hidden;
position: sticky;
top: -31px;
}
header .header_main {
background-color: rgba(255, 255, 255, 0.98);
}
header div.header_meta {
font-family: 'Open Sans', sans-serif;
font-weight: bold;
font-size: 11px;
border-bottom: 1px solid rgba(224, 224, 224, 0.56);
}
header div.container {
line-height: 30px;
width: 90%;
margin: auto;
padding: 0 50px;
}
header div.container nav ul {
line-height: 30px;
margin: 0 auto;
float: right;
}
header div.container nav ul li {
float: right;
list-style: none;
}
header div.container nav ul li a {
text-decoration: none;
float: right;
padding: 0 10px;
color: #ffffff;
}
header div.container nav ul li a:hover {
text-decoration: underline;
color: #e6e6e6;
}
header .header_meta .header_contact {
margin: auto;
line-height: 30px;
color: #ffffff;
}
header .header_main {
box-shadow: 0 3px 4px -4px rgba(138, 138, 138, 0.65);
}
header .header_main .container_logo_nav {
width: 90%;
height: 60px;
line-height: 60px;
margin: 0 auto;
padding: 0 4%;
}
header .header_main .container_logo_nav img {
height: 100%;
width: 216px;
float: left;
}
header .header_main .container_logo_nav ul {
float: right;
padding-right: 1%;
}
header .header_main .container_logo_nav ul li {
float: right;
list-style: none;
}
header .header_main .container_logo_nav ul li a {
text-decoration: none;
font-family: 'Open Sans', sans-serif;
font-weight: bolder;
font-size: 14px;
color: #6e6e6e;
padding: 0 13px;
transition: 300ms;
}
header .header_main .container_logo_nav ul li a.search {
font-size: 11px;
}
header .header_main .container_logo_nav ul li a:hover {
color: #000000;
}
.container_slider {
position: relative; /*changed to relative*/
top: 0;
left: 0;
width: 100%;
height: 82vh;
animation: animate 35s ease-in-out infinite;
background-size: cover;
background: no-repeat center;
clear: both;
display: block;
}
.container_slider::before {
width: 100%;
height: 100%;
content: '';
background-color: rgba(22, 22, 22, 0.2);
position: absolute;
top: 0;
}
#keyframes animate {
0%,
100% {
background-image: url('https://www.pexels.com/photo/green-leaf-plant-808510/');
}
20% {
background-image: url('https://www.pexels.com/photo/green-leaf-plant-808510/');
}
40% {
background-image: url('https://www.pexels.com/photo/green-leaf-plant-808510/');
}
60% {
background-image: url('https://www.pexels.com/photo/green-leaf-plant-808510/');
}
80% {
background-image: url('https://www.pexels.com/photo/green-leaf-plant-808510/');
}
}
.container_slider .outer {
width: 100%;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
text-align: center;
}
.container_slider .outer .details {
}
.container_slider .outer .details h1 {
font-family: 'Finger Paint', cursive;
font-weight: lighter;
color: #ffffff;
font-size: 70px;
line-height: 77px;
padding: 15px 0;
animation: caption 600ms ease-in-out 1;
}
#keyframes caption {
0% {
transform: translate(0, -20px);
opacity: 0;
}
100% {
transform: translate(0, 0);
opacity: 1;
}
}
.container_slider .outer .details span {
font-family: 'Open Sans';
font-weight: 600;
font-size: 16px;
color: #ffffff;
display: block;
animation: ltlspan 600ms linear 1;
}
#keyframes ltlspan {
0% {
transform: translate(0, 20px);
opacity: 0;
}
100% {
transform: translate(0, 0);
opacity: 1;
}
}
.container_slider .outer .buttons {
width: 100%;
margin-top: 40px;
}
.container_slider .outer a {
background-color: #f8f8f8;
width: 152px;
height: 46px;
line-height: 23px;
border-radius: 100px;
padding: 10px 20px;
margin: 0 10px;
text-decoration: none;
font-family: 'Open Sans', sans-serif;
font-size: 12px;
font-weight: bold;
display: inline-block;
text-align: center;
transition: 300ms;
color: #666666;
animation: abuttons 1300ms ease-in 1;
}
#keyframes abuttons {
0% {
transform: translate(0, -20px);
opacity: 0;
}
100% {
transform: translate(0, 0);
opacity: 1;
}
}
.container_slider .outer a:first-child {
background-color: #109bc5;
color: #ffffff;
border-bottom: 1px solid #0079a3;
}
.container_slider .outer a:first-child:hover {
background-color: rgba(16, 156, 198, 0.9);
}
.container_slider .outer a:nth-child(2):hover {
background-color: rgba(255, 255, 255, 0.86);
color: black;
}
div.box {
width: 100px;
height: 100px;
background-color: blue;
/* I want this box to be displayed below my background image */
}
I made a mobile responsive hamburger menu to horizontal nav bar, but I'm having trouble making a hover style for the links on the horizontal nav bar that don't make them jump. If you look at my Codpen you'll see the general style I want on those links on hover, but I want that highlight to be larger around the wording. When I've tried to do this the links end up jumping on hover. The other thing is that I can't get the top highlight much bigger... it's like it's cut off with some other property. This is the first menu like this I've made (I'm fairly new) so I played around with a lot of different CSS properties and values to get things to look perfect upon first glance and I'm sure some CSS isn't right, I just don't know what or where. I pasted the code below with everything inline but definitely check out the codpen because that's more accurate to how it looks on my computer. Thanks for your help!
http://codepen.io/sshine2/pen/VbjGaE
EDIT: I edited the code in Codepen to show how the top of the highlight gets cut off and the link jumps when the highlight is the size I want it to be.
SECOND EDIT: Fixed the top being cut off myself. Changed where the entire menu was displayed.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<style>
body {
font-family: 'Noto Sans', sans-serif;
margin: 0;
width: 100%;
height: 100vh;
background: #ffffff;
background-color: black;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
header {
width: 100%;
background: #ffffff;
position: fixed;
height: 4em;
line-height: 4em;
display: inline-block;
padding-left: 1em;
border-bottom: .1em solid #dddddd;
}
h2 {
font-size: 2.1em;
}
p {
font-size: 10em;
color: white;
padding-top: 1em;
}
#media only screen and (min-width: 319px) {
.menu {
z-index: 1;
display: none;
font-weight: bold;
font-size: 1.2em;
width: 100%;
background: #f1f1f1;
position: fixed;
text-align: center;
margin-top: 3.3em;
color: black;
}
.menu ul {
margin: 0;
padding: 0;
list-style-type: none;
list-style-image: none;
border-top: #dddddd 1px solid;
}
.menu li {
display: block;
padding: 1em 0 1em 0;
border-bottom: #dddddd 1px solid;
}
.menu li:hover {
display: block;
background: #585858;
padding: 1em 0 1em 0;
cursor: crosshair;
}
.menu ul li a {
text-decoration: none;
margin: 0px;
color: black;
}
.menu ul li a:hover {
color: white;
text-decoration: none;
}
.menu a {
text-decoration: none;
color: black;
}
.menu a:hover {
text-decoration: none;
color: white;
}
#nav-icon4 {
width: 35px;
height: 25px;
float: right;
margin-top: -47px;
margin-right: 30px;
-webkit-transform: rotate(0deg);
-moz-transform: rotate(0deg);
-o-transform: rotate(0deg);
transform: rotate(0deg);
-webkit-transition: .5s ease-in-out;
-moz-transition: .5s ease-in-out;
-o-transition: .5s ease-in-out;
transition: .5s ease-in-out;
cursor: cell;
}
#nav-icon4 span {
display: block;
position: absolute;
height: 5px;
width: 100%;
background: darkred;
border-radius: 7px;
opacity: 2;
left: 0;
-webkit-transform: rotate(0deg);
-moz-transform: rotate(0deg);
-o-transform: rotate(0deg);
transform: rotate(0deg);
-webkit-transition: .25s ease-in-out;
-moz-transition: .25s ease-in-out;
-o-transition: .25s ease-in-out;
transition: .25s ease-in-out;
}
#nav-icon4 span:nth-child(1) {
top: 0px;
-webkit-transform-origin: left center;
-moz-transform-origin: left center;
-o-transform-origin: left center;
transform-origin: left center;
}
#nav-icon4 span:nth-child(2) {
top: 10px;
-webkit-transform-origin: left center;
-moz-transform-origin: left center;
-o-transform-origin: left center;
transform-origin: left center;
}
#nav-icon4 span:nth-child(3) {
top: 20px;
-webkit-transform-origin: left center;
-moz-transform-origin: left center;
-o-transform-origin: left center;
transform-origin: left center;
}
#nav-icon4.open span:nth-child(1) {
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-o-transform: rotate(45deg);
transform: rotate(45deg);
top: 0;
left: 6px;
}
#nav-icon4.open span:nth-child(2) {
width: 0%;
opacity: 0;
}
#nav-icon4.open span:nth-child(3) {
-webkit-transform: rotate(-45deg);
-moz-transform: rotate(-45deg);
-o-transform: rotate(-45deg);
transform: rotate(-45deg);
top: 25px;
left: 6px;
}
}
#media only screen and (min-width : 768px) {
h2 {
z-index: 1000000;
font-size: 1.5em;
}
p {
font-size: 20em;
color: white;
padding-top: 1em;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
}
li {
float: right;
margin-left: 20px;
margin-right: 8px;
margin-top: -10px;
}
li a {
display: block;
text-align: center;
text-decoration: none;
}
.menu {
display: block!important;
position: absolute;
right: 0px;
font-size: .9em;
width: 100%;
padding-right: 15px;
margin-top: 10px;
padding-top: 10px;
padding-bottom: 10px;
background: rgba(255, 255, 255, 0);
}
.menu ul {
border-bottom: 0;
border-top: 0;
}
.menu li {
border-bottom: 0;
border-top: 0;
}
.menu li:hover {
cursor: crosshair;
padding-top: 1em;
padding-bottom: .4em;
padding-right: 0em;
padding-left: 0em;
}
.menu ul li a:hover {
color: white;
}
#nav-icon4 {
display: none;
}
}
#media only screen and (min-width : 922px) {
li {
margin-left: 55px;
margin-right: 18px;
}
.menu {
padding-right: 1px;
}
}
#media only screen and (min-width : 1400px) {
header {
height: 5em;
line-height: 5em;
}
h2 {
font-size: 2.6em;
}
li {
margin-left: 55px;
margin-right: 30px;
}
.menu {
padding-right: 1px;
font-size: 1.2em;
}
}
</style>
<title>hamburgers</title>
</head>
<body>
<header>
<span>Shine Design</span>
<div id="nav-icon4">
<span></span>
<span></span>
<span></span>
</div>
</header>
<div class="menu">
<ul>
<a href="#">
<li>LINK ONE</li>
</a>
<a href="#">
<li>LINK TWO</li>
</a>
<a href="#">
<li>LINK THREE</li>
</a>
<a href="#">
<li>LINK FOUR</li>
</a>
<a href="#">
<li>LINK FIVE</li>
</a>
</ul>
</div>
</body>
<script src="http://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript">google.load("jquery", "1.3.2");</script>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script>
$(document).ready(function(){
$('#nav-icon4').click(function(){
$(this).toggleClass('open');
});
});
</script>
</html>
The jumping issue is because you add padding on hover which isn't there before.
Before your media queries define the padding ones:
.menu li {
border-bottom: 0;
border-top: 0;
padding: 1em;
}
Then remove the defined paddings for .menu li in your min 768px query.,
code pen
Trying to vertically center a p element and an image. I know I could adjust the margins and padding, but I want to make sure the elements are aligned no matter what device the user enters the website on. Hence I'm looking for another option.
html, body {
font-size: 100%;
height: 100%;
font-family: 'Lato', sans-serif;
font-weight: 200;
}
/*Menu*/
.menu {
height: auto;
background-color: #fff;
width: 100%;
position: fixed;
z-index: 1;
-moz-box-shadow: 0 2px 0 0 #6ed3cf;
-webkit-box-shadow: 0 2px 0 0 #6ed3cf;
box-shadow: 0 2px 0 0 #6ed3cf;
}
.menu .logo {
padding-left: 2em;
}
.menu ul li a {
color: #3b3a36;
}
.menu .dropdown {
float: right;
right: 2em;
z-index: 20;
}
.menu .dropdown-menu {
background: #fff;
border: none;
}
.dropdown img {
height: 2.8em;
width: 2.8em;
-webkit-transition: width .8s, height .8s, -webkit-transform .8s; /* Safari */
transition: width .8s, height .8s, transform .8s;
}
.dropdown ul {
top: 3em;
left: -6.5em;
width: auto;
position: absolute;
color: #3DD0AC;
}
.rotate {
-webkit-transform: rotate(180deg); /* Safari */
transform: rotate(180deg);
}
.logo p {
font-size: 100%;
color: black;
font-family: 'Lato', sans-serif;
font-weight: bolder;
letter-spacing: 0.5em;
margin: 0;
}
<div class="menu">
<div class="logo">
<p><⁄BY_John Doe></p>
</div>
<div class="dropdown"> <img src="img/menu.jpg">
<ul class="dropdown-menu">
<li>Find me on Linkedin
<li>
<li>Send me an email</li>
<li>Download my resume</li>
</ul>
</div>
</div>
Flex box can acheive this for you. just add this to your css for .menu:
display:flex;
justify-content:space-between;
align-items: center
More settings for flexbox here: https://css-tricks.com/snippets/css/a-guide-to-flexbox/
html,
body {
font-size: 100%;
height: 100%;
font-family: 'Lato', sans-serif;
font-weight: 200;
}
/*Menu*/
.menu {
height: auto;
background-color: #fff;
width: 100%;
position: fixed;
z-index: 1;
-moz-box-shadow: 0 2px 0 0 #6ed3cf;
-webkit-box-shadow: 0 2px 0 0 #6ed3cf;
box-shadow: 0 2px 0 0 #6ed3cf;
display:flex;
justify-content:space-between;
align-items: center
}
.menu .logo {
padding-left: 2em;
}
.menu ul li a {
color: #3b3a36;
}
.menu .dropdown {
float: right;
right: 2em;
z-index: 20;
}
.menu .dropdown-menu {
background: #fff;
border: none;
}
.dropdown img {
height: 2.8em;
width: 2.8em;
-webkit-transition: width .8s, height .8s, -webkit-transform .8s;
/* Safari */
transition: width .8s, height .8s, transform .8s;
}
.dropdown ul {
top: 3em;
left: -6.5em;
width: auto;
position: absolute;
color: #3DD0AC;
}
.rotate {
-webkit-transform: rotate(180deg);
/* Safari */
transform: rotate(180deg);
}
.logo p {
font-size: 100%;
color: black;
font-family: 'Lato', sans-serif;
font-weight: bolder;
letter-spacing: 0.5em;
margin: 0;
}
<div class="menu">
<div class="logo">
<p><⁄BY_John Doe></p>
</div>
<div class="dropdown">
<img src="img/menu.jpg">
<ul class="dropdown-menu">
<li>Find me on Linkedin
<li>
<li>Send me an email</li>
<li>Download my resume</li>
</ul>
</div>
</div>