I've been working on making a personal site with a navigation bar. I read w3schools' article and used the code there to make my nav. There are some problems with this, however:
The same code needs to be copied and pasted on each page.
If I decide to add a new page, I have to add the navigation bar to the new page and add the new page's link to the navigation bar on every page.
If I find an error in the nav code, I have to fix it on each individual page.
Here's the code:
html {
color: blue;
font-family: sans-serif;
}
.resource-dropdown {
position: sticky;
display: inline-block;
}
.resource-dropdown-content {
display: none;
position: absolute;
background-color: #b51d1d;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
padding: 12px 16px;
z-index: 1;
}
.resource-dropdown:hover .resource-dropdown-content {
display: block;
}
.resource-dropdown-content:hover {
color: greenyellow;
}
.topnav {
background-color: black;
}
.topnav a {
float: left;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}
.topnav a:hover {
background-color: white;
color: black;
}
<div class="topnav">
Home
<div class="resource-dropdown">
<span><a>Resources</a></span>
<div class="resource-dropdown-content">
<p>Sites</p>
<p>Books</p>
<p>Videos</p>
<p>Other</p>
</div>
</div>
About
</div>
Is there a way to make a shortcut? (Something like the alias command in the C languages)
There is no shortcut in HTML only. If you avec a local server such as MAMP / XAMP for exemple, and that you're ready to make a bit of PHP, you'll be able to create one file for the menu, and include it in all other files. This way, each time you change the menu in the menu file, it'll change on every pages.
here is the official documentation on php include function : http://php.net/manual/en/function.include.php
here is the documentation of MAMP : https://www.mamp.info/en/#controlcenter
Related
this is the first ever website I am building from scratch and I am definitely jumping right in head first. I managed to get my index page complete and really like the buttons that I have for the navigation. The problem I am running into is the sizing. Everything on the index page is exactly how I want it, but when going to any other page the header becomes larger than what it is showing on the index and larger than what I want. I am new to scripting and still learning. Any help is appreciated!
I have tried messing with the sizes, margins, and padding of nav in .css but once things start going well on the pages I am trying to fix, it is affecting the index. I also tried messing with the formatting of the photo on the index page, but nothing I am doing seems to be doing the trick and searching for help is not getting me anywhere as I am not using query or react, etc.
I have thought about creating a separate div tag for these pages but that seems inefficient and uncommon in navigation tags!
Files > https://github.com/sumbernotas/Portfolio
<header>
<h1 class="logo">SB</h1>
<nav>
ABOUT
PROJECTS
CONTACT
</nav>
</header>
nav {
text-align: right;
width: 99%;
height: 90px;
margin: 20px;
padding-right: 15%;
position: absolute;
top: 20px;
}
nav a {
display: inline-block;
padding: 0.5em 1.7em;
margin: 0 4.2em 0.1em 0;
border: 0.16em solid rgb(46, 196, 182);
border-radius: 2em;
box-sizing: border-box;
text-decoration: none;
text-align: right;
font-family: "Futara";
font-weight: 300;
font-size: 30px;
color: #7B7B7B;
text-shadow: 0 0.04em 0.04em rgba(123, 123, 123);
transition: all 0.2s;
}
nav a:hover{
color: #FDFFFC;
background-color: #2EC4B6;
}
I have a problem. I suspect that the problem is a browser-side rendering problem. Maybe even an expectable behaviour, but I have no idea, and that is why I am going to ask you:
I have an <a>-element and I place two other elements (a <span> and a <div>, the <div> has even more children) inside that element.
I upload my HTML-file to my server and can access and download it (e.g. via curl or wget). There is no problem and the file is exactly the same. When I open it in web browsers (I tested Firefox and Chrome) it is still the same, but only when I open it using the "debugging" tab where I can see the original files. The displayed HTML-file (which I can access using the "inspection" tab) is different. The <div>-element got moved out of the <a>-element. Here is the code-snippet:
<div class="navbar">
A link
<a class="dropdown">
<span>A dropdown</span>
<div class="dropdown-content">
Another link
And a third link
</div>
</a>
</div>
As you can guess, it is a snipped from a navbar ;) Maybe you need the CSS (I use SCSS-files) too:
.navbar {
background-color: $navbar-color;
overflow: hidden;
padding-left: 10vw;
padding-right: 10vw;
a {
position: relative;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
color: $navbar-text-color;
}
a.dropdown {
position: static;
display: inline-block;
span::after {
content: '\f0d7';
font-family: FontAwesome;
padding-left: 6px;
}
.dropdown-content {
display: block;
position: absolute;
background-color: $navbar-color;
min-width: 160px;
box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2);
a {
float: none;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
color: $navbar-text-color;
}
}
}
}
I know, the design is not perfect and not finished, but I expect I am facing an HTML problem and so I wanted to ask you first.
Do you have any hints, ideas, references, explanations or corrections for me? I would really appreciate it.
When I tried to add a dropdown menu to my navigation bar it sent that child to the right of the navigation bar. I want it to be the 3rd child. How can I fix that? I tried to make it an absolute to keep its place however, it will then place itself over another child. I do not want that.
rightNav {
float: left;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
background: white;
}
.rightNav:hover{
color: #0067ff;
transition-duration: .4s;
}
.bar {
background-color: white;
}
.dropdown {
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
}
.dropdown-content a {
color: black;
padding: 15px;
text-decoration: none;
display: block;
font-size: 17px;
}
.dropdown-content a:hover {
background-color: #ebebeb;
transition: .1s;
}
.dropdown:hover .dropdown-content {
display: block;
}
<div class="navbar">
<div>
LOGO
<div class="w3-right smallScreen">
HOME
DIRECTOR OF BANDS
<div class="dropdown">
MARCHING BAND
<div class="dropdown-content">
MARCHING BAND
STAFF
MUSIC
</div>
</div>
CONCERT BAND
JAZZ BAND
CLASSES
MEDIA
CONTACT US
</div>
Antonio.
I tried replicating your code to troubleshoot it, but the CSS is poorly pasted, so I won't be able to give you a full picture on it right now.
If I understand correctly, the issue you're facing is that the drop-down content isn't behaving as such, instead just showing up as links in the nav-bar. Correct?
If that is the case, I would refer you to https://www.w3schools.com/howto/howto_js_dropdown.asp as you'd need some JavaScript to make it work. There is some neat code there ready for the use. Also, I would strongly recommend that you use no spaces in any of the class names in your HTML, as it becomes quite impossible to reference them later in your CSS code.
So I'm using Foundation 6 to prototype a project and I'm noticing that top-bar, top-bar-left, and top-bar-right work just as shown on the docs page except when I want to wrap the left and right bars so that they don't touch the sides.
Both top-left-bar and top-right-bar take up the whole width of the top-bar area each and then end up stacking on top of each other. I want them to look like they do in the code pen link below:
(its linked with foundation 6.0.5, and I'm using 6.4.1 - couldn't find a link for that version)
https://codepen.io/mgrosen/pen/RgEVvY
relevant code from app.css
.wrap {
width: 90%;
max-width: 1100px;
margin: 0 auto;
}
.nav-desktop {
background-color: #222;
height: 80px;
padding: 0;
}
.site-logo {
color: white;
line-height: 80px;
}
.nav-desktop .menu-desktop {
line-height: 80px;
background-color: transparent;
}
.nav-desktop a {
display: inline-block;
}
.menu-desktop > li > a {
display: inline-block;
line-height: 80px;
padding-top: 0;
padding-bottom: 0;
color: white;
}
.menu-desktop > li > a:hover {
background-color: rgba(255,255,255, 0.1);
}
relevant index.html code
<nav class="top-bar nav-desktop" id="responsive-menu">
<div class="wrap">
<div class="top-bar-left">
<h3 class="site-logo">Site Logo</h3>
</div>
<div class="top-bar-right">
<ul class="menu menu-desktop">
<li>Home</li>
<li>About</li>
<li>Foundation Examples</li>
</ul>
</div>
</div>
</nav>
That's the actual code I'm using, but when open index.html to look at it (or run my flask application and view it on local host) this is what i see when I'm scrolled all the way to the top of the screen.
Anybody know why this is happening or how I might debug it with dev tools?
Thanks!
alright, first time asker, i have an issue when using an external style sheet with the chrome browser, which doesn't occur when using Edge and Firefox. it also works correctly in Jsfiddle.
the issue is that it doesn't display background or text colour in my body, but for the header, it works perfectly.
this is my first time using an external style sheet, but i assume since its working in other browsers, this is an issue with compatibility with chrome.
i link the CSS file like so:
<link rel="stylesheet" type="text/css" href="styles.css" />
here is my CSS code itself:
body {
background-color: Black;
color: Green;
font-family: verdana;
}
h1 {
text-align: center;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: Green;
}
li {
float: left;
border-right:1px solid #bbb;
}
li:last-child {
border-right: none;
}
li a {
display: block;
color: Black;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
li a:hover:not(.active) {
background-color: #111;
}
.active {
background-color: green;
}
thanks in advance for any help you can offer, its for a school esque project with strict criteria, which is why it needs to be external and in chrome.
goto settings
search for cache
clear browsing data
check cached images and files (the past hour / day)
clear browsing data
and goto your webpage and press "Ctrl + r"
Hope this helps !