- Joined
- Sep 20, 2018
- Messages
- 3,958
I've created both a horizontal menu and a vertical menu for my student final project (we can create anything we want. so long as we meet a minimal list of requirements so this isn't a "cheating" question). The HTML & CSS are very close for both.
I know conditional logic is very limited, and I don't want to use JavaScript because I want the website to work without needing it. I also don't want to use an "empty" conditional hack because it goes against the core purpose of "empty" to identify unfilled fields, so would be confusing to whoever has to read it (such as a tired and grouchy instructor at the end of the semester at 11 PM who has run out of coffee). What's the best way to merge the CSS so it can be used for both?
Here's what I have for the original toolbar:
For the vertical navigation, I've copied the css, changing ul.nav to ul.nav.v, and changed:
and I've added a width to the ul.nav-v selector. I suspect I should use attribute selectors but my brain is kinda fogged right now, and this is only a "nice to have" for the project. Also, ignore that I'm using pixel measurements, I'll properly change them to percents once I start working on the responsive requirement.
Thanks!
I know conditional logic is very limited, and I don't want to use JavaScript because I want the website to work without needing it. I also don't want to use an "empty" conditional hack because it goes against the core purpose of "empty" to identify unfilled fields, so would be confusing to whoever has to read it (such as a tired and grouchy instructor at the end of the semester at 11 PM who has run out of coffee). What's the best way to merge the CSS so it can be used for both?
Here's what I have for the original toolbar:
Code:
html
<nav>
<h2>Navigation Menu</h2>
<ul class="nav">
<li><a href="final.html">Home</a></li>
<li><a class="selected" href="boilerplate.html">Boilerplate</a></li>
<li><a href="#contact">Contact</a></li>
<li><a href="#about">About</a></li>
</ul>
</nav>
css
:root {
--body-bg-color: beige;
--nav-fg-color: #ffffff;
--nav-bg-color: #3333ff;
--nav-bg-selected-color: #000088;
--nav-bg-hover-color: #8888ff;
ul.nav {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: var(--nav-bg-color);
}
ul.nav li {
float: left;
}
ul.nav li a {
display: block;
color: var(--nav-fg-color);
text-align: center;
padding: 16px;
text-decoration: none;
}
ul.nav li a.selected {
display: block;
background-color: var(--nav-bg-selected-color);
text-align: center;
padding: 16px;
text-decoration: none;
}
ul.nav li a:hover {
background-color: var(--nav-bg-hover-color);
}
Code:
ul.nav-v li {
width: 100px;
/* float: left;*/
}
Thanks!





