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.
So I have managed to create these sections on my web page, each with an image and some text in them. However with these boxes, the text element (eg. text-lifestyle), is not positioning correctly where I want it to go? Is there a way of fixing this please... I am trying to get each text part either to the left or right of the image, positioned in the centre of that side of the box.
body, html{
height: 100%;
margin: 0;
padding: 0;
font-family: 'Work Sans', sans-serif;
font-weight: 400;
}
.container {
width: 100%;
margin: 0 1.5%;
}
header{
background:rgb(241, 200, 203);
position: relative;
overflow: hidden;
}
header::after{
content: "";
display: table;
clear:both;
}
.logo{
width: 9%;
height: 5.4%;
float: left;
padding: 0px;
}
nav{
float: inline-end;
overflow: auto;
}
nav ul{
margin: 0;
padding: 0;
list-style: none;
display: inline;
}
nav li{
display: inline-block;
margin-left: 6.3%;
padding-top: 1.8%;
font-size: 112.5%;
position: relative;
}
nav .search{
float: right;
margin-bottom: 1%;
margin-right: 7%;
position: relative;
margin-top: 1.7%;
}
nav input[type=text]{
background-color: transparent;
color: rgb(95, 62, 64);
font-size: 112.5%;
border: none;
border-bottom: solid 2px black;
}
nav .search input[type="text"]:focus {
width: 200px;
outline : none;
}
nav input::placeholder{
color: rgb(95, 62, 64);
font-family: 'Work Sans', sans-serif;
}
nav a{
color: rgb(95, 62, 64);
text-decoration: none;
text-transform: uppercase;
}
nav a:hover{
color: rgb(95, 62, 64);
}
nav a::before{
content: "";
display: block;
height: 10%;
background-color: rgb(95, 62, 64);
position: absolute;
top: 0;
width: 0%;
transition: all ease-in-out 250ms;
}
nav a:hover::before{
width: 100%;
}
.main-bg{
background-image: url("bg-two.jpg");
height: auto;
padding-top: 8em;
background-attachment: fixed;
background-position: center;
background-size: cover;
position: relative;
-webkit-animation: fadein 2s; /* Safari, Chrome and Opera > 12.1 */
-moz-animation: fadein 2s; /* Firefox < 16 */
-ms-animation: fadein 2s; /* Internet Explorer */
animation: fadein 2s;
}
#keyframes fadein {
from { opacity: 0; }
to { opacity: 1; }
}
/* Firefox */
#-moz-keyframes fadein {
from { opacity: 0; }
to { opacity: 1; }
}
/* Safari, Chrome and Opera*/
#-webkit-keyframes fadein {
from { opacity: 0; }
to { opacity: 1; }
}
/* Internet Explorer */
#-ms-keyframes fadein {
from { opacity: 0; }
to { opacity: 1; }
}
.footer *{
margin: 0;
padding: 0;
box-sizing: border-box;
}
.container-two{
max-width: 1170px;
margin: auto;
}
.row{
display: flex;
flex-wrap: wrap;
}
.footer ul{
list-style: none;
}
.footer{
background-color: rgb(241, 200, 203);
width: auto;
margin: auto;
padding-top: 3%;
line-height: 1.5;
}
.footer .container-bottom{
padding-left: 12%;
}
.footer-col{
width: 25%;
padding: 0 15px;
}
.footer-col h5{
font-size: 112.5%;
color: rgb(126, 81, 83);
text-transform: capitalize;
margin-bottom: 30px;
position: relative;
}
.footer-col h5::before{
content: '';
position: absolute;
left: 0;
bottom: -10px;
background-color: rgb(82, 44, 46);
height: 2px;
box-sizing: border-box;
width: 50px;
}
.footer-col ul li:not(:last-child){
margin-bottom: 10px;
}
.footer-col ul li a{
font-size: 16px;
text-transform: capitalize;
color: rgb(126, 81, 83);
text-decoration: none;
font-weight: 600;
display: block;
}
.fab{
color:rgb(126, 81, 83);
margin-right: 10px;
}
.copyright{
margin-top: 5%;
text-align: center;
background-color: rgb(126, 81, 83);
color:rgb(240, 178, 182);
padding: 1%;
padding-left: 0%;
margin-bottom: 0%;
}
article h2{
color: rgb(240, 178, 182);
font-size: 280%;
text-align: center;
margin-top: 0%;
border-bottom: 1px solid rgb(240, 178, 182);
padding-bottom: 3px;
}
article p{
color:rgb(240, 178, 182);
font-size: 110%;
text-align: center;
}
.lifestyle{
height: 100%;
border:rgb(82, 44, 46);
border-radius: 10px;
background-color: rgb(82, 44, 46);
margin-left: 15%;
margin-right: 15%;
position: relative;
}
.lifestyle img{
margin: 5%;
width: 35%;
height: 50%;
position: relative;
}
.text-lifestyle{
position: relative;
align-items: center;
margin-left: 50%;
}
.entertainment{
height: 100%;
background-color: rgb(240, 178, 182);
margin: 15%;
}
.entertainment img{
margin: 5%;
position: relative;
width: 29%;
height: 50%;
margin-left: 65%;
}
.text-entertainment{
position: absolute;
margin: 15%;
top: 30%;
left: 7.5%;
box-sizing: border-box;
width: 30%;
}
.food{
height: 100%;
background-color:rgb(82, 44, 46);
margin: 15%;
}
.food img{
margin: 5%;
position: relative;
width: 29%;
height: 50%;
}
.text-food{
position: absolute;
top: 66.5%;
right: 22.5%;
box-sizing: border-box;
width: 30%;
}
.shopping{
height: 100%;
background-color: rgb(240, 178, 182);
margin: 15%;
}
.shopping img{
margin: 5%;
position: relative;
width: 29%;
height: 50%;
margin-left: 65%;
}
#media screen and (max-width: 768px) {
body{
font-size: 80%;
}
h1{
font-size: 312%;
}
a{
font-size: 80%;
}
}
Here is the HTML Code. As you can see I have placed the text and image elements into boxes e.g. lifestyle, entertainment, food, shopping.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta content="width=device-width, initial-scale=1" name="viewport"/>
<title>New York - The City That Never Sleeps</title>
<link rel="stylesheet" href="about.css">
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Work+Sans:wght#400&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://unpkg.com/aos#next/dist/aos.css" />
<script src="https://kit.fontawesome.com/f107c76e74.js" crossorigin="anonymous"></script>
</head>
<body>
<header>
<div class="container">
<img src="nyc-logo.png" alt="logo" class="logo">
<nav>
<ul>
<li>Home</li>
<li>About</li>
<li>Gallery</li>
<li>Contacts</li>
</ul>
<div class="search">
<input type="text" placeholder="Search">
<i class="fas fa-search" aria-hidden="true"></i>
</div>
</nav>
</div>
</header>
<div class = "main-bg">
<article>
<div class = "lifestyle">
<img src='abt-one.jpg' alt />
<div class="text-lifestyle">
<h2>LIFESTYLE</h2>
<p>New York hosts its guests with some of the best 5-star hotels and restaurants, leisure activities and more.<br/>
Relax your mind and enjoy the breathtaking views of what New York has to offer...</p>
</div>
</div>
<div class = "entertainment">
<img src='abt-two.jpg' alt />
<div class="text-entertainment">
<h2 style='color: rgb(82, 44, 46); border-bottom: 1px solid rgb(82, 44, 46);'>ENTERTAINMENT</h2>
<p style= 'color: rgb(82, 44, 46);'>Music and entertainment is a big thing in this great city. Everywhere you go, entertainment will be right at your feet. Enjoy first class musicals at BroadWay Theatre or watch busking take place free of charge!</p>
</div>
</div>
<div class = "food">
<img src='abt-three.jpg' alt />
<div class="text-food">
<h2>FOOD</h2>
<p>Enjoy some of the best cuisines across the city.<br/>
From classic burgers to jaw-dropping desserts, there's nothing to miss out on.</p>
</div>
</div>
<div class = "shopping">
<img src='abt-four.jpg' alt />
<div class="text-shopping">
<h2 style='color: rgb(82, 44, 46); border-bottom: 1px solid rgb(82, 44, 46);'>SHOPPING</h2>
<p style= 'color: rgb(82, 44, 46);'>Feeling like treating yourself with some fancy shoes? New York streets are lined with fabulous, glamourous shops, all endorsed with the latest trends from across the world.</p>
</div>
</div>
</article>
<footer class="footer">
<div class="container-bottom">
<div class="row">
<div class="footer-col">
<h5>New York</h5>
<p style="color: rgb(126, 81, 83); font-weight: 600;">The largest and most influential American metropolis</p>
</div>
<div class="footer-col">
<h5>Links</h5>
<ul>
<li>Home</li>
<li>About</li>
<li>Gallery</li>
<li>Contact</li>
</ul>
</div><div class="footer-col">
<h5>Extras</h5>
<ul>
<li>Official NYC</li>
<li>New York Magazine</li>
<li>Eater New York</li>
<li>Curbed NY</li>
</ul>
</div><div class="footer-col">
<h5>Socials</h5>
<div>
<i class="fab fa-facebook-f"></i>
<i class="fab fa-twitter"></i>
<i class="fab fa-instagram"></i>
</div>
</div>
</div>
</div>
<div class="copyright">
<small>© New York 2021 | Designed by Priya Patel</small>
</div>
</footer>
</div>
</body>
</html>
is this what you are looking for? What I did is that I removed some of your top and right css selectors due to the fact that it often messes CSS up. I also added padding so the object would be better aligned. Here is my code, really hope this works for you!
body,
html {
height: 100%;
margin: 0;
padding: 0;
font-family: 'Work Sans', sans-serif;
font-weight: 400;
}
.container {
width: 100%;
margin: 0 1.5%;
}
header {
background: rgb(241, 200, 203);
position: relative;
overflow: hidden;
}
header::after {
content: "";
display: grid;
clear: both;
}
.logo {
width: 9%;
height: 5.4%;
float: left;
padding: 0px;
}
nav {
float: inline-end;
overflow: auto;
}
nav ul {
margin: 0;
padding: 0;
list-style: none;
display: inline;
}
nav li {
display: inline-block;
margin-left: 6.3%;
padding-top: 1.8%;
font-size: 112.5%;
position: relative;
}
nav .search {
float: right;
margin-bottom: 1%;
margin-right: 7%;
position: relative;
margin-top: 1.7%;
}
nav input[type=text] {
background-color: transparent;
color: rgb(95, 62, 64);
font-size: 112.5%;
border: none;
border-bottom: solid 2px black;
}
nav .search input[type="text"]:focus {
width: 200px;
outline: none;
}
nav input::placeholder {
color: rgb(95, 62, 64);
font-family: 'Work Sans', sans-serif;
}
nav a {
color: rgb(95, 62, 64);
text-decoration: none;
text-transform: uppercase;
}
nav a:hover {
color: rgb(95, 62, 64);
}
nav a::before {
content: "";
display: block;
height: 10%;
background-color: rgb(95, 62, 64);
position: absolute;
top: 0;
width: 0%;
transition: all ease-in-out 250ms;
}
nav a:hover::before {
width: 100%;
}
.main-bg {
background-image: url("bg-two.jpg");
height: auto;
padding-top: 8em;
background-attachment: fixed;
background-position: center;
background-size: cover;
position: relative;
-webkit-animation: fadein 2s;
/* Safari, Chrome and Opera > 12.1 */
-moz-animation: fadein 2s;
/* Firefox < 16 */
-ms-animation: fadein 2s;
/* Internet Explorer */
animation: fadein 2s;
}
#keyframes fadein {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
/* Firefox */
#-moz-keyframes fadein {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
/* Safari, Chrome and Opera*/
#-webkit-keyframes fadein {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
/* Internet Explorer */
#-ms-keyframes fadein {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
.footer * {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.container-two {
max-width: 1170px;
margin: auto;
}
.row {
display: flex;
flex-wrap: wrap;
}
.footer ul {
list-style: none;
}
.footer {
background-color: rgb(241, 200, 203);
width: auto;
margin: auto;
padding-top: 3%;
line-height: 1.5;
}
.footer .container-bottom {
padding-left: 12%;
}
.footer-col {
width: 25%;
padding: 0 15px;
}
.footer-col h5 {
font-size: 112.5%;
color: rgb(126, 81, 83);
text-transform: capitalize;
margin-bottom: 30px;
position: relative;
}
.footer-col h5::before {
content: '';
position: absolute;
left: 0;
bottom: -10px;
background-color: rgb(82, 44, 46);
height: 2px;
box-sizing: border-box;
width: 50px;
}
.footer-col ul li:not(:last-child) {
margin-bottom: 10px;
}
.footer-col ul li a {
font-size: 16px;
text-transform: capitalize;
color: rgb(126, 81, 83);
text-decoration: none;
font-weight: 600;
display: block;
}
.fab {
color: rgb(126, 81, 83);
margin-right: 10px;
}
.copyright {
margin-top: 5%;
text-align: center;
background-color: rgb(126, 81, 83);
color: rgb(240, 178, 182);
padding: 1%;
padding-left: 0%;
margin-bottom: 0%;
}
article h2 {
color: rgb(240, 178, 182);
font-size: 280%;
text-align: center;
margin-top: 0%;
border-bottom: 1px solid rgb(240, 178, 182);
padding-bottom: 3px;
}
article p {
color: rgb(240, 178, 182);
font-size: 110%;
text-align: center;
}
.lifestyle {
height: 100%;
border: rgb(82, 44, 46);
border-radius: 10px;
background-color: rgb(82, 44, 46);
margin-left: 15%;
margin-right: 15%;
padding: 30px;
position: relative;
}
.lifestyle img {
margin: 5%;
width: 35%;
height: 50%;
position: relative;
}
.text-lifestyle {
position: relative;
align-items: center;
margin-left: 50%;
}
.entertainment {
margin-top: 15em;
height: 100%;
border: rgb(240, 178, 182);
border-radius: 10px;
background-color: rgb(240, 178, 182);
margin-left: 15%;
margin-right: 15%;
padding: 30px;
position: relative;
}
.entertainment img {
position: relative;
width: 29%;
height: 50%;
float: right;
}
.text-entertainment {
box-sizing: border-box;
width: 50%;
}
.food {
margin-top: 15em;
min-height: 278px;
border: rgb(82, 44, 46);
border-radius: 10px;
background-color: rgb(82, 44, 46);
margin-left: 15%;
margin-right: 15%;
padding: 30px;
position: relative;
}
.food img {
position: relative;
width: 29%;
height: 50%;
}
.text-food {
box-sizing: border-box;
width: 30%;
float: right;
}
.shopping {
height: 100%;
background-color: rgb(240, 178, 182);
margin: 15%;
padding: 30px;
border-radius: 10px;
}
.shopping img {
margin: 5%;
position: relative;
width: 29%;
height: 50%;
margin-left: 65%;
}
#media screen and (max-width: 768px) {
body {
font-size: 80%;
}
h1 {
font-size: 312%;
}
a {
font-size: 80%;
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta content="width=device-width, initial-scale=1" name="viewport" />
<title>New York - The City That Never Sleeps</title>
<link rel="stylesheet" href="about.css">
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Work+Sans:wght#400&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://unpkg.com/aos#next/dist/aos.css" />
<script src="https://kit.fontawesome.com/f107c76e74.js" crossorigin="anonymous"></script>
<link rel="stylesheet" href="main.css">
</head>
<body>
<header>
<div class="container">
<img src="nyc-logo.png" alt="logo" class="logo">
<nav>
<ul>
<li>Home</li>
<li>About</li>
<li>Gallery</li>
<li>Contacts</li>
</ul>
<div class="search">
<input type="text" placeholder="Search">
<i class="fas fa-search" aria-hidden="true"></i>
</div>
</nav>
</div>
</header>
<div class="main-bg">
<article>
<div class="lifestyle">
<img src='abt-one.jpg' alt />
<div class="text-lifestyle">
<h2>LIFESTYLE</h2>
<p>New York hosts its guests with some of the best 5-star hotels and restaurants, leisure activities and more.<br/> Relax your mind and enjoy the breathtaking views of what New York has to offer...</p>
</div>
</div>
<div class="entertainment">
<img src='abt-two.jpg' alt />
<div class="text-entertainment">
<h2 style='color: rgb(82, 44, 46); border-bottom: 1px solid rgb(82, 44, 46);'>ENTERTAINMENT</h2>
<p style='color: rgb(82, 44, 46);'>Music and entertainment is a big thing in this great city. Everywhere you go, entertainment will be right at your feet. Enjoy first class musicals at BroadWay Theatre or watch busking take place free of charge!</p>
</div>
</div>
<div class="food">
<img src='abt-three.jpg' alt />
<div class="text-food">
<h2>FOOD</h2>
<p>Enjoy some of the best cuisines across the city.<br/> From classic burgers to jaw-dropping desserts, there's nothing to miss out on.</p>
</div>
</div>
<div class="shopping">
<img src='abt-four.jpg' alt />
<div class="text-shopping">
<h2 style='color: rgb(82, 44, 46); border-bottom: 1px solid rgb(82, 44, 46);'>SHOPPING</h2>
<p class="text-shopping" style='color: rgb(82, 44, 46);'>Feeling like treating yourself with some fancy shoes? New York streets are lined with fabulous, glamourous shops, all endorsed with the latest trends from across the world.</p>
</div>
</div>
</article>
<footer class="footer">
<div class="container-bottom">
<div class="row">
<div class="footer-col">
<h5>New York</h5>
<p style="color: rgb(126, 81, 83); font-weight: 600;">The largest and most influential American metropolis</p>
</div>
<div class="footer-col">
<h5>Links</h5>
<ul>
<li>Home</li>
<li>About</li>
<li>Gallery</li>
<li>Contact</li>
</ul>
</div>
<div class="footer-col">
<h5>Extras</h5>
<ul>
<li>Official NYC</li>
<li>New York Magazine</li>
<li>Eater New York</li>
<li>Curbed NY</li>
</ul>
</div>
<div class="footer-col">
<h5>Socials</h5>
<div>
<i class="fab fa-facebook-f"></i>
<i class="fab fa-twitter"></i>
<i class="fab fa-instagram"></i>
</div>
</div>
</div>
</div>
<div class="copyright">
<small>© New York 2021 | Designed by Priya Patel</small>
</div>
</footer>
</div>
</body>
</html>
I see you're using display: table. I would advise against using this because it is basically impossible to make your website responsive in a good manner. Rather than using display: table try using display: grid. More on css-grid here: https://css-tricks.com/snippets/css/complete-guide-grid/
Concering positioning elements on your webpage, a combination of css-grid and flexbox is the best and easiest way to achieve this, more on flexbox here: https://css-tricks.com/snippets/css/a-guide-to-flexbox/
I'm not knowing how to increase the height of vitaminpic, which is under container. I'm still new to development, and I know this seems like an amateur mistake. I tried everything I can but it's not working. I believe it has to do with with the fact that it is under the container. I'm trying to make a website that sells vitamins, still new to it but I'm still trying.
#import url('https://fonts.googleapis.com/css2?family=Syne+Mono&display=swap');
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: sans-serif;
}
.background {
width: 100%;
height: 100vh;
background-color: #e0d1cb;
position: relative;
overflow: hidden;
z-index: 2;
}
.nav {
position: fixed;
top: 0;
width: 100%;
display: flex;
justify-content: space-around;
align-items: center;
min-height: 8vh;
background-color: #e0d1cb;
font-family: 'Syne Mono', monospace;
z-index: 3;
}
.nav-links {
display: flex;
justify-content: space-around;
width: 30%;
font-family: 'Syne Mono', monospace;
}
.nav-links li {
list-style: none;
font-family: 'Syne Mono', monospac
}
.nav-links a {
color: rgb(0, 0, 0);
text-decoration: none;
letter-spacing: 2px;
font-weight: bold;
font-size: 14px;
font-family: 'Syne Mono', monospac
}
.burger {
display: none;
}
.burger div {
width: 25px;
height: 3px;
background-color: rgb(226, 226, 226);
margin: 5px;
transition: all 0.3s ease;
}
#media screen and (max-width: 1024px) {
.nav-links {
width: 60%;
}
}
#media screen and (max-width: 768px) {
body {
overflow-x: hidden;
}
.nav-links {
position: fixed;
right: 0px;
height: 92vh;
top: 8vh;
background-color: #e0d1cb;
display: flex;
flex-direction: column;
align-items: center;
width: 20%;
transform: translateX(100%);
transition: transform 0.5s ease-in;
}
.nav-links li {
opacity: 0;
}
.burger {
display: block;
cursor: pointer;
}
}
.nav-active {
transform: translateX(0%);
}
#keyframes navLinkFade {
from {
opacity: 0;
transform: translateX(50px);
}
to {
opacity: 1;
transform: translateX(0);
}
}
.toggle .line1 {
transform: rotate(-45deg) translate(-5px, 6px);
}
.toggle .line2 {
opacity: 0;
}
.toggle .line3 {
transform: rotate(45deg) translate(-5px, -6px);
}
#import url('https://fonts.googleapis.com/css2?family=Syne+Mono&display=swap');
.logo {
resize: both;
font-family: 'Syne Mono', monospace;
}
.link::after {
content: '';
display: block;
width: 0;
height: 2px;
background: #000000;
transition: width .3s;
}
.link:hover::after {
width: 100%;
transition: width .3s;
}
.header {
width: 100%;
background-color: rgba(0, 0, 0, 0.5)
}
.header ul {
text-align: center;
}
.header ul li {
list-style: none;
display: inline-block;
}
.header ul li a {
display: block;
text-decoration: none;
text-transform: uppercase;
color: white;
font-size: 100%;
letter-spacing: 2px;
font-weight: 600;
padding: 25px;
transition: width .3s;
}
.content {
color: #fbfcfd;
position: absolute;
top: 50%;
left: 8%;
transform: translateY(-50%);
z-index: 2;
}
.heading1 {
font-size: 300%;
margin-bottom: 10px 0 30px;
background: transparent;
position: relative;
animation: text 5s 1;
left: 120%;
}
#keyframes text {
0% {
color: transparent;
margin-bottom: -40px;
}
30% {
letter-spacing: 4px;
margin-bottom: -40px;
}
85% {
letter-spacing: 3px%;
margin-bottom: -40px;
}
}
.welcome {
font-size: 30px;
position: relative;
}
.container {
position: absolute;
height: 80%;
width: 30%;
background: #dfcac1;
top: 50%;
left: 35%;
transform: translate(-43%, -60%);
}
.container img {
size: ;
}
.vitaminpic {
width: 100%;
transform: translate(10%, 80%);
padding: 0 10;
}
<head>
<link rel="stylesheet" href="home.css">
</head>
<header class="site-header"></header>
<div class="background">
<div class="nav">
<h1 class="logo">Realvite</h1>
<ul class="nav-links">
<li>
<a href="#" class="link1">
<div class="link1">Home</div>
</a>
</li>
<li>Shop</li>
<li>Contact</li>
</ul>
<div class="burger">
<div class="line1"></div>
<div class="line2"></div>
<div class="line3"></div>
</div>
</div>
</nav>
<div class="container">
<img src="/images/capsule-1079838_1920.jpg" alt="" class="vitaminpic">
</div>
<p style="font-size: 1px;">قيل قديقال</p>
<div class="content">
<small class="welcome"></small>
<h1 class="heading1"></h1>
</div>
</div>
<script src="script.js"></script>
If I were you I would use Bootstrap columns, because not only are these easily configurable, but importing bootstrap also allows you to use a wide variety of HTML, CSS and Javascript libraries which are widely supported. Here's the link - https://getbootstrap.com
In the meantime though, I would recommend removing this:
.container img {
size: ;
}
and changing your container width to 50% to see if that works, because currently you've set your container to 30% width, whereas your image is larger than that, so it isn't fitting inside the container. If 50% doesn't work then try a few different values to try and get it to fit, but as mentioned I would recommend Bootstrap, then you can use "col-md-4" and set the background for that, would probably be much more convenient for you in the long run! :)
Here is what I see for my website:
website
As the image is below Navigation Bar, I want this to center vertically in my responsive website, similar to this website: https://www.ownhour.co.kr/#;
I have added width and height as 100% in internal image stylesheet and added margin and block in external CSS. After inspecting with the mobile version, it seems like the image is sitting at the top with a huge gap at the bottom.
Here is what I see for my website:
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="monday.css">
<title>J[a]son</title>
</head>
<body>
<nav>
<div class = "logo">
<h4>J[a]son</h4>
</div>
<ul class = "nav-links">
<li>
HOME
</li>
<li>
PHOTOGRAPHY
<ul class="sub-menu">
<li>Colour</li>
<li>Black</li>
</ul>
</li>
<li>
CODING
</li>
<li>
ABOUT
</li>
</ul>
<div class= "burger">
<div class="line1"></div>
<div class="line2"></div>
<div class="line3"></div>
</div>
</nav>
<script src="testing.js"></script>
<img class="main_car" src="Photos/main_car.jpg" alt="car" width="100%" height="100%"/>
<!--<p>June, 2020. Sunshine Coast, BC, Canada </p>-->
</body>
</html>
CSS
* {
margin: 0px;
padding: 0px;
box-sizing: border-box;
}
nav {
display: flex;
justify-content: space-between;
/*padding-right: 2em;*/
padding-left: 2em;
padding-top: 2em;
padding-bottom: 1.5em;
align-items: center;
min-height: 8vh;
background-color: black;
/*font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;*/
font-family: 'Poppins', sans-serif;
}
.logo {
color: rgb(240, 235, 235);
font-size: 20px;
text-transform: uppercase;
letter-spacing: 5px;
}
.nav-links {
display: flex;
justify-content: space-around;
width: 30%;
}
.nav-links li {
list-style: none;
}
.nav-links a {
color: white;
text-decoration: none;
letter-spacing: 1px;
font-weight: bold;
font-size: 11px;
/*padding: 5px 5px;*/
}
.burger {
display: none;
cursor: pointer;
}
.burger div {
width: 25px;
height: 3px;
background-color: white;
margin: 5px;
transition: all 0.3s ease;
}
#media screen and (max-width:1430px) {
.nav-links {
width: 40%;
}
}
#media screen and (max-width:950px) {
body {
overflow-x: hidden;
}
.nav-links {
position: absolute;
right: 0px;
height: 92vh;
top: 8vh;
background-color: black;
display: flex;
flex-direction: column;
align-items: center;
width: 30%;
transform: translateX(100%);
padding-right: 2em;
transition: transform 0.5s ease-in;
}
.nav-links li {
opacity: 0;
}
.burger {
display: block;
padding-right: 1em;
}
.sub-menu {
position: relative;
}
}
.nav-active {
transform: translate(0%);
}
The question is how to center the car image and remain responsive.
As I understand it (and this may need adjustment for your particular case) the requirement is for the car image to fill space but not leave a huge gap underneath before the footers are reached.
To do this in this case I've set the body element to flex so that once it's decided what is needed space-wise for the navbar and footer it can fill the remaining space with the car.
I initially tried to do this with object-fit: contain and object-position: center within a wrapper around the car img. However, I could not make this work and instead I've removed the car image and set it as a background to a div instead and allowed this div to fill up any remaining space on the screen.
Here's the snippet.
* {
margin: 0px;
padding: 0px;
box-sizing: border-box;
}
body {
display: flex;
flex-direction: column;
height: 100vh;
}
nav {
display: flex;
justify-content: space-between;
/*padding-right: 2em;*/
padding-left: 2em;
padding-top: 2em;
padding-bottom: 1.5em;
align-items: center;
min-height: 8vh;
background-color: black;
/*font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;*/
font-family: 'Poppins', sans-serif;
}
.logo {
color: rgb(240, 235, 235);
font-size: 20px;
text-transform: uppercase;
letter-spacing: 5px;
}
.nav-links {
display: flex;
justify-content: space-around;
width: 30%;
}
.nav-links li {
list-style: none;
}
.nav-links a {
color: white;
text-decoration: none;
letter-spacing: 1px;
font-weight: bold;
font-size: 11px;
/*padding: 5px 5px;*/
}
.burger {
display: none;
cursor: pointer;
}
.burger div {
width: 25px;
height: 3px;
background-color: white;
margin: 5px;
transition: all 0.3s ease;
}
#media screen and (max-width:1430px) {
.nav-links {
width: 40%;
}
}
#media screen and (max-width:950px) {
body {
overflow-x: hidden;
}
.nav-links {
position: absolute;
right: 0px;
height: 92vh;
top: 8vh;
background-color: black;
display: flex;
flex-direction: column;
align-items: center;
width: 30%;
transform: translateX(100%);
padding-right: 2em;
transition: transform 0.5s ease-in;
}
.nav-links li {
opacity: 0;
}
.burger {
display: block;
padding-right: 1em;
}
.sub-menu {
position: relative;
}
}
.nav-active {
transform: translate(0%);https://ahweb.org.uk/car.png
}
.main_car_wrapper {
background-image: url(https://ahweb.org.uk/car.png);
background-repeat: no-repeat no-repeat;
background-position: center center;
background-size: contain;
width: 100%;
flex: 1 1 auto;
}
</style>
<nav>
<div class = "logo">
<h4>J[a]son</h4>
</div>
<ul class = "nav-links">
<li>
HOME
</li>
<li>
PHOTOGRAPHY
<ul class="sub-menu">
<li>Colour</li>
<li>Black</li>
</ul>
</li>
<li>
CODING
</li>
<li>
ABOUT
</li>
</ul>
<div class= "burger">
<div class="line1"></div>
<div class="line2"></div>
<div class="line3"></div>
</div>
</nav>
<script src="testing.js"></script>
<div class="main_car_wrapper">
</div>
And some more footer stuff here
<p>June, 2020. Sunshine Coast, BC, Canada </p>
UPDATED
Can use with code like
margin-left: -50px;
margin-right: -50px;
width:100px;
in
.main_car img {
position: absolute;
top: 50%;
left: 50%;
margin-left: [-50% of your image's width];
margin-top: [-50% of your image's height];
}
I'm added css like this
.main_car
{
position: relative;
}
.main_car img
{
position: absolute;
top: 50%;
left: 50%;
margin-left: [-50% of your image's width];
margin-top: [-50% of your image's height];
}
Then will get output like this
Centered Image
body {
background-color: black;
/*rgb(241, 233, 233);*/
}
* {
margin: 0px;
padding: 0px;
}
.main_car
{
position: relative;
}
.main_car img
{
position: absolute;
top: 50%;
left: 50%;
margin-left: -50px;
margin-right: -50px;
width:100px;
}
#media screen and (max-width:1430px) {
.nav-links {
width: 40%;
}
}
#media screen and (max-width:950px) {
body {
overflow-x: hidden;
}
.nav-links {
position: absolute;
right: 0px;
height: 92vh;
top: 8vh;
background-color: black;
display: flex;
flex-direction: column;
align-items: center;
width: 30%;
transform: translateX(100%);
padding-right: 2em;
transition: transform 0.5s ease-in;
}
.nav-links li {
opacity: 0;
}
.burger {
display: block;
padding-right: 1em;
}
.sub-menu {
position: relaative;
}
}
<div class="main_car">
<img src="https://www.gravatar.com/avatar/efb780ba8c3560a06d4c1a1825b1e800?s=32&d=identicon&r=PG" alt="car">
</div>
I want "THE NAV" to be displayed in the center of the navbar for mobile view and want the hamburger menu icon on the far right side.
how do i do this?
I tried .logo justify-content: center but nothing changed
If anyone would care to explain this to me I would be super grateful, I have tried finding a solution myself by using google but as I'm quite new to this I haven't been able to find a fix for my problem because I'm really not sure what to search for to fix my problem
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
nav {
display: flex;
justify-content: space-around;
align-items: center;
min-height: 8vh;
background-color: #5d4954;
font-family: "Poppins", sans-serif;
}
.logo {
color: rgb(226, 226, 226);
text-transform: uppercase;
letter-spacing: 5px;
font-size: 20px;
}
.nav-links {
display: flex;
justify-content: space-around;
width: 40%;
}
.nav-links li {
list-style: none;
}
.nav-links a {
color: rgb(226, 226, 226);
text-decoration: none;
letter-spacing: 3px;
font-weight: bold;
font-size: 14px;
}
.burger {
display: none;
cursor: pointer;
}
.burger div {
width: 25px;
height: 3px;
background-color: rgb(226, 226, 226);
margin: 5px;
transition: all 0.3s ease;
}
#media screen and (max-width: 1024px) {
.nav-links {
width: 60%;
}
}
#media screen and (max-width: 768px) {
body {
overflow: hidden;
}
.nav-links {
position: absolute;
right: 0px;
height: 92vh;
top: 8vh;
background-color: #5d4954;
display: flex;
flex-direction: column;
align-items: center;
width: 50%;
transform: translateX(100%);
transition: transform 0.4s ease-in;
}
.nav-links li {
opacity: 0;
}
.burger {
display: block;
}
}
.nav-active {
transform: translateX(0%);
}
<nav>
<div class="logo">
<h4>The Nav</h4>
</div>
<ul class="nav-links">
<li>Home</li>
<li>About</li>
<li>Work</li>
<li>Projects</li>
</ul>
<div class="burger">
<div class="line1"></div>
<div class="line2"></div>
<div class="line3"></div>
</div>
</nav>
So thing is: Display Flex distributes space between divs evenly. This means your logo and your burger bove geht the same space and justify-content then placees them next to each other with 50% width.
What you need to do is: Take the burger out of the equation for the flexbox. You can do this by placing it absolute (with position: absolute) and then you just have to tell it a right-value of e.g. 40px
//CSS
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
nav {
display: flex;
justify-content: space-around;
align-items: center;
min-height: 8vh;
background-color: #5d4954;
font-family: "Poppins", sans-serif;
}
.logo {
color: rgb(226, 226, 226);
text-transform: uppercase;
letter-spacing: 5px;
font-size: 20px;
}
.nav-links {
display: flex;
justify-content: space-around;
width: 40%;
}
.nav-links li {
list-style: none;
}
.nav-links a {
color: rgb(226, 226, 226);
text-decoration: none;
letter-spacing: 3px;
font-weight: bold;
font-size: 14px;
}
.burger {
display: none;
cursor: pointer;
}
.burger div {
width: 25px;
height: 3px;
background-color: rgb(226, 226, 226);
margin: 5px;
transition: all 0.3s ease;
}
#media screen and (max-width: 1024px) {
.nav-links {
width: 60%;
}
}
#media screen and (max-width: 768px) {
body {
overflow: hidden;
}
.nav-links {
position: absolute;
right: 0px;
height: 92vh;
top: 8vh;
background-color: #5d4954;
display: flex;
flex-direction: column;
align-items: center;
width: 50%;
transform: translateX(100%);
transition: transform 0.4s ease-in;
}
.nav-links li {
opacity: 0;
}
.burger {
display: block;
position: absolute;
right: 40px;
}
}
.nav-active {
transform: translateX(0%);
}
//HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="nav.css" />
<link
href="https://fonts.googleapis.com/css2?family=Poppins:wght#400;500&display=swap"
rel="stylesheet"
/>
<title>NAVIGATION</title>
</head>
<body>
<nav>
<div class="logo">
<h4>The Nav</h4>
</div>
<ul class="nav-links">
<li>Home</li>
<li>About</li>
<li>Work</li>
<li>Projects</li>
</ul>
<div class="burger">
<div class="line1"></div>
<div class="line2"></div>
<div class="line3"></div>
</div>
</nav>
<script src="nav.js"></script>
</body>
</html>