List-item starting in the middle of the box - html

I want to have a margin on the right and left side of the list-items hence why I created the "wrapper", can someone figure out why it starts somewhat on the center and not from left to right?
Here's a jsfiddle for it: http://jsfiddle.net/vd8rb51s/
.add-remove-skills {
position: relative;
float: right;
display: block;
border: 2px solid #d1d9de;
border-radius: 4px;
width: 287px;
height: 394px
}
ul.edit-skills {
}
ul.edit-skills li {
display: block;
margin: 0;
padding: 10px;
text-align: left;
background: #000;
margin-bottom: 15px
}
.skills-wrapper {
width: 267px;
margin: 0 auto
}
h3.manage-skills {
font-weight: 700;
font-size: 16px;
width: 100%;
padding: 15px;
margin-top: 0;
border-bottom: 2px solid #d1d9de
}
input.add-skill {
position: absolute;
font-size: 16px;
bottom: 0;
width: 100%;
height: 40px;
text-indent: 10px;
font-weight: 700;
border: none;
border-top: 2px solid #d1d9de
}
input.add-skill::-webkit-input-placeholder {
/* WebKit browsers */
color: #939fa7;
font-weight: 500
}
input.add-skill:-moz-placeholder {
/* Mozilla Firefox 4 to 18 */
color: #939fa7;
font-weight: 500;
opacity: 1
}
input.add-skill::-moz-placeholder {
/* Mozilla Firefox 19+ */
color: #939fa7;
font-weight: 500;
opacity: 1
}
input.add-skill:-ms-input-placeholder {
/* Internet Explorer 10+ */
color: #939fa7;
font-weight: 500
}
<div class="add-remove-skills">
<h3 class="manage-skills">Manage skills</h3>
<div class="skills-wrapper">
<ul class="edit-skills">
<li>Skill number one</li>
<li>Skill number two</li>
<li>Skill number three</li>
</ul>
</div>
<input class="add-skill" placeholder="Add new skill here" type="text">
</div>

Most browsers add some padding-left to ul elements by default. Just remove it:
.edit-skills {
padding-left: 0;
}
.add-remove-skills {
position: relative;
float: right;
display: block;
border: 2px solid #d1d9de;
border-radius: 4px;
width: 287px;
height: 394px;
}
ul.edit-skills {
padding-left: 0;
}
ul.edit-skills li {
display: block;
margin: 0;
padding: 10px;
text-align: left;
background: #000;
margin-bottom: 15px;
}
.skills-wrapper {
width: 267px;
margin: 0 auto;
}
h3.manage-skills {
font-weight: 700;
font-size: 16px;
width: 100%;
padding: 15px;
margin-top: 0;
border-bottom: 2px solid #d1d9de;
}
input.add-skill {
position: absolute;
font-size: 16px;
bottom: 0;
width: 100%;
height: 40px;
text-indent: 10px;
font-weight: 700;
border: none;
border-top: 2px solid #d1d9de;
}
input.add-skill::-webkit-input-placeholder { /* WebKit browsers */
color: #939fa7;
font-weight: 500;
}
input.add-skill:-moz-placeholder { /* Mozilla Firefox 4 to 18 */
color: #939fa7;
font-weight: 500;
opacity: 1;
}
input.add-skill::-moz-placeholder { /* Mozilla Firefox 19+ */
color: #939fa7;
font-weight: 500;
opacity: 1;
}
input.add-skill:-ms-input-placeholder { /* Internet Explorer 10+ */
color: #939fa7;
font-weight: 500;
}
<div class="add-remove-skills">
<h3 class="manage-skills">Manage skills</h3>
<div class="skills-wrapper">
<ul class="edit-skills">
<li>Skill number one</li>
<li>Skill number two</li>
<li>Skill number three</li>
</ul>
</div>
<input type="text" class="add-skill" placeholder="Add new skill here">
</div>

unordered lists have a default indent/padding so that the bullets will not end up outside the list itself.
Ussually a CSS reset stylesheet would fix this kind of thing. It would contain something like this:
ul { margin: 0; padding: 0; }
or you can apply this in your case
ul.edit-skills { margin: 0; padding: 0; }

Related

Hover effects on Form Placeholder Text

I am trying to change the color of the placeholder text of a contact form when hovering over it. Is this possible using only html/CSS or is javascript necessary?
You will see in the code below that I have put each input field of the contact form within its own div in order structure it properly on the page, which results in some long and messy code. But otherwise it has worked well. I have the background of the input fields set to change when hovering.
What I don't understand is why using the hover selector on the form to make the text bold works on BOTH the placeholder text and the input text; however, changing the color on hover works ONLY on the input text and NOT to placeholder.
I tried nesting the ::placeholder selector (as well as its counterparts for various web browsers) inside the hover selector in the SCSS document to change the color when hovering but with no luck.
Does anyone have any advice for how to make this placeholder text color change when hovering?
I included some images of the site and my code below.
Thanks!
Contact form as is.
Contact form on hover; placeholder text color not changing.
HTML & CSS CODE
.contact-form {
text-align: center;
justify-content: center;
position: relative;
}
.name {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
width: 40vw;
padding: 0;
}
.first {
float:left;
width: 50%;
padding: 0.5em;
padding-left: 0;
margin: 0;
}
.form-control-first {
color: #878F93;
background-color: white;
border: none;
border-radius: 1em;
box-shadow: rgba(0, 0, 0, 0.1) 0em 0em 1em 0em;
padding: 1em;
font-family: Circe;
font-weight: 300;
font-size: 1em;
margin-top: 1em;
margin-bottom: 1em;
width: 100%;
}
.form-control-first:hover {
color: white;
font-weight: 600;
background-color: #AEBDB2;
cursor: pointer;
}
.form-control-first:focus {
outline: none;
pointer-events: none;
}
.last {
float:left;
width: 50%;
padding: 0.5em;
padding-right: 0;
margin: 0;
}
.form-control-last {
background-color: white;
color: #878F93;
border: none;
border-radius: 1em;
box-shadow: rgba(0, 0, 0, 0.1) 0em 0em 1em 0em;
padding: 1em;
font-family: Circe;
font-weight: 300;
font-size: 1em;
margin-top: 1em;
margin-bottom: 1em;
width: 100%;
}
.form-control-last:hover {
color: white;
font-weight: 600;
background-color: #AEBDB2;
cursor: pointer;
}
.form-control-last:focus {
outline: none;
pointer-events: none;
}
.email-message {
position: relative;
top: 5.5em;
bottom: 0;
left: 0;
right: 0;
padding-top: 0em;
margin: auto;
width: 40vw;
}
.form-control-email {
background-color: white;
color: #878F93;
border: none;
border-radius: 1em;
box-shadow: rgba(0, 0, 0, 0.1) 0em 0em 1em 0em;
padding: 1em;
font-family: Circe;
font-weight: 300;
font-size: 1em;
margin: 0;
margin-top: 0.5em;
margin-bottom: 0.5em;
width: 100%;
}
.form-control-email:hover {
color: white;
font-weight: 600;
background-color: #AEBDB2;
cursor: pointer;
}
.form-control-email:focus {
outline: none;
pointer-events: none;
}
.form-control-message {
background-color: white;
color: #878F93;
border: none;
border-radius: 1em;
box-shadow: rgba(0, 0, 0, 0.1) 0em 0em 1em 0em;
padding: 1em;
text-align: left;
font-family: Circe;
font-weight: 300;
font-size: 1em;
margin: 0;
margin-top: 0.5em;
margin-bottom: 0.5em;
width: 100%;
height: 30vh;
max-width: 100%;
max-height: 30vh;
}
.form-control-message:hover {
color: white;
font-weight: 600;
background-color: #AEBDB2;
cursor: pointer;
}
.form-control-message:focus {
outline: none;
pointer-events: none;
}
.form-control-submit {
justify-content: center;
align-items: center;
padding: 0.75em;
padding-left: 2em;
padding-right: 2em;
font-family: Circe;
font-weight: bold;
font-size: 0.75em;
text-transform: uppercase;
color:white;
border-radius: 2em;
background-color: #207CB4;
border: none;
display: inline-block;
margin: 0px, 2px;
text-decoration: none;
}
.form-control-submit:hover {
color: #174456;
background-color: #FFE98E;
cursor: pointer;
}
::-webkit-input-placeholder { /* WebKit, Blink, Edge */
color: #878F93;
}
:-moz-placeholder { /* Mozilla Firefox 4 to 18 */
color: #878F93;
opacity: 1;
}
::-moz-placeholder { /* Mozilla Firefox 19+ */
color: #878F93;
opacity: 1;
}
:-ms-input-placeholder { /* Internet Explorer 10-11 */
color: #878F93;
}
::-ms-input-placeholder { /* Microsoft Edge */
color: #878F93;
}
::placeholder { /* Most modern browsers support this now. */
color: #878F93;
}
<div class="contact-form">
<form id="contact-form" method="post">
<div class="name">
<div class="first">
<input name="first-name" type="text" class="form-control-first" placeholder="First Name" required>
</div>
<div class="last">
<input name="last-name" type="text" class="form-control-last" placeholder="Last Name" required>
</div>
<br>
</div>
<div class="email-message">
<input name="email" type="text" class="form-control-email" placeholder="Email" required>
<br>
<textarea name="message" class="form-control-message" placeholder="Type your message here." row="4" required></textarea>
<br>
<input type="submit" class="form-control-submit" value="Submit"></div>
</form>
</div>
This worked for me!
.input {
}
.input::placeholder {
color: red;
}
.input:hover::placeholder {
color: blue;
}

Setting text to stay above another element at all times

I have one regular box and I wish the text to float above it and resize the text's font size appropriately.
This is what I have done: https://jsfiddle.net/a87uo3t2/
#import url('https://fonts.googleapis.com/css?family=Share+Tech+Mono');
body {
margin: 0 auto;
overflow: hidden;
}
#content {
width: 100%;
height: 2527px;
background-image: url('../images/wallpaper.jpg');
}
#menu-container,
#button-container {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
width: 30%;
height: 40%;
border: 1px line #ccc;
background-color: #ffffff;
background-image: url('../images/brick-wall.png');
box-shadow: 0 0 3em #ccc;
}
#button-container {
border: none;
box-shadow: none;
}
.button-sub-container {
display: inline-flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
h1 {
position: relative;
bottom: 120px;
left: 6px;
text-align: center;
font-family: 'Share Tech Mono', monospace;
font-size: 5vw;
text-transform: uppercase;
text-decoration: none;
letter-spacing: 15px;
}
/*BUTTONS*/
.main-button {
text-decoration: none;
font-family: 'Share Tech Mono', monospace;
font-size: 35px;
margin: 15px;
color: #000;
letter-spacing: 5px;
text-transform: uppercase;
transition: letter-spacing 0.5s, color 0.8s;
}
.main-button:hover {
letter-spacing: 15px;
color: red;
}
.main-button:active {
letter-spacing: 2px;
color: blue;
}
<div id="content">
<div id="menu-container">
<h1>welcome</h1>
<div id="button-container" class="button-sub-container">
<a class="main-button" href="about.html">about</a>
<a class="main-button" href="projects.html">projects</a>
<a class="main-button" href="contact.html">contact</a>
</div>
</div>
As you can see I have tried setting it on top by positioning it relatively yet this means upon resizing it shifts, I can fix this by using vw as font size to a point, since if one would have a very wide monitor, it would go over my small menu-container.
Side-Note: don't bring attention to the buttons-text breaking out of the box, I have a a media-key to fix that
A solution with flexbox
and changing only the font-size of the box
#import url('https://fonts.googleapis.com/css?family=Share+Tech+Mono');
html,
body {
height: 100%;
}
body {
margin: 0;
display: flex;
justify-content: center;
align-items: center;
}
.box {
font-family: 'Share Tech Mono', monospace;
max-width: 50%;
text-align: center;
/* Change to your needs */
font-size: 20px;
}
.box h1 {
text-transform: uppercase;
margin-top: 0;
}
.box ul {
list-style: none;
margin: 0;
padding: 15px;
border: 1px line #ccc;
background-color: #ffffff;
background-image: url('../images/brick-wall.png');
box-shadow: 0 0 3em #ccc;
}
.box a {
text-decoration: none;
color: #000;
text-transform: uppercase;
white-space: nowrap;
transition: letter-spacing 0.5s, color 0.8s;
}
.box a:hover {
letter-spacing: 3px;
color: red;
}
/* Change to your needs */
#media screen and (min-width: 600px) {
.box {
font-size: 20px;
}
}
/* Change to your needs */
#media screen and (min-width: 1200px) {
.box {
font-size: 30px;
}
}
<div class="box">
<h1>Heading</h1>
<!-- It's a list -->
<ul>
<li>Site 1</li>
<li>Site 2</li>
<li>Site 3</li>
</ul>
</div>

How do I get my menu blocks to appear over banner again?

So initially the top half of my black menu blocks appeared over the top of the banner, but now the top half of them are cut off underneath of the banner like this:
Here is my styles.css file:
/* Base */
* {
margin: 0;
padding: 0;
}
body {
/*background-color: #F5F4F1;*/
background-image: url('./img/bg.jpg');
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 15px;
line-height: 20px;
color: #353535;
-webkit-font-smoothing: antialiased;
text-rendering: optimizelegibility;
}
#banner {
position: relative;
}
#banner__text-content {
position: absolute;
top: 50%;
transform: translateY(-50%);
left: 0;
width: 100%;
text-align: center;
}
#banner__title {
font-size: 5.8rem;
text-shadow: -1px 0 white, 0 1px white, 1px 0 white, 0 -1px white;
}
h1,h2,h3,h4,h5,h6 {
margin: 30px 0;
/*font-weight: 200;*/
color: #8ca757;
}
h1 {
font-size: 35px;
}
h1 small {
font-size: 25px;
color: #666;
}
h2 + p {
margin-top: -20px;
}
h3 + p {
margin-top: -20px;
}
h2,h3,h4 {
font-size: 30px;
}
h4.error {
color: #faa722;
}
h5,h6 {
font-size: 20px;
}
p {
margin: 0 0 20px;
}
a:link, a:visited {
color: #8ca757;
}
a:hover {
color: #7a9347;
}
ul, ol {
margin: 0 0 10px 18px;
}
ul li, ol li {
margin: 0 0 15px;
}
hr {
border: none;
height: 18px;
width: 114px;
background-image: url('./img/hr.png') center center no-repeat;
margin: 20px auto;
}
small {
font-size: 12px;
}
blockquote {
background: white;
padding: 10px;
margin: 0 0 15px;
border-left: solid 4px #d1cbb8;
font-style: italic;
}
blockquote p {
margin: 5px 0 10px;
}
blockquote code {
font-style: normal;
}
code {
color: #006699;
font-weight: bold;
font-family: "Consolas", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace;
}
sup {
font-size: 0.6em;
}
/* Layout */
.wrapper {
position: relative;
width: 620px;
margin: 40px auto;
padding: 40px;
background: white;
text-align: center;
}
.wrapper:before, .wrapper:after {
content: "";
position: absolute;
top: 5px;
left: -5px;
width: 100%;
height: 100%;
background: #97917e;
z-index: -1;
}
.wrapper:before {
top: 10px;
left: -10px;
background: #514933;
}
#logo {
width: 240px;
margin: 0 auto;
display: block;
}
.sandbox {
padding: 20px;
background: #f8f5f1;
text-align: left;
}
aside {
background: white;
border: dashed 2px #97917e;
padding: 10px 20px;
margin: 40px;
}
aside h3 {
font-size: 24px;
margin-top: 10px;
}
aside h6 {
margin: 15px 0 5px;
}
table {
width: 100%;
font-size: 13px;
background: white;
margin: 0 0 20px;
}
table td {
border-bottom: solid 1px #d1cbb8;
padding: 4px;
}
table th {
background: #8ca757;
color: white;
padding: 4px;
font-weight: normal;
font-size: 15px;
}
/* Global */
input {
-webkit-font-smoothing: antialiased;
text-rendering: optimizelegibility;
}
autton, input.button {
display: inline-block;
background: #ccc;
outline: solid 2px #ccc;
border: solid 2px white;
color: white;
padding: 10px 15px;
margin: 20px 0;
text-decoration: none;
font-family: inherit;
font-size: inherit;
font-weight: bold;
cursor: pointer;
}
.button:hover, input.button:hover {
background: #bbb;
outline-color: #bbb;
}
.button.prev {
float: left;
background: #514933;
outline-color: #514933;
}
.button.prev:hover {
background: #494331;
outline-color: #494331;
}
.button.next, input.button.next {
background: #8ca757;
outline: solid 2px #8ca757;
float: right;
}
.button.next:hover, input.button.next:hover {
background: #7c9745;
}
input.button.next {
display: block;
float: none;
width: 100%;
}
.block {
display: block;
}
.cf:before,
.cf:after {
content: " "; /* 1 */
display: table; /* 2 */
}
.cf:after {
clear: both;
}
/**
* For IE 6/7 only
* Include this rule to trigger hasLayout and contain floats.
*/
.cf {
*zoom: 1;
}
.copyright-info h4, .copyright-info h5 {
margin: 0;
line-height: 18px;
font-size: 14px;
text-align: center;
}
.copyright-info h4 {
font-weight: bold;
}
.copyright-info {
margin: 20px 0 40px;
}
/* Final example website */
#final-example .wrapper {
width: 800px;
padding: 0;
}
#final-example .content {
padding: 20px 50px 50px;
text-align: left;
}
#final-example #nav {
margin: -27px 0 0;
}
#final-example #nav ul {
display: inline-block;
list-style: none;
text-align: left;
}
#final-example #nav ul li {
display: inline-block;
text-align: center;
margin: 0 10px;
}
#final-example #nav ul li a {
display: block;
background: #353535;
outline: solid 2px #353535;
border: solid 2px white;
color: white;
padding: 10px 15px;
text-decoration: none;
}
#final-example #nav ul li a:hover {
background: #8ca757;
outline: solid 2px #8ca757;
}
#final-example #philosophy {
text-align: center;
font-size: 18px;
line-height: 22px;
}
#final-example #footer {
font-size: 12px;
line-height: 15px;
margin: 60px 0 0 0;
}
#final-example #footer strong {
display: block;
margin: 0 0 20px;
}
#final-example .column {
display: block;
float: left;
}
#final-example .column.three {
width: 203px;
margin-right: 45px;
}
#final-example .column.last {
margin: 0;
}
#final-example small {
display: block;
text-align: center;
margin: 40px 0 0;
}
#final-example .member {
width: 203px;
float: left;
margin-right: 45px;
}
#final-example .member:last-child {
margin: 0;
}
#final-example .member img {
max-width: 100%;
}
#final-example .closed {
color: #d13916;
}
#final-example .open {
color: #67b512;
}
#menu-items ul {
list-style: none;
margin: 0;
padding: 20px 0;
text-align: center;
font-size: 18px;
}
#menu-items ul li a {
text-decoration: none;
font-weight: bold;
}
.price {
float: right;
font-size: 18px;
font-weight: bold;
color: #353535;
}
#contact {
width: 320px;
margin: 0 auto;
}
#contact-form label {
display: block;
font-size: 11px;
font-weight: bold;
text-transform: uppercase;
}
#contact-form input[type="text"],
#contact-form input[type="email"],
#contact-form textarea {
border: solid 2px #353535;
outline: none;
font-size: 18px;
padding: 10px;
margin: 0 0 10px;
width: 300px;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
text-rendering: optimizelegibility;
}
#contact-form textarea {
resize: vertical;
height: 120px;
}
#contact-form input[type="checkbox"] + label {
display: inline;
cursor: pointer;
}
When I try to do this:
#final-example #nav {
margin: -27px 0 0;
position: absolute;
}
to this
#final-example #nav {
margin: -27px 0 0;
}
this happens:
and text-align:center; did not work. Any ideas?
Here is the index.php:
<!DOCTYPE html>
<html>
<head>
<title>MicroUrb</title>
<link rel="stylesheet" href="assets/styles.css">
</head>
<body id="final-example">
<div class="wrapper">
<div id="banner">
<a href="/" title="Return to Home">
<img src="assets/img/banner0.jpg" alt="MicroUrb">
<div id="banner__text-content">
<h1 id="banner__title">MicroUrb</h1>
</div>
</a>
</div><!-- banner -->
<div id="nav">
<ul>
<li>Home</li>
<li>Team</li>
<li>Products</li>
<li>Contact</li>
</ul>
</div><!-- nav -->
<div class="content">
<div id="footer" class="cf">
<div class="column three">
<strong>Phone</strong>
609.505.3395
</div><!-- column -->
<div class="column three">
<strong>Location</strong>
<!-- location to go here -->
</div><!-- column -->
<div class="column three last">
<strong>Hours</strong>
<em>Tuesday - Thursday</em><br>
1:00pm - 9:00pm<br><br>
<em>Friday and Saturday</em><br>
4:00pm - 11:00pm<br><br>
<em>Sunday - Monday</em>
Closed<br><br>
</div><!-- column -->
</div><!-- footer -->
<small>©2017 MicroUrb</small>
</div><!-- content -->
</div><!-- wrapper -->
<div class="copyright-info">
<?php includes('../assets/includes/copyright.php'); ?>
</div><!-- copyright-info -->
</body>
</html>
Put a z-index on the nav and set the position to relative
#final-example #nav {
margin: -27px 0 0;
z-index: 5;
position: relative;
}
I believe to get the navigation in front of the banner like you are trying to achieve you could utilise the z-index property.
Add a z-index of 1 to your #final-example #nav {} and a z-index of 0 to your #banner {} which will bring the navigation in front of the banner while keeping its absolute positioning in the centre.
The final outcome will be:
#final-example #nav {
margin: -27px 0 0;
position: absolute;
z-index: 1;
}
#banner {
position: relative;
z-index: 0;
}
Let me know if you need any other help.
You can use z-index on the nav element to make it appear above the banner if you set the banner to a lower z-index compared to the nav element.
So for example:
#final-example #nav {
z-index:1;
position:relative;
margin:-27px auto 0;
}
That said, it would be useful if you would've posted your html part as well.
Edit:
Further investigation and with a temporary asset, the code seems to work fine with the code posted above as can be seen in this JSFiddle: https://jsfiddle.net/t2d70q3y/2/
Let me know if you require further assistance.

Is there an easier way, that would be understandable for beginners?

I found this menu that displays border at bottom, i would like to learn how to do it, but i don't understand how its done, is there an easier way that the same thing would be achieved?
Here is the URL: https://codepen.io/atomas/pen/zBoEZe?editors=1100
HTML:
<ul>
<li class="elm selected">Home</li>
<li class="elm">Services</li>
<li class="elm">About</li>
<li class="elm bar">Contact</li>
</ul>
CSS:
$elementsNumber: 4;
$width: 1/$elementsNumber;
* {
box-sizing: border-box;
}
ul {
position: relative;
margin: 50px auto;
width: 80%;
padding: 0;
list-style: none;
color: #000;
overflow: auto;
overflow: hidden;
li {
float: left;
padding: 15px;
font-size: 18px;
font-family: Roboto;
font-weight: 700;
width: percentage($width);
text-align: center;
cursor: pointer;
border-bottom: 4px solid #555;
}
.bar:before {
overflow: hidden;
content: "";
position: absolute;
top: 54px;
bottom: 0;
transition: all 0.25s;
left: 0;
width: percentage($width);
height: 4px;
background: red;
}
}
#for $i from 1 through $elementsNumber {
li:nth-child( #{$i} ) {
&.selected~.bar:before,
&.elm:hover~.bar:before,
&.selected.bar:before,
&.elm.bar:hover:before
{
left: percentage( ( $i - 1 ) * $width );
}
}
}
* { box-sizing: border-box;}
ul {
padding: 0;
list-style: none;
color: #000;
}
li {
float: left;
padding: 15px;
font-size: 18px;
font-family: Roboto;
font-weight: 700;
text-align: center;
border-bottom: 4px solid #555;
transition: all 0.3s;
}
li:hover {
border-bottom: 4px solid red;
}
<ul>
<li class="elm selected">Home</li>
<li class="elm">Services</li>
<li class="elm">About</li>
<li class="elm bar">Contact</li>
</ul>
If you'd just want a border on the bottom of the menu you can just use border-bottom:
body, html {
margin: 0;
padding: 0;
}
header {
background-color: #eee;
}
ul {
list-style-type: none;
padding-left: 0;
margin: 0;
border-bottom: 5px solid #ccc;
}
ul>li {
display: inline-block;
padding: 0 15px 0 15px;
margin-left: -4px;
}
ul>li:first-child {
margin-left: 0;
}
ul>li>a {
display: block;
color: #333;
text-decoration: none;
padding: 5px 0 5px 0;
}
ul>li:hover {
border-bottom: 5px solid #555;
margin-bottom: -5px
}
<header>
<nav>
<ul>
<li class="active">Home
</li>
<li>About
</li>
<li>Contact
</li>
</ul>
</nav>
</header>
That css does a lot more than just adding a border at the bottom.
The grey border you see at the bottom is displayed through:
li {
float: left;
padding: 15px;
font-size: 18px;
font-family: Roboto;
font-weight: 700;
width: percentage($width);
text-align: center;
cursor: pointer;
***border-bottom: 4px solid #555***;
}
However, the css also adds a component which highlights the specific li element which is being hovered over to make the border-bottom red.
The width property at the top just makes sure each li element gets equal space horizontally in the browser:
$elementsNumber: 4;
$width: 1/$elementsNumber;
In order to achieve the same red hover as your codepen illustrates, you will need to write some css such as li:hover etc. to mimic the same effect.
That css you have is definitely more complicated than it needs to be but works for the intended purpose. Taking a look at w3schools link here should help you understand the hover property and other useful properties in CSS.
Hope this helped!

CSS Drop-down Sub-menu Erroneously Modifying Parent Width

I have been fiddling with CSS-based drop-down navigation on my website and ran into some trouble with the sub-menus modifying the width of the parent menus. When a sub-drop-down is opened, the parent drop-down will enlarge to match the width. If sub-drop-down menus are smaller than the parent, they appear to be using the width of the parent menus for their horizontal offset instead of their own width, which creates a gap.
I have pulled together a live example here: http://jsfiddle.net/vwLf9f3w/2/
Sorry for the large quantity of CSS; I have pulled the relevant code to the top.
Here is the CSS just for my navigation:
/* ----------- Navigation ----------- */
div.nav
{
display: block;
position: absolute;
top: 83px;
left: 470px;
height: 47px;
width: 530px;
background-color: transparent;
z-index: 21;
padding: 0px;
margin: 0;
font-size: 16px;
}
/* ------ [ NAV LINKS ] ------- */
/* Primary header links */
div.nav > ul > li > a
{
display: block;
background-color: transparent;
text-align: center;
height: 24px;
width: 96px;
background-color: #a9a9a9;
border: 1px solid #666666;
border-radius: 3px;
margin-top: 6px;
margin-bottom: 6px;
margin-left: 6px;
padding: 6px 0px 0px 0px;
}
div.nav > ul > li:hover > a
{
background-color: #8bbbdd;
}
/* All header links */
div.nav a
{
color: #000000;
text-decoration: none;
}
/* Header Sub-links */
div.nav > ul > li li > a
{
display: block;
padding: 0px 0px;
padding-top: 6px;
padding-bottom: 6px;
padding-left: 20px;
padding-right: 20px;
margin-top: 0px;
margin-left: 0px;
background: #a9a9a9;
color: #000000;
}
div.nav > ul > li li > a:hover, div.nav > ul ul li:hover > a
{
background: #8bbbdd;
}
/* ------ [ NAV LISTS ] ------- */
/* Primary navigation items */
div.nav > ul > li
{
display: inline-block;
background-color: transparent;
vertical-align: top; /* here */
max-width: 104px;
overflow: show;
}
/* Primary navigation list */
div.nav > ul
{
display: inline-block;
width: 650px;
margin: 0px;
}
/* Secondary navigation lists */
div.nav > ul ul
{
z-index: 0;
white-space:nowrap;
border: 1px solid #666666;
border-radius: 3px;
padding: 0 0 0 0;
list-style: none;
position: relative;
display: none;
background-color: transparent;
background: URL(images/blank.gif);/*#000;transparent; IE FIX*/
padding: 0;
left: 6px;
top: -3px;
position: relative;
margin-bottom: 0px;
margin-left: 0px;
width: auto;
height: auto;
}
div.nav ul li:hover > ul
{
display: inline-block;
}
/* Secondary list items */
div.nav > ul > li li
{
max-height: 31px;
}
/* Tertiary menu list */
div.nav > ul ul ul
{
top: -36px;
left: -100%;
position: relative;
}
And here is the relevant HTML:
...
<div class="nav">
<ul>
<li>Home
</li><li>Tech
<ul>
<li>Subject 1</li>
<li>Subject 2
<ul>
<li>An Item</li>
<li>Some Other Item</li>
<li>And Yet Another!</li>
<li>I Am Running Out of Ideas
<ul>
<li>Even More To Show Expansion</li>
<li>And More</li>
<li>And More!</li>
</ul>
</li>
<li>One Last Item</li>
</ul>
</li>
<li>Subject 3</li>
<li>Subject 4</li>
</ul>
</li><li>Personal
<ul>
<li>Subject 1
<ul>
<li>1111</li>
<li>2222</li>
<li>3333</li>
<li>4444
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
</li>
<li>5555</li>
</ul>
</li>
<li>Subject 2</li>
<li>Subject 3</li>
</ul>
</li><li>Software
<ul>
<li>Subject 1</li>
<li>Subject 2</li>
<li>Subject 3</li>
</ul>
</li><li>Contact
<ul>
<li>Subject 1</li>
<li>Subject 2</li>
<li>Subject 3</li>
</ul>
</li>
</ul>
</div>
...
To summarize: How can I get each navigation sub-menu to have its own size that will not modify the size of other menus? And, how can I get the sub-menus to reference their own width rather than their parents' to prevent gaps?
All suggestions are welcome; my apologies for the unpolished code.
Parent element expansion:
The reason that your parent elements are expanding is because you are are not using absolute positioning on your child menus and the parent width is adjusting accordingly to the wider child elements. You will need to add position:relative; to div.nav > ul > li li and position: absolute; to div.nav > ul ul ul to remove your child menus from the flow so they don't widen your parent elements.
Sub Menu Alignment and Gap Elimination:
Sub Menus on right side of dropdown:
div.nav > ul ul ul {
left: 100%; /* All the way to the right of parent */
position: absolute;
}
Sub menus on left side of dropdown:
div.nav > ul ul ul {
left: auto; /* reset */
position: absolute;
right: 100%; /* All the way to the leftt of parent */
}
Sub Menu Vertical Alignment:
I also changed the top position on your sub menus to adjust the alignments for the 1px border and the 4px top margin on your ULs.
div.nav > ul ul {
top: -5px; / * corrects sub menu top alignment */
}
Take a look at the snippet below. It is set up with menus on the right side of the dropdown.
/* ===============----------- Navigation -----------=============== */
div.nav
{
display: block;
position: absolute;
top: 83px;
left: 470px;
height: 47px;
width: 530px;
background-color: transparent;
z-index: 21;
padding: 0px;
margin: 0;
font-size: 16px;
}
/* ------ [ NAV LINKS ] ------- */
/* Primary header links */
div.nav > ul > li > a {
display: block;
background-color: transparent;
text-align: center;
height: 24px;
width: 96px;
background-color: #a9a9a9;
border: 1px solid #666666;
border-radius: 3px;
margin-top: 6px;
margin-bottom: 6px;
margin-left: 6px;
padding: 6px 0px 0px 0px;
}
div.nav > ul > li:hover > a {
background-color: #8bbbdd;
}
/* All header links */
div.nav a {
color: #000000;
text-decoration: none;
}
/* Header Sub-links */
div.nav > ul > li li > a {
display: block;
padding: 0px 0px;
padding-top: 6px;
padding-bottom: 6px;
padding-left: 20px;
padding-right: 20px;
margin-top: 0px;
margin-left: 0px;
background: #a9a9a9;
color: #000000;
}
div.nav > ul > li li > a:hover, div.nav > ul ul li:hover > a {
background: #8bbbdd;
}
/* ------ [ NAV LISTS ] ------- */
/* Primary navigation items */
div.nav > ul > li {
display: inline-block;
background-color: transparent;
vertical-align: top; /* here */
max-width: 104px;
overflow: show;
}
/* Primary navigation list */
div.nav > ul {
display: inline-block;
width: 650px;
margin: 0px;
}
/* Secondary navigation lists */
div.nav > ul ul {
z-index: 0;
white-space:nowrap;
border: 1px solid #666666;
border-radius: 3px;
padding: 0 0 0 0;
list-style: none;
position: relative;
display: none;
background-color: transparent;
background: URL(images/blank.gif);/*#000;transparent; IE FIX*/
padding: 0;
left: 6px;
top: -5px; /* corrects sub menu top alignment */
position: relative;
margin-bottom: 0px;
margin-left: 0px;
width: auto;
height: auto;
}
div.nav ul li:hover > ul {
display: inline-block;
}
/* Secondary list items */
div.nav > ul > li li {
max-height: 31px;
position: relative; /* required for child menu absolute positioning */
}
/* Tertiary menu list */
div.nav > ul ul ul {
position: absolute; /* removes child sub menu from flow and stops the expandsion of parent element */
left: 100%; /* positions sub menu to right side of parent */
}
/* =======-------- Shouldn't Be Relevant Beyond Here --------======= */
/* Page Setup */
#font-face
{
font-family: 'DejaVu Sans';
src: local(default_font), url('fonts/DejaVuSans.ttf') format('truetype');
font-weight: normal;
font-style: normal;
font-variant: normal;
}
#font-face
{
font-family: 'DejaVu Sans';
font-weight: bold;
font-style: normal;
font-variant: normal;
src: local('DejaVu Sans'), url('fonts/DejaVuSans.ttf') format('truetype');
}
#font-face
{
font-family: 'DejaVu Sans';
font-weight: normal;
font-style: italic;
font-variant: normal;
src: local('DejaVu Sans'), url('fonts/DejaVuSans.ttf') format('truetype');
}
*
{
padding: 0;
margin: 0;
border: 0;
/*font-family: "Arial", Gadget, sans-serif;*/
font-family: "DejaVu Sans", "Arial", "Gadget", "sans-serif";
color: #000;
}
.clearfix:after
{
content: ".";
display: block;
height: 0;
clear: both;
visibility: hidden;
font-size: 0;
}
* html .clearfix
{
height: 1%;
}
.clearfix
{
display: block;
}
html, body
{
min-height: 100%;
}
body
{
background: url(images/background.png) repeat; /*no-repeat*/
/*background-attachment: fixed;
background-size: cover;*/
font-family: Geneva, Arial, Helvetica, san-serif;
height: 100%;
min-height: 100%;
}
/* Main body components */
.header
{
height: 128px;
text-indent: -9999px;
margin: -1px 0px 0px 0px;
border-bottom: 0px solid #000;
padding: 0px;
}
#container
{
display: block;
position: relative;
width: 1000px; /* 750px */
height: 100%;
margin: 0 auto;
padding: 0px;
background-color: #fff;
box-shadow: 0px 0px 5px #888888;
border-bottom: 4px #000 solid;
margin-bottom: 32px;
z-index: 1;
}
.slideshow
{
display: block;
text-align: center;
margin-left: 0px;
margin-bottom: 24px;
}
#hide
{
display: none;
}
.announcement
{
/*color: #B0B0B0;*/
position: absolute;
top: 140px; left: 425px;
height: 47px; width:575px;
z-index: 20;
}
.selectable
{
}
.selectable:hover
{
cursor: pointer;
background-color: #F3F3FF;
}
#pagecategory
{
font-family: "League Gothic", "Arial", "sans-serif" !important;
letter-spacing: .02em;
position: absolute;
top: 128px;
left: 0px;
width: 400px;
height: 35px;
text-align: center;
padding-right: 32px;
background-color: transparent;
padding-top: .25em;
font-size: 24px;
/*text-shadow: 0 0 3px #777777;*/
}
/* Simple elements */
a
{
color: #FF6600 ;/*#151B8D; HYPERLINK 0066CC*/
font-style: bold;
/*text-shadow: 0.1em 0.1em 0.1em black;*/
text-decoration: none;
}
a:hover
{
text-decoration: underline;
}
a.a_subtle
{
color: #888;
font-style: italic;
text-decoration: none;
}
a.a_subtle:hover
{
color: #0000ff;
font-style: regular;
text-decoration: underline;
}
a.a_download
{
display: block;
color: #444444;
font-size: 20px;
text-decoration: none;
text-decoration: underline;
clear: left;
}
a.a_download:hover
{
color: #0000ff;
}
glowred
{
color: rgb(255, 102, 0);
/*text-shadow: 0.1em 0.1em 0.1em black;*/
}
.buildsbox
{
text-align: left;
display: inline-block;
border: 1px solid #bbbbbb;
border-radius: 3px;
padding: 12px;
overflow: scroll;
max-height: 512px;
width: 700px;
}
input
{
margin-bottom: 8px;
}
input[type="text"], textarea
{
border: 1px solid;
font-size: 16px;
padding: 3px;
}
input[type="submit"]
{
border: 1px solid;
font-size: 16px;
padding: 3px;
}
input[type="submit"]:hover
{
background-color: #CCCCFF;
cursor: pointer;
}
label
{
font-size: 15px;
}
.errorbox
{
display: block;
margin-top: 5px;
margin-bottom: 5px;
border: 1px dashed #903333;
border-radius: 2px;
padding: 5px;
background-color: #FFBBBB;
}
.successbox
{
display: block;
margin-top: 5px;
margin-bottom: 5px;
border: 1px dashed #339033;
border-radius: 2px;
padding: 5px;
background-color: #BBFFBB;
}
/* Posts/text */
h1
{
font-family: "League Gothic", arial, sans-serif !important;
text-align: left;
font-size: 30px;
font-weight: normal;
margin-bottom: 16px;
display: block;
}
h2
{
font-family: "League Gothic", arial, sans-serif !important;
margin-bottom: 8px;
margin-top: 16px;
display: block;
font-size: 16px;
letter-spacing: .02em;
font-weight: 700 !important;
}
em, i
{
font-style: italic !important;
font-family: inherit;
font-weight: inherit;
}
/*subtitle_in
{
margin-left: -4px;
margin-bottom: 8px;
margin-top: 16px;
text-shadow: 0 0 1px #111111;
display: inline-block;
font-weight: bold;
}*/
code
{
background: #EEEEEE;
display: inline-block;
padding: 1px;
font-family: "courier new", monospace !important;
}
ul
{
margin-left: 32px;
margin-top: 4px;
margin-bottom: 4px;
}
/*h1
{
height: 1px;
background: transparent;
font-size:0px;
font-weight:normal;
padding:0px;
color: transparent;
}
h1 em
{
font-style:normal;
}*/
#content
{
/*width: 916px; /* 1111 */
float: left;
margin: 0px;
margin-left: 12px;
margin-right: 12px;
width: 976px;
}
h3
{
font-size: 24px;
border-bottom: 2px solid #666666;
}
.category
{
font-size: 18px;
margin: 15px 0 0 20px;
}
ph
{
padding: 0px;
margin-left: -1px;
margin-top: 0px;
}
h5
{
font-size: 12px;
margin: 10px 10px 25px 50px;
line-height: 20px;
border-left: 3px solid #ffffff;
padding-left: 13px;
}
.post
{
display: inline-block;
font-size: 16px;
line-height: 25px !important;
margin-top: 5px;
margin-bottom: 10px;
margin-left: 16px;
margin-right: 16px;
line-height: 20px;
font-weight: 1;
background-color: transparent;
background-image: URL(images/PostBKG.png);
background-repeat: repeat;
padding: 15px;
width: 914px;
text-align: justify;
}
.pagesplit
{
height: 20px;
width: 904px;
background: transparent URL(images/postbreak.png);
margin-top: 16px;
margin-bottom: 10px;
margin-left: auto;
margin-right: auto;
}
.summaryblock
{
width: 440px;
display: inline-block;
vertical-align: top;
margin-left: 8px;
margin-right: 8px;
height: 275px !important;
overflow-x: visible;
overflow-y: hidden;
}
.summaryblock:hover
{
cursor: pointer;
/*color: #000099;*/
}
.summaryblock a
{
text-decoration: none;
color: inherit;
}
.summaryblock a:hover
{
text-decoration: none;
}
.imgleft
{
border-radius: 5px;
box-shadow: 2px 2px 5px #888888;
float: left;
margin-right: 16px;
margin-top: 2px;
margin-bottom: 8px;
margin-left: 0px;
}
.imgleft_noborder
{
float: left;
margin-right: 16px;
margin-top: 2px;
margin-bottom: 8px;
margin-left: 0px;
}
.imgright
{
border-radius: 5px;
box-shadow: 2px 2px 5px #888888;
float: right;
margin-right: 0px;
margin-top: 2px;
margin-bottom: 8px;
margin-left: 16px;
}
.imgright_noborder
{
float: right;
margin-right: 0px;
margin-top: 2px;
margin-bottom: 8px;
margin-left: 16px;
}
.imgnormal
{
border-radius: 5px;
box-shadow: 2px 2px 5px #888888;
}
.rounded
{
border-radius: 16px;
}
/* Css Effect8 box shadow */
.elegant
{
position:relative;
-webkit-box-shadow:0 1px 4px #000000, 0 0 40px #000000 inset;
-moz-box-shadow:0 1px 4px #000000, 0 0 40px #000000 inset;
box-shadow:0 1px 4px #000000, 0 0 40px #000000 inset;
}
/*#comment
{
margin-left: 32px;
margin-right: 32px;
padding: 8px;
border-radius: 5px;
border: 1px solid #5555ee;
}*/
/* COMMENTS */
.comment
{
color: #000000;
font: 16px "Trebuchet MS", Helvetica, sans-serif;
/*line-height:24px;*/
padding: 15px;
background-color: #f2f2f2;/*#e8e7e2;*/
border: 1px solid #c2c2c2;
-moz-border-radius: 5px; /* Firefox 3.6-, removed in Firefox 13 */
-webkit-border-radius: 5px; /* Safari 4-, Chrome 3- */
border-radius: 5px; /* Firefox 4+, Safari 5+, Chrome 4+, Opera 10.5+, IE9+ */
width: auto%;
margin-right: 32px;
margin-left: 32px;
}
.com_report
{
float: right;
}
.com_title_text
{
font-size:19px;
/*text-transform:capitalize;*/
color: #000000;
}
.com_title
{
padding: 5px;
margin-right: -15px;
padding-left: 10px;
background-color: #ffffff;
margin-left: -15px;
margin-top: -15px;
-moz-border-radius: 5px; /* Firefox 3.6-, removed in Firefox 13 */
-webkit-border-radius: 5px; /* Safari 4-, Chrome 3- */
border-top-right-radius: 5px; /* Firefox 4+, Safari 5+, Chrome 4+, Opera 10.5+, IE9+ */
border-top-left-radius: 5px; /* Firefox 4+, Safari 5+, Chrome 4+, Opera 10.5+, IE9+ */
border-bottom: 1px solid #e2e2e2;
width: auto;
}
.com_body
{
margin: 0 auto;
margin-top: 15px;
font: 'lucida grande',tahoma,verdana,arial,sans-serif;
font-size: 15px;
line-height: 21px;
}
.post r
{
color: #2554C7;
font-style: bold;
/*text-shadow: 0.1em 0.1em 0.2em black*/
}
.post span
{
display:block;
text-align:center;
}
.post form
{
display:block;
text-align:left;
}
.post table
{
display:block-inline;
border-collapse: collapse;
border: 2px solid #DDDDDD;
margin-left: 16px;
margin-right: 16px;
}
.post table caption
{
text-align: center;
font-size: 18px;
font-weight: bold;
margin-top: 3px;
}
.post td
{
border: 1px solid #DDDDDD;
padding: 5px;
font-size: 16px;
font-weight: normal;
}
.post th
{
border: 1px solid #DDDDDD;
padding: 5px;
font-weight: bold;
text-align: center;
background-color: #EEEEEE;
font-size: 16px;
}
input.myButton
{
background-image: url('images/formbutton.png');
width: 200px;
height: 48px;
border-style:none;
font-size: 20px;
color: #ffffff;
}
input.myButton:hover{
background-image: url('images/formbutton_hover.png');
}
input.myButton:active{
background-image: url('images/formbutton_press.png');
}
.cap
{
font-style: italic;
color: #666666;
display: block;
text-align: center;
}
#full_citation
{
display: none;
}
#full_citation_link
{
display: inline;
}
/* Footer */
footer
{
height: auto;
margin-left:auto;
margin-right:auto;
margin-bottom: 16px;
/*background: #000000;*/
background: transparent;
font-size: 12px;
/*color: #fff;*/
width: 984px;
border-radius: 8px;
text-align: center;
padding: 8px;
}
footer a
{
color: #FFF;
}
<!DOCTYPE html>
<body>
<!-- Header -->
<div id="container" class="clearfix">
<div class="nav">
<ul>
<li>Home
</li><li>Tech
<ul>
<li>Subject 1</li>
<li>Subject 2
<ul>
<li>An Item</li>
<li>Some Other Item</li>
<li>And Yet Another!</li>
<li>I Am Running Out of Ideas
<ul>
<li>Even More To Show Expansion</li>
<li>And More</li>
<li>And More!</li>
</ul>
</li>
<li>One Last Item</li>
</ul>
</li>
<li>Subject 3</li>
<li>Subject 4</li>
</ul>
</li><li>Personal
<ul>
<li>Subject 1
<ul>
<li>1111</li>
<li>2222</li>
<li>3333</li>
<li>4444
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
</li>
<li>5555</li>
</ul>
</li>
<li>Subject 2</li>
<li>Subject 3</li>
</ul>
</li><li>Software
<ul>
<li>Subject 1</li>
<li>Subject 2</li>
<li>Subject 3</li>
</ul>
</li><li>Contact
<ul>
<li>Subject 1</li>
<li>Subject 2</li>
<li>Subject 3</li>
</ul>
</li>
</ul>
</div>
<div class="announcement">
<p>
<b>News - </b> Incredibly exciting news goes here!
</p>
</div>
<div id="pagecategory">Test Pages</div>
<div class='header' style="width: 1000px; height: 168px; background: #999999 url('http://www.bitfracture.com/images/header.png') 100% 100% no-repeat;') 100% 100% no-repeat; "></div>
<br/>
<div id="content">
<div class="post">
<h1>Test Page</h1>
Notice that when hovering over "Tech" and opening any sub-menu, all parent menus resize to the size of the sub-menu.<br/><br/>
Also notice that when hovering over "Personal" all sub-menus are now float as far left as the width of the parent, rather than their own width, leaving a gap. <br/><br/>
</div>
</div>
</div>
<footer>
© 2008-2015 Erik Greif All Rights Reserved. <br>Site design and content created by Erik Greif.
</footer>
</body>
</html>