Flexbox justify content space between not responsive - html

I'm having a very basic problem with the CSS in my React website, and I was looking for some help.
I have a very barebones header section set up
HTML:
<div className="nav">
<div className="menu">
Menu
</div>
<div className="logo">
<a className="title" href="/">Brand Name</a>
<a className="subtitle" href="/">Slogan</a>
</div>
<div className="lang">
<ul>
<li>FB</li>
<li>IG</li>
<li>TW</li>
</ul>
</div>
</div>
CSS:
body {
margin: 0;
padding: 0;
}
.nav{
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
color: white;
text-decoration: none;
font-family: Visual;
letter-spacing: 1px;
width: 100%;
.menu{
a{
text-decoration: none;
color: white;
letter-spacing: 1.3px;
font-size: 1.2rem;
}
}
.logo{
.title{
font-size: 2rem;
}
.subtitle{
text-align: center;
margin-top: 5px;
}
a{
text-decoration: none;
color: white;
display: block;
}
}
.lang{
font-size: 1.2rem;
ul{
li{
display: inline;
margin-left: 10px
}
}
}
}
The flex seems to be working, but when I resize the window horizontally, the center element gets pushed off center and eventually out of the screen on one side.
Is this related to media queries?

add padding: 0; property to ul in your css
ul {
padding: 0;
li {
display: inline;
margin-left: 10px;
}
}
You can use border styling something like
border: 1px solid black;
when have problems with css. In this way, you can see which elements have unexpected properties like paddings or margins. When you use border styling for your ul, you will see it has padding. Make padding zero and your items will be centralized.

Related

how to making the navigation menu size equal to the navigation menu child size?

I am creating a navigation menu. Inside the navigation menu I have child navigation menu. I want the size of navigation menu equal to the child navigation menu.
I created three hyper-tags and then there is a div element which is the element after the hyper tags. I am floating the three hyper tags as well as div element to the left.
the div element contains one button and div. I am setting the child div element to be absolute so its drawing itself below the button. I want the size of button to be equal to the size of the div element which contains child links. I thought if I set the root div element with position relative it will have the same width of the button but its not working. Here the css and html code. Any answers would be really appreciated.
/* css */
<style>
.navbar {
background: #006669;
overflow: hidden;
}
.navbar a{
float: left;
padding: 15px 15px;
text-decoration: none;
color: white;
font-size: 1.1rem;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
.navbar .subnav{
float: left;
border:1px solid black;
}
.navbar .subnav .subnavbutton{
padding: 15px 15px;
text-decoration: none;
color: white;
font-size: 1.1rem;
border: none;
outline: none;
background: transparent;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
.navbar .subnav .subnavcontent{
position:absolute;
border: 1px solid red;
min-width: 100px;
display: none;
}
.navbar .subnav .subnavcontent a{
float: none;
color: #444;
background: white;
display: block;
}
.navbar .subnav .subnavcontent a:hover{
background: #a0a0a0;
}
.navbar .subnav:hover .subnavcontent{
display: block;
}
</style>
here is the body content
<div class="navbar">
Home
News
<div class="subnav">
<button class="subnavbutton">Contact</button>
<div class="subnavcontent">
link1
link2
link3
</div>
</div>
</div>
I can do what you want using a flex-box based nav
html
<nav>
<ul>
<li>Home</li>
<li>News</li>
<li class="dropdown">Menu
<ul id="dropdown-menu" class="dropdown-menu">
<li>link1</li>
<li>link2</li>
<li>link3</li>
</ul>
</li>
</ul>
</nav>
css
nav ul {
background: #006669;
list-style-type: none;
display: flex;
flex-flow: row nowrap;
justify-content: flex-start;
align-items: center;
}
nav a {
color: white;
font-size: 1.5rem;
text-decoration: none;
display: block;
padding: 1rem;
}
nav a:hover {
background: white;
color: #006669;
}
nav ul ul {
display: flex;
flex-flow: column nowrap;
justify-content:flex-start;
align-items: center;
}
.dropdown {
position: relative;
}
.dropdown-menu {
display: none;
position: absolute;
z-index: 1;
}
.dropdown:hover .dropdown-menu {
display: block;
width: 100%;
padding:0;
border: 1px solid #006669;
}

How do I add corner logos into Footer using Html & CSS?

So for one of my school projects, we have to design a website using Html & CSS and I've encountered a problem where I don't know how to fit 2 logos (left & right) into the corners of my footer. I've tried to change the position, float, width etc and it doesn't seem to work, the logo always seems to not go in the place I want it to be. Sorry if this sounds amateur as I've only started doing Html & CSS a few weeks ago.
This is the current image where the logo is below my ul's and is in the incorrect position. -
This is what I want the footer to look like, it would be great to have the text on the left "Sponsored by HP omen gaming" to be a image as I may swap it out with another logo in the future. -
Thanks to anyone in advance who may be able to solve this problem for me, below would be my html & CSS code.
.footer {
background-color: #035642;
margin-top: 10px;
height: 60px;
color: #efe5d0;
text-align: center;
padding: 15px;
font-size: 100%;
font-family: Arial;
display: block;
}
.footer ul {
padding: 5px;
list-style-type: none;
text-align: center;
margin: 10px;
overflow: hidden;
}
.footer li {
text-decoration: none;
text-align: center;
font-family: arial;
font-weight: bold;
list-style-type: none;
display: inline-block;
}
.footer ul li {
display: inline-block;
}
.footer ul li a {
text-decoration: none;
padding: .2em 1em;
color: #efe5d0;
background-color: #5c755e;
text-align: center;
font-family: arial;
font-weight: bold;
}
.footer ul li a:hover {
color: #000;
background-color: #fff;
}
#footer-right {
height: 50px;
width: auto;
position: fixed;
float: right;
}
<div class="footer">
<li>WBHS ESPORTS</li>
<ul>
<li>Facebook</li>
<li>|</li>
<li>YouTube</li>
<li>|</li>
<li>Twitch</li>
</ul>
<img src="hp-omen-logo.png" id="footer-right">
</div>
Try look into flexbox. Here's a quick template to do what you want.
.footer {
display: flex;
justify-content: space-between;
}
.center {
text-align: center;
}
<div class="footer">
<p>Left</p>
<div class="center">
<p>Some text</p>
<p>Your list</p>
</div>
<p>Right</p>
</div>
I think a solution can be the use of display:flex
And to be more clean try to use also the widgets, you can see in this example how it works.
.footer {
background-color: #035642;
margin-top: 10px;
height: 60px;
color: #efe5d0;
text-align: center;
padding: 15px;
font-size: 100%;
font-family: Arial;
display: block;
}
.footer ul {
padding: 5px;
list-style-type: none;
text-align: center;
margin: 10px;
overflow: hidden;
}
.footer li {
text-decoration: none;
text-align: center;
font-family: arial;
font-weight: bold;
list-style-type: none;
display: inline-block;
}
.footer ul li {
display: inline-block;
}
.footer ul li a {
text-decoration: none;
padding: .2em 1em;
color: #efe5d0;
background-color: #5c755e;
text-align: center;
font-family: arial;
font-weight: bold;
}
.footer ul li a:hover {
color: #000;
background-color: #fff;
}
#footer-right {
height: 50px;
width: auto;
position: fixed;
float: right;
}
/*my-edit*/
#the-footer{
display:flex;
flex-wrap:wrap;
justify-content:space-between;
align-items:center;
height: auto;
margin: 0;
padding: 10px;
}
#the-footer .widget{
width: 30%;
}
#the-footer .widget.left{
text-align: left;
}
#the-footer .widget.right{
text-align: right;
}
#the-footer .widget.center{
text-align: center;
}
#the-footer .widget .title{
font-weight: bold;
letter-spacing: 2px;
}
#the-footer .widget .logo-link{
color:#fff;
display: inline-block;
text-decoration: none;
max-width:150px;
}
#the-footer .widget .logo-link:hover{
color:#000;
}
<div class="footer" id="the-footer">
<div class="widget left">
<a class="logo-link" href="#" target="_blank">Sponsored by HP omen gaming</a>
</div>
<div class="widget center">
<div class="title">WBHS ESPORTS</div>
<ul class="footer-nav">
<li>Facebook</li>
<li>|</li>
<li>YouTube</li>
<li>|</li>
<li>Twitch</li>
</ul>
</div>
<div class="widget right">
<a class="logo-link" href="#" target="_blank"><img class="logo-footer" src="https://via.placeholder.com/60" alt="logo"></a>
</div>
</div>
You can use the display: grid property so you can separate your footer into 3 parts
You can learn about the grid property here: https://www.w3schools.com/css/css_grid.asp

Display link to each other in navagation

I tried several times, float: right or display: inline-block, but it didn't work on my side. Can anyone guys help me to achieve it? I want to display my navigation next to each other just like below.
I tried to run several codes just what I mention above. But seems it need your help to work it properly.
.menu {
list-style-type: none;
display: inline-block;
padding: 0 11px;
font-size: 1.5rem;
margin-right: 6rem;
font-family: "Montserrat", sans-serif;
}
ul li .link {
position: relative;
display: inline-block;
}
ul li a {
text-decoration: none;
text-transform: uppercase;
}
.head {
position: relative;
text-align: right;
width: 100%;
padding: 22px 48px 25px;
border-bottom: 1px solid #f5f5f5;
}
div .logopix {
height: 5rem;
display: inline-block;
font-size: 0;
top: 1.1rem;
left: 37px;
position: absolute;
}
<div class="head">
<img class="logopix" src="./images/logo.png" alt="HUB Motivator Logo" >
<ul class="menu">
<li class="link"> About </li>
<li class="link"> Contact Us </li>
</ul>
</div>
add css in
.menu {
display: flex;
justify-content: flex-end;
}
Following same technique as you used with inline-block, to display li on same line add:
ul li {
display: inline-block;
}
Here is the code: Codepen
You can achieve the same requirement by writing very minimal semantic code and styling. Please check the code below.
Semantic HTML code
<header class="header">
<img src="http://via.placeholder.com/150x60"/>
<nav class="navbar">
About
Services
Contact
</nav>
</header>
CSS Style
.header {
display: flex;
justify-content: space-between;
align-items: center;
}
.navbar a {
padding-left: 10px;
font-size: 20px;
}
View Demo : jsfiddle

White space above the body when I use "height:100vh"

I've got a basic HTML document setup and I want the div to have the height of the view port. But as soon as I add height:100vh to the .main div there's a gap above the body and there's a vertical scroll bar
Here's my code.
HTML:
<div class="main">
<div class="container">
<div class="nav">
<ul>
<li>Work</li>
<li>About</li>
<li>Contact</li>
</ul>
</div>
<div class="main_text">
<h1>Hey there! I'm <span class="yellow">Gautham SK</span>, a digital designer & web developer.</h1>
</div>
</div> <!-- end container -->
</div> <!-- end main -->
CSS:
html, body {
height: 100%;
padding: 0;
margin: 0;
font-family: 'Montserrat', sans-serif;
font-weight: 400;
}
.container {
max-width: 1024px;
padding: 0 20px;
margin: 0 auto;
}
/* NAVIGATION */
.nav ul {
display: flex;
align-items: center;
justify-content: flex-end;
/* margin-top: 75px;*/
list-style-type: none;
}
.nav ul li {
margin-left: 40px;
list-style: none;
font-size: 16px;
}
.nav ul li a, .nav ul li a:visited {
color: #000;
padding: 5px;
text-decoration: none;
transition: 0.2s color;
}
.nav ul li a:hover {
color: #ffde00;
transition: 0.2s color;
}
.nav ul li a.active {
color: #000;
border-bottom: 5px solid #ffde00;
}
/* MAIN SECTION */
.main {
background: url("../images/bg.jpg") center center no-repeat;
background-size: cover;
}
.main, .main .container {
height: 100vh;
}
.main_text {
height: 100%;
text-align: center;
display: flex;
align-items: center;
justify-content: center;
}
.main_text h1 {
font-weight: 400;
font-size: 45px;
}
span.yellow {
color: #ffde00;
}
I've also got a normalize.css linked to this document. I tried to remove the padding and margin for all the elements but that doesn't work.
UPDATE
Yay! Found the solution. Here's what I did:
Removed the margin for the nav and it's children and replaced it with a top padding to get the desired look.
Changed the height of the main_text to 80%.
If you've got a better solution, let me know!
As a simple test, set padding: 1px on body. If the gap goes away read: http://www.sitepoint.com/web-foundations/collapsing-margins/

How to center nav in div

I am trying to center the navigation bar in the middle of the div body. I want the navigation bar to go from one side of the div to the other but have the list in the ul to be center in the middle of the div if that makes sense. I can't seem to figure it out even after trying online examples. Thanks
body {
margin: 0px;
padding: 0px;
background-color: #505050 ;
}
#body {
width: 75%;
margin: 0 auto;
position: center;
background-color: #C0C0C0;
height: 100%;
}
.nav {
}
.nav ul {
background-color: #CCCCCC;
width: 100%;
padding: 0;
text-align: center;
}
.nav li {
list-style: none;
font-family: Arial Black;
padding: 0px;
height:40px;
width: 120px;
line-height: 40px;
border: none;
float: left;
font-size: 1.3em;
background-color: #CCCCCC;
display:inline;
}
.nav a {
display: block;
color: black;
text-decoration: none;
width: 60px;
}
<div id="body">
<h2>Hello World!</h2>
<div class="nav">
<ul>
<li><a href="#">Home<a></li>
<li><a href="#">About<a></li>
<li><a href="#">News<a></li>
<li><a href="#">Contact<a></li>
</ul>
</div>
</div>
i attach fix here http://jsfiddle.net/o4716uo9/
use inline-block for li
background property should be setted in ul element, not li, in your case. Delete the float in nav li. Also, the a element it isn't closed correctly. Main changes:
.nav ul {
background-color: #cccccc;
text-align: center;
}
.nav ul li {
display: inline-block;
min-width: 120px;
[...]
}
I'll recommend you to take a look at the bootstrap framework. It could be interesting for you.
There are a couple things you can change to correct the issue:
1) Your <a> elements have a width of 60px. You can remove this.
2) You .nav li has a width of 120px. I would change this to 25% (If there are only going to be four navigational items).
http://jsfiddle.net/xLnz90ek/
Is that any closer to the desired effect.
Is this what you’re trying to do?
* { margin:0; padding:0 }
html {
background-color: #505050;
font-size: 4vw;
}
header {
width: 75%;
margin: 0 auto;
background-color: #C0C0C0;
}
nav {
background-color: #CCCCCC;
display: flex;
padding: 0.2rem 0;
}
nav a {
flex: 1 0 auto;
font-family: Arial Black;
font-size: 1rem;
background-color: #CCCCCC;
color: black;
text-decoration: none;
text-align: center;
margin: 0 0.3rem;
}
<header>
<h2>Hello World!</h2>
<nav>
Home
About
News
Contact
</nav>
</header>