I'm quite new to building grid layouts. I'm trying to change the dimensions of the content in the grid elements via pixels, percentages, but they remain the same, only viewport units work. There are grid-template-columns and grid-template-rows allow to increase the size of the content. I'm trying to make the top two elements: logo and menu hamburger, get bigger and almost adjacent to each other. And, I noticed that if reduce the height of the visible area of the screen, then the elements increase. Why can't I "simply" increase these two elements without doing this is beyond me? Below is a piece of code and one screenshot of what the mobile version looks like now, and how it should. Please check what is wrong.
* {
padding:0;
margin:0;
box-sizing: border-box;
}
body {
font-family: "Segoe UI", sans-serif;
height: 100vh;
}
.container {
display: grid;
grid-template-columns: repeat(10, 10%);
grid-template-rows: repeat(20, 5%);
height: 100%;
box-sizing: border-box;
}
.logo {
grid-column: 1 / 10;
grid-row: 1 / 4;
background-color: #f8f8f8;
display: flex;
align-items: center;
padding-left: 3%;
}
.logo img {
max-width: 100%;
height: auto;
}
.header {
grid-column: 10 / 11;
grid-row: 1 / 4;
background-color: #f8f8f8;
display: flex;
justify-content: center;
align-items: center;
}
.gsi {
background-color: #1b8183;
grid-column: 1 / 6;
grid-row: 8 / 17;
z-index: 1;
display: flex;
flex-direction: column;
justify-content: space-evenly;
align-items: start;
padding-left: 7%;
}
/* Text */
.gsi h1 {
font-family: 'TT Norms', Helvetica Now, Helvetica, Arial, sans-serif;
font-weight: normal;
font-style: normal;
font-size: 3vw;
color: #ffffff;
white-space: nowrap;
}
.gsi h1::after {
display: inline-block;
vertical-align: middle;
content: "";
height: 1px;
position: relative;
background-color: #ffffff;
width: 4vw;
right: -0.5em;
}
.gsi p {
font-family: 'TT Norms', Helvetica Now, Helvetica, Arial, sans-serif;
font-weight: normal;
font-style: normal;
font-size: 2vw;
color: #ffffff;
margin: 0;
white-space: nowrap;
}
.button {
font-family: 'TT Norms', Helvetica Now, Helvetica, Arial, sans-serif;
font-size: 1.5vw;
background-color: rgba(28, 28, 28, 0);
border: 2px solid #fff;
border-radius: 3em / 3em;
color: white;
padding: 1% 7.5%;
text-align: center;
text-decoration: none;
margin: 4px 2px;
cursor: pointer;
}
.pillar {
grid-column: 5 / 11;
grid-row: 4 / 21;
}
.pillar img {
width: 100%;
height: 100%;
object-fit: cover;
}
/* Anything related to hamburger */
.logo-text a:active,
.logo-text a:hover,
.logo-text a {
text-decoration: none;
color: #1b8183;
font-size: 2vw;
font-weight: bold;
}
.menu-btn {
height: 70px;
position: relative;
z-index: 3;
overflow: hidden;
padding-right: 50px;
cursor: pointer;
}
.menu-btn span {
width: 50px;
height: 4px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-color: #538b99;
border: 1px solid #538b99;
border-radius: 10px;
transition: all 0.5s;
}
.menu-btn span:nth-of-type(2) {
top: calc(40% - 5px);
}
.menu-btn span:nth-of-type(3) {
top: calc(60% + 5px);
}
.menu-btn.active span:nth-of-type(1) {
display: none;
}
.menu-btn.active span:nth-of-type(2) {
top: 50%;
transform: translate(-50%, 0%) rotate(45deg);
}
.menu-btn.active span:nth-of-type(3) {
top: 50%;
transform: translate(-50%, 0%) rotate(-45deg);
}
.menu {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
padding: 15px;
background: #f8f8f8;
transform: translateX(-100%);
transition: transform 0.5s;
}
.menu.active {
transform: translateX(0);
z-index: 2; /* > gsi =1 & < menu.active = 3 */
}
.menu li {
list-style-type: none;
font-family: 'TT Norms', Helvetica Now, Helvetica, Arial, sans-serif;
font-weight: normal;
font-style: normal;
font-size: 2vw;
padding-top: 2%;
}
.menu.active nav {
margin: 0 auto;
text-align: center;
}
.menu.active nav a {
position: relative;
color: black;
cursor: pointer;
line-height: 1;
text-decoration: none;
}
.menu.active nav a:after {
display: block;
position: absolute;
left: 0;
width: 0;
height: 3.5px;
background-color: black;
content: "";
transition: width 0.4s ease-out;
}
.menu.active nav a:hover:after,
.menu.active nav a:focus:after {
width: 100%;
}
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=0">
<title>Web-site</title>
</head>
<body>
<div class="container">
<div class="logo"><img src="https://i.postimg.cc/bYD24JGb/logo.png" alt="логотип"></div>
<div class="header">
<div class="menu-btn">
<span></span>
<span></span>
<span></span>
</div>
</div>
<div class="menu">
<nav>
<ul>
<li>Home</li>
<li>About</li>
<li>Services</li>
<li>Contacts</li>
</ul>
</nav>
</div>
<div class="gsi"><h1>NAME</h1><p>Lorem Ipsum</p><input type="button" class="button" value="Compose"></div>
<div class="pillar"><img src="https://i.postimg.cc/7hxMnrVX/pillar.png" alt="Pillar"></div>
</div>
</body>
</html>
Related
div position problem i want this hello text under the pricing section`
please help me to solve this problem
i am using different div but it still show me same result
div position problem i want this hello text under the pricing sectiondiv position problem i want this hello text under the pricing section div position problem i want this hello text under the pricing section
#import url("https://fonts.googleapis.com/css2?family=Fira+Sans+Condensed:wght#100&family=Poppins:wght#300;400;500;600&family=Roboto:wght#300&family=Silkscreen&display=swap");
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: "Lucida Sans", "Lucida Sans Regular", "Lucida Grande",
"Lucida Sans Unicode", Geneva, Verdana, sans-serif;
}
body {
background: #161c41;
}
.gallery {
position: relative;
float: left;
/* display: flex; */
}
.cardBx {
width: 100%;
/* min-height: 100%; */
/* display: flex; */
/* flex-wrap: wrap; */
justify-content: center;
align-items: center;
float: left;
}
.cardBx .card {
width: 280px;
border-radius: 10px;
margin: 20px 40px;
background: #1b2141;
overflow: hidden;
}
.cardBx .card img {
width: 100%;
height: 250px;
object-fit: cover;
}
.cardBx .card .content {
padding: 10px;
}
.cardBx .card .content h4 {
color: white;
margin: 15px 0;
}
.cardBx .card .progress-line {
position: relative;
height: 10px;
width: 100%;
background-color: #35407e;
margin-bottom: 15px;
border-radius: 10px;
transform: scaleX(0);
transform-origin: left;
animation: animate 1s cubic-bezier(1, 0, 0.5, 1) forwards;
}
.cardBx .card .progress-line span {
position: absolute;
height: 100%;
width: 80%;
border-radius: 10px;
background: #1aeeef;
transform: scaleX(0);
transform-origin: left;
animation: animate 1s cubic-bezier(1, 0, 0.5, 1) forwards;
}
#keyframes animate {
100% {
transform: scaleX(1);
}
}
.cardBx .card .info {
border-top: 2px solid #35407e;
padding: 5px;
display: flex;
justify-content: space-between;
align-items: center;
}
.cardBx .card .info p {
font-size: 1em;
color: white;
}
.cardBx .card .info p span {
color: #1aeeef;
}
.cardBx .card .content .info a {
display: inline-block;
padding: 10px 20px;
margin: 20px 0;
border: 1px solid #1aeeef;
text-decoration: none;
font-weight: 700;
border-radius: 5px;
color: white;
letter-spacing: 1px;
}
.cardBx .card .content .info a:hover {
background: #1aeeef;
border: none;
color: #050e2d;
box-shadow: 0 0 10px #1aeeef;
}
.cardBx {
display: flex;
justify-content: center;
align-items: center;
}
/* ////nav */
nav {
display: flex;
align-items: center;
justify-content: space-between;
background: #05123d;
height: 70px;
text-decoration: none;
}
.logo {
width: 160px;
margin-right: 45px;
margin-left: 10px;
}
.nav-left {
display: flex;
align-items: center;
}
.nav-left ul li {
font-family: "Gill Sans", "Gill Sans MT", Calibri, "Trebuchet MS", sans-serif;
cursor: pointer;
list-style: none;
margin-left: 70px;
text-decoration: none;
display: inline-block;
}
.nav-left ul li a {
color: rgb(255, 255, 255);
font-size: 25px;
font-family: "Lucida Sans", "Lucida Sans Regular", "Lucida Grande",
"Lucida Sans Unicode", Geneva, Verdana, sans-serif;
text-decoration: none;
padding: 1rem;
}
/* ===========hjbhedbfj======== */
/* html,
body {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
font-family: "Helvetica", sans-serif;
} */
img {
max-width: 100%;
}
.slider-container {
height: 600px;
width: 100%;
border-top: 2px solid #1aeeef;
border-bottom: 2px solid #1aeeef;
position: relative;
overflow: hidden;
text-align: center;
}
.menu {
position: absolute;
left: 0;
z-index: 900;
width: 100%;
bottom: 0;
}
.menu label {
cursor: pointer;
display: inline-block;
width: 16px;
height: 16px;
background: #fff;
border-radius: 50px;
margin: 0 0.2em 1em;
&:hover {
background: red;
}
}
.slide {
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 100%;
z-index: 10;
padding: 8em 1em 0;
background-size: cover;
background-position: 50% 50%;
transition: left 0s 0.75s;
}
[id^="slide"]:checked + .slide {
left: 0;
z-index: 100;
transition: left 0.65s ease-out;
}
.slide-1 {
background-image: url("https://wallpaperaccess.com/full/625497.jpg");
}
.slide-2 {
background-image: url("https://freefiremobile-a.akamaihd.net/common/web_event/official2.ff.garena.all/img/20228/29bfa3738921a9e9d096f5c4cdfaf297.jpg");
}
.slide-3 {
background-image: url("https://wallpaperaccess.com/full/625497.jpg");
}
/* ==========footer========== */
.bddiv {
display: inline-block;
vertical-align: middle;
color: #1aeeef;
}
<!DOCTYPE html>
<html lang="en">
<head>
<style>
#import url("https://fonts.googleapis.com/css2?family=Poppins:wght#200&display=swap");
</style>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<!-- css link -->
<link rel="stylesheet" href="./shop.css" />
<!-- <link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta2/css/all.min.css"
/> -->
<title>Shop</title>
</head>
<body>
<nav>
<div class="nav-left">
<img src="./ggh.svg" class="logo" />
<ul>
<li>Home</li>
<li><a>Turnament</a></li>
<li><a>News</a></li>
<li class="shopname"><a>Shop</a></li>
<li><a>About us</a></li>
</ul>
</nav>
<main>
<?php
include './slider/slider.php' ?>
<?php
include 'shopdb.php';
$sql="SELECT * from shop_table";
$query=mysqli_query($conn,$sql);
while($info=mysqli_fetch_array($query)){
?>
<div class="gallery">
<div class="cardBx">
<div class="card" data-item="pc">
<img src="shop/<?php echo $info['imageup']; ?>" alt="loding">
<div class="content">
<h4><?php echo $info['gamename']; ?></h4>
<div class="progress-line"><span></span>
</div>
<div class="info">
<p>pricing<br /><span> <?php echo $info['price']; ?></span></p>
Buy Now
</div>
</div>
</div>
</div>
</div>
<?php
}
?>
<div class="bddiv"> hello</div>
</main>
</body>
</html>
`
the float made this problem if you want to put your price section in the right , remove float and use this code:
.gallery {
position: relative;
}
.cardBx {
width: 100%;
justify-content: start;
align-items: center;
}
Please Try This
Just add clear:both as style in <div> containing "Hello" text
<div class="bddiv" style="clear:both;"> hello</div>
I just increase the padding-top and padding-left and it works fine, Here's the code of the CSS I changed.
.bddiv {
padding-top: 230px;
padding-left: 60px;
color: #1aeeef;
}
Just change the bddiv CSS. The Html code is working good
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'm trying to create a small website and want to place an image (logo, square, svg) in the navbar. I want the logo to fit the navbar but it simply just won't scale no matter what I try.
I've tried floating a div with the image to the left and the navbar to the right but it still won't scale. It's really frustrating.
Here's an image of the problem:
Here's my code (sorry it's messy):
#import url('https://fonts.googleapis.com/css?family=Montserrat');
.heading {
display: inline-block;
font-family: "Montserrat";
font-weight: lighter;
text-align: left;
margin-left: 20vw;
line-height: 30vw;
}
body {
width: 100%;
margin: auto;
font-family: 'Montserrat', sans-serif;
background-color: white;
}
.container {
display: flex;
flex-wrap: wrap;
flex-direction: row;
justify-content: center;
margin-top: 30px;
flex-flow: row wrap;
margin-top: -10vw;
}
img {
margin: 9px;
transition: filter 0.2s;
filter: brightness(100%);
display: inline-block;
min-height: 100px;
height: 50vh;
}
img:hover {
filter: brightness(80%);
}
.responsive:hover {}
header {
position: relative;
height: 50vh;
background-image: linear-gradient(rgb(50, 50, 50), rgb(30, 30, 30));
margin-top: -20px;
transform: skewY(-5deg);
transform-origin: top left;
}
.fullwidth {
width: 100%;
}
.headertitle {
margin-top: -36vh;
margin-left: 12vw;
position: absolute;
font-size: calc(13px + 2.5vw);
color: white;
font-family: 'Montserrat';
font-weight: lighter;
}
/* navbar */
nav {
background: rgb(52, 52, 52);
position: relative;
z-index: 1;
height: calc(18px + 6vh);
box-shadow: 0 3px 3px -1px rgba(0, 0, 0, 0.065);
overflow: auto;
width: 100vw;
}
nav ul {
margin: 0;
padding: 0;
text-align: left;
margin-left: 1.2vw;
}
nav ul li {
display: inline-block;
list-style: none;
font-size: 1.2em;
padding: 1vh;
}
.navul a {
text-decoration: none;
color: white;
line-height: 5.5vh;
height: 5.5vh;
font-size: calc(15px + 0.25vh + 0.15vw);
}
.navuul a:visited,
a:link,
a:active {
text-decoration: none;
color: white;
font-weight: 200;
line-height: 5.5vh;
height: 5.5vh;
}
.navuul a:hover {
text-decoration: none;
color: grey;
font-weight: 200;
line-height: 5.5vh;
height: 5.5vh;
}
.submit {
float: right;
margin-right: 1.5vw;
}
.submit a {
color: white;
border-radius: 5px;
}
.navimg img {
max-width: 100%;
max-height: 20%;
}
.navimgdiv {
height: 1.5vh;
}
/* navbar end */
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="pgallerystyles.css">
<title> Photo Gallery </title>
<link rel="shortcut icon" href="logo.ico">
</head>
<body>
<div class="fullwidth">
</div>
<nav>
<ul class="navul">
<li>
<div class="navimgdiv"><img class="navimg" src="logo.svg"></div>Lumastock</li>
<li>Photos</li>
<li>Featured</li>
<li>Contact</li>
<li>Pricing</li>
<li>Assesment Requirements</li>
<li class="submit">Submit a photo</li>
</ul>
</nav>
<header>
</header>
<h1 class="headertitle">Image Gallery</h1>
Thanks!
Simply use the logo outside of the list. I have added max-width for logo image. Optionally padding and margin you can customize based on your requirement. I hope this solution will be helpful.
.heading {
display: inline-block;
font-family: "Montserrat";
font-weight: lighter;
text-align: left;
margin-left: 20vw;
line-height: 30vw;
}
body {
width: 100%;
margin: auto;
font-family: 'Montserrat', sans-serif;
background-color: white;
}
.container {
display: flex;
flex-wrap: wrap;
flex-direction: row;
justify-content: center;
margin-top: 30px;
flex-flow: row wrap;
margin-top: -10vw;
}
img {
/* margin: 9px;
transition: filter 0.2s;
filter: brightness(100%);
display: inline-block;
min-height: 100px;
height: 50vh; */
max-width: 100%;
}
img:hover {
filter: brightness(80%);
}
.responsive:hover {}
header {
position: relative;
height: 50vh;
background-image: linear-gradient(rgb(50, 50, 50), rgb(30, 30, 30));
margin-top: -20px;
transform: skewY(-5deg);
transform-origin: top left;
}
.fullwidth {
width: 100%;
}
.headertitle {
margin-top: -36vh;
margin-left: 12vw;
position: absolute;
font-size: calc(13px + 2.5vw);
color: white;
font-family: 'Montserrat';
font-weight: lighter;
}
/* navbar */
nav {
background: rgb(52, 52, 52);
position: relative;
z-index: 1;
height: calc(40px + 6vh);
box-shadow: 0 3px 3px -1px rgba(0, 0, 0, 0.065);
overflow: auto;
width: 100vw;
display: flex;
}
nav ul {
margin: 0;
padding: 0;
text-align: left;
margin-left: 1.2vw;
}
nav ul li {
display: inline-block;
list-style: none;
font-size: 1.2em;
padding: 1vh;
}
.navul a {
text-decoration: none;
color: white;
line-height: 5.5vh;
height: 5.5vh;
font-size: calc(15px + 0.25vh + 0.15vw);
}
.navuul a:visited,
a:link,
a:active {
text-decoration: none;
color: white;
font-weight: 200;
line-height: 5.5vh;
height: 5.5vh;
}
.navuul a:hover {
text-decoration: none;
color: grey;
font-weight: 200;
line-height: 5.5vh;
height: 5.5vh;
}
.submit {
float: right;
margin-right: 1.5vw;
}
.submit a {
color: white;
border-radius: 5px;
}
.navimgdiv img {
max-width: 50px;
}
.navimgdiv {
padding: 5px 0;
}
<div class="fullwidth"></div>
<nav>
<a class="navimgdiv"><img src="https://cdn.worldvectorlogo.com/logos/react.svg"></a>
<ul class="navul">
<li>Lumastock</li>
<li>Photos</li>
<li>Featured</li>
<li>Contact</li>
<li>Pricing</li>
<li>Assesment Requirements</li>
<li class="submit">Submit a photo</li>
</ul>
</nav>
<header></header>
<h1 class="headertitle">Image Gallery</h1>
I want to left align text in a drop-down menu but I'm having some problems. I have this HTML
<nav>
<a>Vote</a>
<a>Search</a>
<a>About</a>
</nav>
and this CSS for the drop down menu
nav {
display: none;
width: 30rem;
padding: 0rem;
background-color: red;
position: absolute;
right: 0%;
top: 100%;
text-align: left;
}
.nav-open {
display: block;
}
nav a {
display: block;
width: 100%;
text-align: left;
padding: 1.4rem 1.6rem;
text-decoration: none;
cursor: pointer;
font-size: 1.2rem;
color: #000;
}
But as you can see, when you click the menu icon the text isn't even visible. Interestingly, when I change:
text-align: left;
to
text-align: center;
I can see the text again, but it is not aligned where i want it. How do I left align my text and keep it visible?
$('.menu-btn').click(function() {
$('nav').toggleClass('nav-open');
});
style* {
margin: 0 auto;
font-family: sans-serif;
}
body {
margin: 0 auto;
font-family: Benton Sans, -apple-system, BlinkMacSystemFont, Roboto, Helvetica Neue, Helvetica, Tahoma, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
}
header {
width: 100%;
background-color: orange;
text-align: center;
position: relative;
}
#pageTitle {
display: flex;
padding: 10px;
}
#pageTitle h2 {
justify-content: center;
/* align horizontal */
align-items: center;
width: 95%;
}
.menu-btn {
position: absolute;
display: inline-block;
cursor: pointer;
}
.menu-btn div {
position: absolute;
left: 100%;
top: 0%;
padding-right: 8px;
margin-top: -0.50em;
line-height: 1.2;
font-weight: 200;
vertical-align: middle;
z-index: 99;
}
.menu-btn span {
display: block;
width: 20px;
height: 2px;
margin: 4px 0;
background: #989da1;
z-index: 99;
}
nav {
display: none;
width: 30rem;
padding: 0rem;
background-color: red;
position: absolute;
right: 0%;
top: 100%;
text-align: left;
}
.nav-open {
display: block;
}
nav a {
display: block;
width: 100%;
text-align: left;
padding: 1.4rem 1.6rem;
text-decoration: none;
cursor: pointer;
font-size: 1.2rem;
color: #000;
}
nav a:hover {
background-color: #111;
color: #fff;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<header>
<div id="pageTitle">
<h2>Page Title</h2>
<div class="mobile-nav">
<button class="menu-btn" id="menu-btn">
<div></div>
<span></span>
<span></span>
<span></span>
</button>
<nav>
<a>Vote</a>
<a>Search</a>
<a>About</a>
</nav>
</div>
</div>
</header>
The problem comes from the rem unit you are using when giving width to your nav. You should use vw viewport width. This is relative from the screen width going from 0 to 100 turning the viewport width into a percentage.
Hope this helps
$('.menu-btn').click(function() {
$('nav').toggleClass('nav-open');
});
style* {
margin: 0 auto;
font-family: sans-serif;
}
body {
margin: 0 auto;
font-family: Benton Sans, -apple-system, BlinkMacSystemFont, Roboto, Helvetica Neue, Helvetica, Tahoma, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
}
header {
width: 100%;
background-color: orange;
text-align: center;
position: relative;
}
#pageTitle {
display: flex;
padding: 10px;
}
#pageTitle h2 {
justify-content: center;
/* align horizontal */
align-items: center;
width: 95%;
}
.menu-btn {
position: absolute;
display: inline-block;
cursor: pointer;
}
.menu-btn div {
position: absolute;
left: 100%;
top: 0%;
padding-right: 8px;
margin-top: -0.50em;
line-height: 1.2;
font-weight: 200;
vertical-align: middle;
z-index: 99;
}
.menu-btn span {
display: block;
width: 20px;
height: 2px;
margin: 4px 0;
background: #989da1;
z-index: 99;
}
nav {
display: none;
width: 100vw;
padding: 0rem;
background-color: red;
position: absolute;
right: 0%;
top: 100%;
text-align: left;
}
.nav-open {
display: block;
}
nav a {
display: block;
width: 100%;
text-align: left;
padding: 1.4rem 1.6rem;
text-decoration: none;
cursor: pointer;
font-size: 1.2rem;
color: #000;
}
nav a:hover {
background-color: #111;
color: #fff;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<header>
<div id="pageTitle">
<h2>Page Title</h2>
<div class="mobile-nav">
<button class="menu-btn" id="menu-btn">
<div></div>
<span></span>
<span></span>
<span></span>
</button>
<nav>
<a>Vote</a>
<a>Search</a>
<a>About</a>
</nav>
</div>
</div>
</header>
As others have pointed out already, the text is actually aligned left, but your screen size might prevent it from showing up due to the big width of your menu.
Try changing the width of your nav element to something relative to the page width, like 80%:
nav {
display: none;
width: 80%;
padding: 0rem;
background-color: red;
position: absolute;
right: 0%;
top: 100%;
text-align: left;
}
https://jsfiddle.net/1y8n08aq/1/