CSS - Border stretched to whole height of navbar - html

I am trying to make a border on the right of most of my LIs (that are also anchor tags) fill the entirety of the div vertically, with a width of 1em like this (my figma mockup):
However, all I am getting currently is this:
Here is my (S)CSS:
.navbar-main {
margin-top: 2em;
display: flex;
background-color: hsl(206, 97%, 13%);
color: hsl(0, 0%, 100%);
border-radius: 34px;
width: 90vw;
height: 3em;
margin-left: auto;
margin-right: auto;
justify-content: space-between;
text-align: center;
.links {
display: flex;
justify-content: flex-start;
margin-left: 2em;
align-items: center;
}
ul {
display: inherit;
flex-direction: row;
align-items: center;
flex-wrap: wrap;
gap: 1em;
height: 100%;
}
/* Add a vertical border to the right of all of the lis that stretches to the whole of the div vertically */
li {
border-right: 1px solid hsl(0, 0%, 100%);
}
.langselect {
margin-right: 2em;
display: inherit;
justify-content: flex-end;
align-items: center;
}
.icon {
margin-right: 0.5em;
height: 1em;
width: 1em;
font-size: inherit;
text-align: center;
display: inline-block;
vertical-align: middle;
}
}
And here is my HTML (REACT):
<div className="navbar-main">
<div className="links">
<ul> {/*TODO: Remember to put icons before the a tags! (USE BOOTSTRAP ICONS!) */}
<li>
<a href="#">
<FaHome className="home icon"/>
Portfolio/CV
</a>
</li>
<li>
<a href="#">
<FaBookOpen className="book icon"/>
Portfolio/CV
</a>
</li>
<li>
<a href="#">
<FaPuzzlePiece className="puzzle icon"/>
!?#!#*$%
</a>
</li>
</ul>
</div>
<div className="langselect">
<FaGlobe className="world icon"/>
<p>Language Select</p>
</div>
</div>
All help is appreciated, thanks a lot.

Turns out after a bit of back and forth debugging and writing code, I found out that I could do this:
li {
display: inherit;
height: 100%;
border-right: 1px solid hsl(206, 94%, 20%);
padding-right: 1em;
a {
margin-top: auto;
margin-bottom: auto;
}
}
li:last-child {
border-right: none;
padding-right: 0;
}
This works flawlessly too, as seen here:
Thanks anyway for your guys' help!

Related

Why does the image within the box shrink upwards when the window shrinks?

I really don't know what I'm doing wrong here. I want the image inside the box to stay centered when the window shrinks. Furthermore, I would have thought that align-items: center; would work, but apparently not. The colors are only relevant for me, so I understand what's going on. I don't know if there is a solution for this either, but I hope so. And please ignore the naming and order of the individual classes, I couldn't do better ...:)
.megadiv {
max-width: 1600px;
margin: auto;
text-align: center;
}
.centerbox {
display: flex;
justify-content: space-between;
}
.left {
width: 64%;
background-color: red;
justify-content: space-between;
border: 2px solid gray;
display: flex;
}
.insideleft {
width: 20%;
background-color: yellow;
align-items: center;
text-align: center;
align-content: center;
}
.insideright {
width: 78%;
background-color: purple;
float: right;
padding-top: 2%;
text-align: left;
border-left: 2px ridge #ffa54f;
padding-left: 2%;
padding-bottom: 1%;
}
.picture {
width: 80%;
border-radius: 1%;
margin-top: 10%;
margin-bottom: 8%;
}
.right {
width: 34%;
border: 2px solid gray;
height: 20px;
}
h7 {
color: rgb(0, 153, 158);
font-size: large;
font-family: sans-serif;
}
.textpart {
margin-bottom: 0.5%;
}
<div class="megadiv">
<div class="centerbox">
<div class="left">
<div class="insideleft">
<h20>
<a href="">
<img class="picture" src="https://images-na.ssl-images-amazon.com/images/I/71hi8fWdX2L.jpg"> </a>
</h20>
</div>
<div class="insideright">
<h7>Headline</h7><br>
<h4>
<div class="textpart">Authors</div>
<div class="textpart">Views <a class="" href="">Chapter 2</a></div>
<div class="textpart">Genres: Action - Adventure - Comedy</div>
<div class="textpart">Rating: ⭐⭐⭐⭐⭐</div>
</h4>
</div>
<div class="right">
wawaeaweew
</div>
</div>
</div>
h4 and h20 are empty
You're pretty close to getting the image vertically aligned as you wanted. Try this out, and see if this works the way you would like:
.megadiv {
max-width: 1600px;
margin: auto;
text-align: center;
}
.centerbox {
display: flex;
justify-content: space-between;
}
.left {
width: 64%;
background-color: red;
justify-content: space-between;
border: 2px solid gray;
display: flex;
}
.insideleft {
display: flex;
width: 20%;
background-color: yellow;
align-items: center;
text-align: center;
align-content: center;
}
.insideright {
width: 78%;
background-color: purple;
float: right;
padding-top: 2%;
text-align: left;
border-left: 2px ridge #ffa54f;
padding-left: 2%;
padding-bottom: 1%;
}
.picture {
width: 80%;
border-radius: 1%;
margin-top: 10%;
margin-bottom: 8%;
}
.right {
width: 34%;
border: 2px solid gray;
height: 20px;
}
h7 {
color: rgb(0, 153, 158);
font-size: large;
font-family: sans-serif;
}
.textpart {
margin-bottom: 0.5%;
}
<div class="megadiv">
<div class="centerbox">
<div class="left">
<div class="insideleft">
<a href="">
<img class="picture" src="https://images-na.ssl-images-amazon.com/images/I/71hi8fWdX2L.jpg"> </a>
</div>
<div class="insideright">
<h7>Headline</h7><br>
<h4>
<div class="textpart">Authors</div>
<div class="textpart">Views <a class="" href="">Chapter 2</a></div>
<div class="textpart">Genres: Action - Adventure - Comedy</div>
<div class="textpart">Rating: ⭐⭐⭐⭐⭐</div>
</h4>
</div>
<div class="right">
wawaeaweew
</div>
</div>
</div>
I saw you used align-items: center; in the .insideleft CSS selector which is for aligning a container's children to the center like you want, you'll just want to make this a flexbox to make this work. To do this, simply add display: flex; to the .insideleft selector like in the example. I also removed the <h20> tag from the HTML as this is not valid or necessary.
As for the image shrinking down when the screen width is shrinked - this is because you're using percentages for the widths for all the containers and the image. If you want the image to stop shrinking after a certain point, you can add min-width: 80px; /* (this can be any number of pixels) */ to your .picture selector to make the image stop shrinking once it gets to a certain width of pixels.
Flexbox is super useful for position elements in CSS and I'd recommend looking into this more to have a better understanding. Check out this link here if you'd like an overview of the different flexbox CSS properties.
I am not 100% sure on your intent - Here I changed the class names a bit for clarity and adjusted the markup for a left-middle-right
Not a huge fan of % for padding and margin sizing myself (em feels more clear since it is based on the current font size)
Not strictly needed but I added the containing element class in a few places in CSS for clarity example: .left-pane .picture-container
.page-container {
max-width: 1600px;
text-align: center;
}
.container-box {
display: flex;
align-content: space-between;
}
.container-box .left-pane {
width: 20em;
display: flex;
align-items: center;
justify-content: center;
background-color: #FF0000;
border: 2px solid gray;
}
.left-pane .picture-container {
width: 30%;
background-color: yellow;
align-items: center; /* vertical */
align-content: center; /* horizontal */
}
.left-pane .picture-container .picture {
width: 80%;
border-radius: 1%;
margin-top: 10%;
margin-bottom: 8%;
}
.container-box .middle-pane {
width: 70em;
background-color: #FFDDDD;
padding-top: 2%;
padding-left: 2%;
padding-bottom: 1%;
border-left: 2px ridge #ffa54f;
}
.middle-pane .headline {
color: rgb(0, 153, 158);
font-size: 1.5em;
font-family: sans-serif;
margin-bottom: 1em;
background-color: #eeeeee;
}
.middle-pane .textpart {
margin-bottom: 0.5em;
}
.container-box .right-pane {
height: 20px;
border: 2px solid gray;
}
<div class="page-container">
<div class="container-box">
<div class="left-pane">
<div class="picture-container">
<div>
<a href="">
<img class="picture" src="https://images-na.ssl-images-amazon.com/images/I/71hi8fWdX2L.jpg"> </a>
</div>
</div>
</div>
<div class="middle-pane">
<div class="headline">Headline</div>
<h4>
<div class="textpart">Authors</div>
<div class="textpart">Views <a class="" href="">Chapter 2</a></div>
<div class="textpart">Genres: Action - Adventure - Comedy</div>
<div class="textpart">Rating: ⭐⭐⭐⭐⭐</div>
</h4>
</div>
<div class="right-pane">
wawaeaweew
</div>
</div>
</div>

Align logo in left with link on the right navbar

I wanna to put a logo in the left of the navigation.
The links are set to justify-content: flex-end;
I tried to make a div element and make it important with !important property.
.navbar {
background-color: #242931;
top: 0%;
text-align: center;
justify-content: flex-end;
display: flex;
}
.left-nav {
justify-content: flex-start !important;
display: flex !important;
}
.navbar a {
color: #b7c2d0;
font-family: cubano;
font-size: 1.15rem;
text-decoration: none;
margin-right: 15px;
margin-left: 15px;
padding: 24px;
}
.navbar a:hover {
-webkit-background-clip: text;
background-image: linear-gradient(to right, #ff6e00, #ff9400, #ffb900, #f8dc00, #e9ff00);
background-clip: text;
color: transparent;
}
<div class="navbar">
<div class="left-nav">
example
</div>
Guides
Clips
Leaderborard
Support the server
Help
Rules
</div>
You don't need any div
simply assign margin-right: auto
to the first a (logo)
.navbar {
display: flex;
gap: 2em;
}
.navbar a:first-child {
margin-right: auto;
}
<div class="navbar">
LOGO
two
three
</div>
If you want to separate those two groups, wrap the actual navigation into a <nav> tag (and for better SEO), and use instead a margin-left: auto on it. The principle is the same:
.navbar {
display: flex;
}
.navbar nav {
display: flex;
gap: 2em;
margin-left: auto;
}
<div class="navbar">
LOGO
<nav>
two
three
</nav>
</div>
Nest the right-nav in a div also. Then you can use justify-content: space-between; which will space out the two divs. Then you can add align-items: center; to make them align.
.navbar {
background-color: #242931;
top: 0%;
text-align: center;
justify-content: space-between;
display: flex;
align-items: center;
}
.left-nav {
justify-content: flex-start !important;
display: flex !important;
}
.navbar a {
color: #b7c2d0;
font-family: cubano;
font-size: 1.15rem;
text-decoration: none;
margin-right: 15px;
margin-left: 15px;
padding: 24px;
}
.navbar a:hover {
-webkit-background-clip: text;
background-image: linear-gradient(to right, #ff6e00, #ff9400, #ffb900, #f8dc00, #e9ff00);
background-clip: text;
color: transparent;
}
<div class="navbar">
<div class="left-nav">
example
</div>
<div class="right-nav">
Guides
Clips
Leaderborard
Support the server
Help
Rules
</div>
</div>

Header content alignment / positioning

I have a project and i struggle with positioning elements in CSS. i want to create a header with a contact number and email to the right and in image at the centre.
The below is the code. suggestions to overcome this problem i'm facing are very welcome.
header {
display: block;
text-align: center;
}
#cw-logo-trans {
width: 200px;
display: inline-block;
align-items: right;
font-size: 24px;
}
#contacts {
margin-left: 5px;
float: left;
color: white;
font-size: 1.5em;
/* 40px/16=2.5em */
color: white;
}
.home {
width: 70px;
height: auto;
background-color: white;
padding: 10px;
margin: 10px;
float: left;
text-align: center;
}
<header>
<span id="cw-logo-trans" alt="cw-logo-trans">
<img src="images/cw_logo.png" alt="cw-logo-" > </span>
<span id="contacts">0800 111 111</br>email#emailyou.com</span>
<div class="home" alt="Home-button">Home</div>
</br>
</header>
Or you can use Flex as well.
.outer {
display: flex;
background-color: lightgray;
}
.outer div {
flex: 1;
align-items: center;
}
.logo {
display: flex;
justify-content: center;
}
<div class="outer">
<div></div>
<div class="logo">
<image src="https://facebookbrand.com/wp-content/uploads/2019/04/f_logo_RGB-Hex-Blue_512.png" height="40px" width="40px" />
</div>
<div>
<p>markzuckerberg#twitter.com</p>
<p>1234567890</p>
</div>
</div>

How do I make this banner look like the Urban Outfitters one?

I am trying to practice designing an online shop landing page, and I am taking inspiration from Urban Outfitters. I am trying to get the orange promo part to look the same as Urban Outfitters.
I have tried justify-content: center and space-around, or also using padding but that is not very responsive.
Codepen here.
*{
margin: 0px;
padding: 0px;
border-sizing: border-box;
}
#promo{
background-color: #F5C793;
display: flex;
align-items: center;
min-height: 50px;
justify-content: space-around;
}
.promo-link{
color: #222;
text-decoration-color: #222;
}
nav{
display: flex;
border-bottom: 0.3px solid #d3d3d3;
min-height: 40px;
align-items: center;
justify-content: center;
}
.nav-links{
display: flex;
list-style: none;
padding-left: 20px;
}
.nav-links li{
padding-left: 15px;
padding-right: 15px;
}
nav a{
text-decoration: none;
color: #767676;
}
nav a:hover{
color: #b2b2b2;
border-bottom: 1px solid black;
}
.logo{
color: #30336b;
text-transform: uppercase;
padding-left: 50px;
}
.landing-body{
padding-top: 10px;
padding-left: 10px;
padding-right: 10px;
display:inline;
}
.landing-page{
display: grid;
grid-template-columns: 49% 2% 49%;
overflow: hidden;
margin-left: 20px;
margin-right: 20px;
}
.three-div{
display: grid;
grid-template-columns: 32% 2% 32% 2% 32%;
overflow: hidden;
margin-left: 20px;
margin-right: 20px;
}
img{
display: inline;
opacity: 1.0;
padding-top: 10px;
width: 100%;
}
img:hover{
opacity: 0.8;
}
<div id="promo">
<p>everything you love, all in one place.</p>
<h3 class="center">MOST ♥ LIKED </h3>
<p>shop</p>
</div>
<nav>
<div class="logo">
<h2>Giants & Dwarfs</h2>
</div>
<ul class="nav-links">
<li id="about">About</li>
<li id="womens">Women's</li>
<li id="mens">Men's</li>
<li id="sale">Sale</li>
</ul>
</nav>
<div class="landing-page">
<img src="https://images.ctfassets.net/q602vtcuu3w3/7rnjSHqBEcgbtJ2pZqZarm/c32a5cbe533a8aab72aee54689ddb7e3/190617-WK3-WGW-4-Update.jpg">
<a></a>
<img src="https://images.ctfassets.net/q602vtcuu3w3/6vo26Ry1p3rcvSURCYBoJH/2fdc52ccb0ee69352d8e02ff905d592a/190603-WK1-LGW-1.jpg">
</div>
<div class="three-div">
<a href="#">
<img src="https://images.ctfassets.net/q602vtcuu3w3/7btvNrhUWJrd5UWYSRHtJr/43f9ce8f23d39c839f9b0e34991d97cc/190603-WK1-MGW-5.jpg">
</a>
<a></a>
<a href="#">
<img src="https://images.ctfassets.net/q602vtcuu3w3/5674zBs4G9hFqVyg2ceT6y/83fd495152f58a7bd12e64d68e541dcd/190617-WK3-HGW-7.jpg">
</a>
<a></a>
<a href="#">
<img src="https://images.ctfassets.net/q602vtcuu3w3/3Rz4KD78yXurQYIyqx6oyC/be018c5eeecd2df0a81471bb81177d8d/190617-WK3-WGW-7.jpg">
</a>
</div>
<div class="exclusives">
</div>
Trying to replicate this, top orange section
I am not a CSS expert by any stretch, but I have played around a bit with it. Have you tried using the following options?
padding-right: 15px;
padding-left: 15px;
margin-left: 1%;
Padding adds space to the left or to the right of your object. Margin adds space around your object. Either can be expressed as pixels or percentage. I have often found percentages to be more reliable for expected output than pixels, but again, I am not an expert so it could be my own unfamiliarity at work there.
For more detail: https://www.w3schools.com/cssref/pr_padding.asp
Hope this helps - happy coding to you!
You can use margins with flexbox, pretty much like align-self with much more control.
#promo {
background-color: #F5C793;
display: flex;
align-items: center;
min-height: 50px;
}
.left {
margin-left: auto;
}
.center {
margin: 0 20px;
}
.right {
margin-right: auto;
}
<div id="promo">
<p class="left">everything you love, all in one place.</p>
<h3 class="center">MOST ♥ LIKED </h3>
<p class="right">shop</p>
</div>
Force your inner elements to display as inline block, add some padding to your center element and flip your promo class from flex to block.
in the below example there are 2 new class (sideMe and sideMeCenter) and a mod to your display property in promo
add the classes to the contained promo elements and should be good to go
.sideMe {
display: inline-block;
margin:10px
}
.sideMeCenter {
padding: 0 40px;
}
*{
margin: 0px;
padding: 0px;
border-sizing: border-box;
}
#promo{
background-color: #F5C793;
display: block;
align-items: center;
min-height: 50px;
justify-content: space-around;
text-align:center;
}
.promo-link{
color: #222;
text-decoration-color: #222;
}
nav{
display: flex;
border-bottom: 0.3px solid #d3d3d3;
min-height: 40px;
align-items: center;
justify-content: center;
}
.nav-links{
display: flex;
list-style: none;
padding-left: 20px;
}
.nav-links li{
padding-left: 15px;
padding-right: 15px;
}
nav a{
text-decoration: none;
color: #767676;
}
nav a:hover{
color: #b2b2b2;
border-bottom: 1px solid black;
}
.logo{
color: #30336b;
text-transform: uppercase;
padding-left: 50px;
}
.landing-body{
padding-top: 10px;
padding-left: 10px;
padding-right: 10px;
display:inline;
}
.landing-page{
display: grid;
grid-template-columns: 49% 2% 49%;
overflow: hidden;
margin-left: 20px;
margin-right: 20px;
}
.three-div{
display: grid;
grid-template-columns: 32% 2% 32% 2% 32%;
overflow: hidden;
margin-left: 20px;
margin-right: 20px;
}
img{
display: inline;
opacity: 1.0;
padding-top: 10px;
width: 100%;
}
img:hover{
opacity: 0.8;
}
.exclusives-title{
padding-top: 20px;
text-align: center;
display: grid;
}
.exclusives-title h2{
font-weight: 100;
padding-bottom: 5px;
}
.exclusives{
grid-template-columns: 14% 3.2% 14% 3.2% 14% 3.2% 14% 3.2% 14% 3.2% 14%;
overflow: hidden;
margin-left: 20px;
margin-right: 20px;
}
<div id="promo">
<p class ="sideMe">everything you love, all in one place.</p>
<h3 class="center sideMe sideMeCenter">MOST ♥ LIKED </h3>
<p class="sideMe">shop</p>
</div>

getting images and Divs to be the same size with flexbox

I know this is probably a basic question but so far I have not been able to resolve it via google:
I want to have a navbar with an Image (a logo) and 3 links on its right. I want them all to have the same height and to be on the same height, a little bit like this:
however all I manage is to make it look like this:
#nav-bar {
position: fixed;
top: 0px;
width: 100%;
background: #b7b7b7;
border: 1px #4c4c4c solid;
padding: 1em;
}
#flex {
display: flex;
justify-content: start;
flex-wrap: wrap;
align-content: center;
}
img {
margin-top: 20px;
height: auto;
width: 15%;
}
.nav-link {
border: 1px solid #4c4c4c;
padding: 0.5em;
background-color: #b7b7b7;
color: black;
text-decoration: none;
}
<nav id="nav-bar">
<div id="flex">
<div><img src="https://i.pinimg.com/originals/58/c8/82/58c88275c1a3389a7260baf05bf34e9a.jpg" alt="violin logo" id="header-img"></div>
Products
Demo
Newsletter
</div>
</nav>
Maybe something like this:
#nav-bar {
position: fixed;
top: 0px;
width: 100%;
background: #b7b7b7;
border: 1px #4c4c4c solid;
padding: 1em;
}
#flex{
display: flex;
justify-content: space-between;
flex-wrap: wrap;
align-content: center;
}
img {
height: 50px;
width: auto;
}
.nav-links {
padding-right: 50px;
}
.nav-links .nav-link {
border: 1px solid #4c4c4c;
background-color: #b7b7b7;
color: black;
height: 50px;
display: inline-block;
text-decoration: none;
}
<nav id="nav-bar">
<div id="flex">
<img src="https://i.pinimg.com/originals/58/c8/82/58c88275c1a3389a7260baf05bf34e9a.jpg" alt="violin logo" id="header-img">
<div class="nav-links">
Products
Demo
Newsletter
</div>
</div>
</nav>
Just wrap links into a div, then set justify-content to 'space-between' and set the same height of both image and div with links. Hope it will help
You almost did it, the only thing you needed was basically to size the <div> around the <img> appropriately, so the <img> could just fill it:
#nav-bar {
position: fixed;
top: 0;
left: 0;
width: 100%;
background: #b7b7b7;
border: 1px #4c4c4c solid;
padding: 1em;
box-sizing: border-box; /* to exclude paddings&borders from width instead of adding them */
}
#flex{
display: flex;
justify-content: start;
align-items: stretch;
}
/* sizing the div with the img */
#flex > div {
width: 15%;
flex: 1 0 auto;
}
/* making the img filling this div */
img{
display: block;
width: 100%;
}
.nav-link{
border: 1px solid #4c4c4c;
padding: 0.5em;
background-color: #b7b7b7;
color: black;
text-decoration: none;
/* making links fill all the space, except some gaps between them */
flex: 1 1 auto;
margin-left: .5em;
/* centering the text in the links and making it responsive */
display: flex;
justify-content: center;
align-items: center;
font-size: calc(10px + 2vw);
}
<nav id="nav-bar">
<div id="flex">
<div>
<img src="https://i.pinimg.com/originals/58/c8/82/58c88275c1a3389a7260baf05bf34e9a.jpg" alt="violin logo" id="header-img">
</div>
Products
Demo
Newsletter
</div>
</nav>