I can't change the position of these elements - html

I would like to change the position of these buttons inside my navbar, also I would like you to tell me if it's correct what I'm doing in my CSS. the main idea is that I wanted to make a navbar, just I wonder to know if it's right how I did it.
Note: About the position of the buttons, as you can see I set 20 px to the margin button(before I set a position relative), but as you can see nothing happen.I would like to move the buttons more to the top.
Another doubt that I've got now, is how do I have to move, the <a> tags or the <li> or both?
Thanks!
body {
background-color: #fcf2e5;
margin: 0;
}
nav {
background-color: #beb8a4;
height: 120px;
}
.menu {
padding-left: 380px;
}
/* Nav Buttons */
.menu li {
display: inline;
font-family: sans-serif;
font-size: 1.2em;
padding-left: 40px;
text-decoration: none;
}
.navButtons {
text-decoration: none;
color: black;
}
.navButtons:hover {
color: #a52929;
}
/*I don't know if it's correct what I'm doing here below*/
ul,
li,
a {
display: inline;
position: relative;
margin-bottom: 20px;
}
/* Logo */
header nav a img {
margin-top: 20px;
margin-left: 22px;
}
<header>
<nav>
<a href="#">
<img src="Images/logo.png" title="Home" alt="Logo" />
</a>
<ul class="menu">
<li>Quienes Somos
</li>
<li>Muestras y Acabados
</li>
<li>Ubicación
</li>
<li>Contáctenos
</li>
</ul>
</nav>
</header>

Most navbars look a little like this these days. Very little markup and a bit of CSS to make it looks nice.
I've used flexbox for positioning. You can position things at the top bottom or centre using this method.
It's also using media queries, this is so it can cope with a small screen (which the snippet will have) press full screen to swap between its states.
body {
background-color: #fcf2e5;
margin: 0;
}
/* Start of navbar */
nav {
background-color: #beb8a4;
display: flex;
padding: 15px 0;
height: 100%;
align-items: center;
justify-content: space-around;
}
/* Nav buttons */
.navButtons {
font-family: sans-serif;
font-size: 1.2em;
text-decoration: none;
color: black;
}
.navButtons:hover {
color: #a52929;
}
/* Small screen support */
#media only screen and (max-width: 640px) {
nav {
flex-direction: column;
}
.navButtons {
text-align: center;
font-size: 1.6em;
max-width: 180px;
margin-top: 10px;
}
}
<nav>
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/7/7d/BBC_America.svg/100px-BBC_America.svg.png" title="Home" alt="Logo" />
About us
Samples and Finishes
Find us
Contact us
</nav>
Hope you find this helpful.

Related

How can I make my webpage icon stay right? [duplicate]

This question already has answers here:
How can I align one item right with flexbox?
(5 answers)
Closed 1 year ago.
I have made a navbar, and it is supposed to replace the links with a menu icon on the right when the webpage gets below 630px wide. The problem is, my icon doesn't stay right, it stays as far left as it can go, leaving space for the margins of the hidden links (the elements themselves are gone - I set them to display: none; - but the margins are still there). I am working with the w3 schools article about responsive navbars, but only using it for the appearing icon part.
I have tried to change he display of the icon to flex, and all sorts of justification and alignment, but nothing will work. When it is set to flex it's width goes to 0 and I cant make it get wider again.
I am trying to give only the relevant code, but there is a fair amount of stuff I didn't include so feel free to ask me for more or to specify something.
.navContainer {
position: sticky;
top: 0;
margin: 0;
background-color: #ffffff;
display: flex;
justify-content: left;
align-content: flex-start;
padding-left: 10px;
padding-top: 20px;
padding-bottom: 10px;
}
.navContainer li {
list-style: none;
margin-right: 40px;
}
.navContainer a {
text-decoration: none;
color: black;
font-family: Montserrat-Regular;
font-size: 20pt;
margin: 10px;
}
.navContainer .icon {
display: none;
margin: 0;
}
.navContainer .iconImg {
max-height: 40px;
max-width: 40px;
}
#media (max-width: 630px) {
.navContainer a:not(.logoContainer, .name) {
display: none;
}
.navContainer li.icon {
float: right;
display: block;
}
}
<ul class="navContainer">
<li class="logoContainer"><img href="TriTech-Home.html" class="logo" src="https://via.placeholder.com/80"></img>
</li>
<li>TriTech</li>
<li><a class="link1" href="#">xDesk</a></li>
<li><a class="link2" href="#">Saturn Bikes</a></li>
<li href="javascript:void(0);" class="icon" onclick="myFunction()">
<img class="iconImg" src="Menu-Bars.ico">
</li>
</ul>
Don't float things. That's an outdated method, especially with flexbox. Use auto left margin on the last item.
.navContainer {
position: sticky;
top: 0;
margin: 0;
background-color: #ffffff;
display: flex;
justify-content: left;
align-content: flex-start;
padding-left: 10px;
padding-top: 20px;
padding-bottom: 10px;
}
.navContainer li {
list-style: none;
margin-right: 40px;
}
.navContainer a {
text-decoration: none;
color: black;
font-family: Montserrat-Regular;
font-size: 20pt;
margin: 10px;
}
.navContainer .icon {
display: none;
margin: 0;
}
.navContainer .iconImg {
max-height: 40px;
max-width: 40px;
}
#media (max-width: 2630px) { /* increased for demo */
.navContainer a:not(.logoContainer, .name) {
display: none;
}
.navContainer li.icon {
display: inline-block;
margin-left: auto; /* <-------------------- HERE */
}
}
<ul class="navContainer">
<li class="logoContainer"><img href="TriTech-Home.html" class="logo" src="https://via.placeholder.com/80" />
</li>
<li>TriTech</li>
<li><a class="link1" href="#">xDesk</a></li>
<li><a class="link2" href="#">Saturn Bikes</a></li>
<li href="javascript:void(0);" class="icon" onclick="myFunction()">
<img class="iconImg" src="https://via.placeholder.com/40">
</li>
</ul>
This should work
.nav-container .icon{
width: 100%;
text-align: end;
}

Navbar chopped off when resizing

My navbar gets chopped off from both sides whenever I resize the window, like in this picture.
Chop chop
I want the navbar to fit the entire screen, even when the window is resized, so that all the links and logo are visible.
I tried making the width 100vw but it has no visible effect.
Here is my HTML and CSS:
<header>
<nav>
<ul>
<li><div class="container"><img src="https://i.ibb.co/SP0TLzQ/broozeb.png" alt="logo" class="logo" border="0"><div class="overlay"><div class="text-test">米</div></div></div></li>
<li>ホーム</li>
<li>米さんについて</li>
<li>日本の文化</li>
<li>学習の情報</li>
<li>English Stuff</li>
</ul>
</nav>
</header>
nav {
background-color: blue;
border-bottom: solid #09316b;
white-space: nowrap;
}
nav ul {
margin: 0;
padding: 0;
display: flex;
justify-content: center;
}
nav ul li {
list-style-type: none;
margin-left: 5px;
}
nav ul li a {
color: white;
background-color: blue;
display: block;
line-height: 3em;
padding: 2em 4em;
text-decoration: none;
font-weight: bold;
}
nav ul li .logo {
background-color: white;
border-radius: 50%;
margin-left: 10px;
}
nav a:hover {
color: red;
background-color: white;
transition: all 0.3s ease 0s;
}
I'm really sorry to ask such basic questions, but this has been troubling me for a few weeks. I very very much appreciate your help!! My webpage can be found here: https://komesannonihongotabi.neocities.org/culture.html
This is being caused by the following CSS line:
nav ul li a {
padding: 2em 4em;
}
Your a tags have a padding on left and right of 4em. Since em is an absolute unit and not a relative one, it will stay the same on any screen size. That is, unless you change the font-size to be smaller but I don't think that would be a good solution here. Just try adding a relative unit like %, or use a breakpoint as follows:
nav ul li a {
padding: 2em 1em;
}
#media screen and (min-width: 900px) {
nav ul li a {
padding: 2em 4em;
}
}
Another, and maybe better solution to your problem would be to use a sidenav with hamburger icon. This may however be a bit complex for beginners.
What if you remove this line white-space: nowrap; from nav {}
Before
nav {
background-color: blue;
border-bottom: solid #09316b;
white-space: nowrap;
}
After:
nav {
background-color: blue;
border-bottom: solid #09316b; }
It starts to resize now. If you want more info about white space -> Click here -<

Flexbox header that when on mobile becomes a dropdown menu

I'm trying to create a website using flexbox for the header. However, it breaks on mobile devices so I wanted to know if there was a way to make the 3 links on the right (look at the code to understand) collapse into a burger-menu style dropdown if the width of the browser means it wouldn't all fit on one row.
Code
Codepen Link
HTML
<header>
<!--Random placeholder logo-->
<img id="logo" src="https://www.goomlandscapes.co.nz/wp-content/uploads/2018/08/logo-placeholder.png" alt="Logo" />
<nav class="nav_links">
<li>About Me</li>
<li>Projects</li>
<li>Contact</li>
</nav>
</header>
CSS
#import url("https://fonts.googleapis.com/css2?family=Montserrat:wght#500&display=swap");
* {
font-family: "Montserrat", sans-serif;
box-sizing: border-box;
margin: 0;
padding: 0;
background-color: #24252a;
color: #edf0f1;
}
li, a, button {
font-weight: 500;
font-size: 16px;
text-decoration: none;
}
header {
display: flex;
justify-content: flex-end;
align-items: center;
padding: 25px 7%;
padding-bottom: 27px;
}
#logo {
height: 36px;
width: auto;
cursor: pointer;
margin-right: auto;
}
.nav_links {
list-style: none;
}
.nav_links li {
display: inline-block;
padding: 0 20px;
}
You can use a media query to specify at what browser width you want your menu to turn into hamburger style. Proper syntax looks like this:
#media screen and (max-width: 768px) {
nav {
some-property: value;
}
}
This will alter the way your nav element is styled whenever the browser width becomes smaller than 768px.

Need a fixed navbar and landing page VH that incorporates navbar height

I am working on my first portfolio and running into some trouble doing two things.
Creating a fixed navbar. When I use position: fixed; it clears my float on the right "Contact Me", and everything collapses. I need this to stay spaced how it is in my example. Searched for quite some hours and I cannot find a fix as of yet, although I am a novice so I am sure that plays into this some as well.
For my landing page photo, I am trying to make a responsive design that allows it to resize to 100% of the available page size. I had implemented this with height: 100vh; however quickly noticed that it is taking the 100vh, and implementing this after my navbar, which leaves excess below. I tried to compensate by reducing the vh to account for the navbar, but of course I realized that this would not be a good fixed as it would only work for that viewport height, and not scale accordingly.
This leaves me either needing a fix to scale the content appropriately, or allow the photo to slide under the navbar, and occupy that space as well so that it is touching the top of the page.
Relevant HTML:
<header>
<div class="navbar">
<ul>
<li>Home</li>
<li>About Me</li>
<li>My Work</li>
<li style="float:right">Contact Me</li>
</ul>
</div>
</header>
<main>
<section class="homeLanding">
<h1>Hi, I'm Michael.</h1>
<p>A Front-End Web Dev</p>
<a href="#aboutMe" class="myBtn">Start here to learn more about me,
<br>and how I can help you</a>
</section>
Relevant CSS:
body {
margin: 0;
}
/** style navbar **/
.navbar ul {
background-color: #333;
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden
}
.navbar li {
float: left;
}
.navbar li a {
display: block;
text-align: center;
text-decoration: none;
color: white;
padding: 14px 16px;
}
.navbar li a:hover:not(.active) {
background-color: #111;
}
.active {
background-color: #4CAF50;
}
/** style landing page **/
.homeLanding {
height: 100vh;
width: 100%;
margin: auto;
background: url(/**Insert Image**/);
display: flex;
background-size: cover;
background-position: center;
flex-direction: column;
justify-content: center;
align-items: center;
text-align: center;
top: 0;
}
.myBtn {
color: white;
text-decoration: none;
border: solid 3px white;
border-radius: 6px;
padding: 7px 7px 0px 7px;
}
p, h1 {
color: white;
}
Background image: http://res.cloudinary.com/dtgbwo6mf/image/upload/v1502053498/bg_b0vucn.jpg
Point 1
In order to have position: fixed on your navbar without losing its layout, all you need to do is make sure to apply width: 100% as well.
Point 2
What you're looking for is to make use of CSS's calculation-driven values.
This way, you can tell you body to occupy 100% of the vertical height minus the height of your navbar, with height: calc(100v - 46px).
Here's a complete sample:
body {
margin: 0;
}
/** style navbar **/
.navbar {
position: fixed;
width: 100%;
}
.navbar ul {
background-color: #333;
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden
}
.navbar li {
float: left;
}
.navbar li a {
display: block;
text-align: center;
text-decoration: none;
color: white;
padding: 14px 16px;
}
.navbar li a:hover:not(.active) {
background-color: #111;
}
.active {
background-color: #4CAF50;
}
/** style landing page **/
.homeLanding {
padding-top: 46px;
height: calc(100vh - 46px);
width: 100%;
margin: auto;
background: url('http://res.cloudinary.com/dtgbwo6mf/image/upload/v1502053498/bg_b0vucn.jpg');
display: flex;
background-size: cover;
background-position: center;
flex-direction: column;
justify-content: center;
align-items: center;
text-align: center;
top: 0;
}
.myBtn {
color: white;
text-decoration: none;
border: solid 3px white;
border-radius: 6px;
padding: 7px 7px 0px 7px;
}
p,
h1 {
color: white;
}
<header>
<div class="navbar">
<ul>
<li>Home</li>
<li>About Me</li>
<li>My Work</li>
<li style="float:right">Contact Me</li>
</ul>
</div>
</header>
<main>
<section class="homeLanding">
<h1>Hi, I'm Michael.</h1>
<p>A Front-End Web Dev</p>
<a href="#aboutMe" class="myBtn">Start here to learn more about me,
<br>and how I can help you</a>
</section>
<section class="homeLanding">
<h1>SAMPLE EXTRA PADDING</h1>
<p>SAMPLE EXTRA PADDING</p>
<a href="#aboutMe" class="myBtn">SAMPLE EXTRA PADDING
<br>SAMPLE EXTRA PADDING</a>
</section>
Note that I added a second <section> to the HTML to demonstrate the scrolling effect with the fixed navbar.
Hope this helps! :)

Order of Links reverses under CSS Media Query

I have a set of links for my website's navigation. When the window reaches certain widths, I have a few media queries that help display the navigation properly. Everything is working fine except for the fact that the links are reversed when the window resizes. Why is this happening?
JSFiddle: http://jsfiddle.net/snpx63mx/
Markup
<header>
<h1><strong>Henry</strong><span id="notbold">+Applications</span></h1>
<nav>
<ul>
<li id="contact"><div id="contactanimation">Contact</div></li>
<li id="project"><div id="projectanimation">Project</div></li>
<li id="me"><div id="meanimation">Me</div></li>
</ul>
</nav>
</header>
CSS
header h1
{
font-size: 40px;
float: left;
font-weight: 100;
}
header nav
{
float: right;
}
header nav ul
{
list-style-type: none;
margin: 0;
vertical-align: middle;
line-height: normal;
float: right;
z-index: 999;
position: relative; /* add this */
}
header nav ul li
{
line-height: 15px;
float: right;
padding: 45px;
font-size: 22px;
font-weight: 100;
text-align: center;
}
header nav ul li a
{
color: black;
text-decoration: none;
}
#media screen and (max-width: 1160px) {
header h1
{
float: none;
text-align: center;
font-size: 36px;
}
header nav
{
width: 100%;
margin-right: 20px;
}
header nav ul
{
float: none;
text-align: center;
}
header nav ul li
{
width: 100%;
box-sizing: border-box;
text-align: center;
padding: 25px;
}
}
JSFIDDLE: http://jsfiddle.net/snpx63mx/2/
You have a float right on your li tags. This means your bottom li is going to be on the left side when in a wider breakpoint. When it becomes a smaller width, the li stacks on top of each other and it is showing from top top bottom in the order that the lis are listed in html. If you ordered the list items like this :
<li id="me"><div id="meanimation">Me</div></li>
<li id="project"><div id="projectanimation">Project</div></li>
<li id="contact"><div id="contactanimation">Contact</div></li>
and then modified your css to float them left, you would have the same order in both sizes.
It's what I said in comment, change float: right to float: left:
header nav ul li
{
float: left;
}
FIDDLE: https://jsfiddle.net/lmgonzalves/snpx63mx/1/