White box within banner image - html

I am trying to add a border-top with 2px on my fixed navbar however on the a href hover it pushes all of the nav items down by 2px, I am trying to make it so it's static, any help is appreciated.
.fixed-nav-bar {
position: fixed;
top: 0;
left: 0;
right: 0;
z-index: 9999;
width: 100%;
height: 70px;
background-color: #3f3f3f;
}
.fixed-nav-bar li, .fixed-nav-bar a {
height: 0 auto;
line-height: 50px;
width: 100px;
overflow: hidden;
}
.menu {
width: 90%;
max-width: 960px;
margin: 0 auto;
text-align: center;
}
.menu a, .menu a:visited {
color: #ffffff;
overflow: hidden;
}
.menu a:hover, .menu a:target {
display: block;
border-top: 2px solid #72BCD4;
color: #72BCD4;
}
.menu-items { display: inline-block; }
.menu-items li {
display: inline-block;
margin-right: 10px;
margin-left: 10px;
}
.menu-items a {
text-decoration: none;
}
.show, .hide {
display: none;
padding-left: 15px;
background-color: transparent;
background-repeat: no-repeat;
background-position: center left;
color: #dde1e2;
}
.show {
background-image: url(../assets/down-arrow-icon.png);
}
.hide {
background-image: url(../assets/up-arrow-icon.png);
}
<nav class="fixed-nav-bar">
<div id="menu" class="menu">
<!-- Example responsive navigation menu -->
<a class="show" href="#menu">Menu</a><a class="hide" href="#hidemenu">Menu</a>
<ul class="menu-items">
<li>HOME</li>
<li>ABOUT</li>
<li>DESIGNS</li>
<li>CONTACT</li>
</ul>
</div>
</nav>

It's because of no border. Either give a transparent border with the same width or use the colour of the border. But in your case, it's screwed up. So I changed the overflow: hidden and used margin-top: -2px:
.fixed-nav-bar {
position: fixed;
top: 0;
left: 0;
right: 0;
z-index: 9999;
width: 100%;
height: 70px;
background-color: #3f3f3f;
}
.fixed-nav-bar li, .fixed-nav-bar a {
height: 0 auto;
line-height: 50px;
width: 100px;
}
.menu {
width: 90%;
max-width: 960px;
margin: 0 auto;
text-align: center;
}
.menu a, .menu a:visited {
color: #ffffff;
}
.menu a:hover, .menu a:target {
display: block;
border-top: 2px solid #72BCD4;
color: #72BCD4;
margin-top: -2px;
}
.menu-items {
display: inline-block;
}
.menu-items li {
display: inline-block;
margin-right: 10px;
margin-left: 10px;
}
.menu-items a {
text-decoration: none;
}
.show, .hide {
display: none;
padding-left: 15px;
background-color: transparent;
background-repeat: no-repeat;
background-position: center left;
color: #dde1e2;
}
.show {
background-image: url(../assets/down-arrow-icon.png);
}
.hide {
background-image: url(../assets/up-arrow-icon.png);
}
<nav class="fixed-nav-bar">
<div id="menu" class="menu">
<!-- Example responsive navigation menu -->
<a class="show" href="#menu">Menu</a><a class="hide" href="#hidemenu">Menu</a>
<ul class="menu-items">
<li>HOME</li>
<li>ABOUT</li>
<li>DESIGNS</li>
<li>CONTACT</li>
</ul>
</div>
</nav>

That's all because of box-sizing property. by default it adds value of paddings/margins/borders outside of content area, so element becomes bigger. Just define globally * {box-sizing: border-box;} it will make elements to fixed sizes. That means if element had no border, and then it adds, the element's area for content will be smaller, but the whole size will be the same. However, I strongly recommend you to use border at the beginning, otherwise, it will jump inside the element. You can set the color 'transparent' and it won't be visible. Then just by changing border-color it will be nicer.

I have created a little fiddler:
https://jsfiddle.net/marco_rensch/0hva2241/
this could be a possible solution
checkout CSS Code Changes between row 31 and 51
the key is to add a default border 2px transparent to the li's and change it by hover:
.menu-items li:hover{border-top: 2px solid #72BCD4;}

Related

How to extend a navbar background, while keeping the elements in the center?

I want the blue of the navbar to extend across the screen, while the About, Updates, and Who am I? to stay in the middle? I want the background to remain a background so that it will change if I resize anything. I am fine with a different centering method, if that works better.
.centered {
display: flex;
justify-content: center;
}
#navbar {
background: #0099CC;
color: #FFF;
height: 51px;
padding: 0;
margin: 0;
border-radius: 0px;
}
*{
padding:0;
margin:0;
}
#navbar ul, #navbar li {
margin: 0 auto;
padding: 0;
list-style: none
}
#navbar ul {
width: 100%;
}
#navbar li {
float: left;
display: inline;
position: relative;
}
#navbar a {
display: inline-block;
display:flex;
line-height: 51px;
padding: 0 14px;
text-decoration: none;
color: #FFFFFF;
font-size: 16px;
text-align: center;
}
#navbar li a:hover {
color: #0099CC;
background: #F2F2F2;
}
#navbar label {
display: none;
line-height: 51px;
text-align: center;
position: absolute;
left: 35px
}
<div class="centered">
<nav id='navbar'>
<ul>
<li><a href='#'>Home</a></li>
<li><a href='#'>Updates</a></li>
<li><a href='#'>Who am I?</a></li>
</ul>
</nav>
</div>
You can add 100% width to #navbar to extend across the screen and change display & width properties for #navbar ul, like this
#navbar {
width: 100%;
}
#navbar ul {
display: flex;
width: fit-content;
}

Using float to place an element in the right side with CSS

I'm trying to do a nav bar with a contact button stuck to the right of the page. I want contact to be aligned with the rest of the elements of the nav bar, however when I add float: right; it just disaligns my nav bar and it doesn't move contact to the right.
Here you can see my code: http://jsfiddle.net/LG2vR/19/
Can someone please tell me the proper way to accomplish this please?
Thanks!
Am not sure if this is what you need exactly, see the updated fiddle
http://jsfiddle.net/ov74xcyg/1/
Basically, i have used position absolute to move your last child of the navigation to the right side and increased width of the navigation till the end of the header.
nav {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100px;
padding: 10px 100px;
z-index: 500;
box-sizing: content-box;
transition: .3s;
background: red;
}
nav.white {
background: white;
height: 35px;
padding: 10px 100px;
transition: .5s;
}
nav ul {
list-style: none;
float: left;
margin: 0;
padding: 0;
display: flex;
width: 90%;
position: relative;
}
nav ul li {
list-style: none;
}
nav ul li:last-child {
display: inline-block;
right: 5%;
position: absolute;
top: 0;
}
nav ul li a {
line-height: 80px;
color: #FFFFFF;
margin: 12px 30px;
text-decoration: none;
text-transform: capitalize;
transition: .5s;
padding: 10px 5px;
font-size: 16px;
}
nav ul li a:hover {
background-color: rgba(255,255,255,0.2);
}
nav.white ul li a {
color: #000;
line-height: 40px;
transition: .5s;
}
nav ul li a:focus {
outline: none;
}
<div class="wrapper">
<nav>
<ul>
<li>LOGO</li>
<li>Home</li>
<li>Page 1</li>
<li>Page 2</li>
<li><a class="contact" href="#">Contact</a></li>
</ul>
</nav>
Just add:
nav ul li a {
float: left;
}
right before:
nav ul li a.contact {
float: right;
}
or use flexbox!
.wrapper li {list-style-type: none;}
.wrapper {
overflow: hidden;
background-color: red;
}
.wrapper .logo{
margin-right : 30px;
}
.wrapper a {
float: left;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}
.wrapper a:hover {
background-color: #ddd;
color: black;
}
.wrapper a.active {
background-color: #4CAF50;
color: white;
}
.topnav-right {
float: right;
}
<div class="wrapper">
<a class="active logo" href="#">Logo</a>
Home
Page 1
Page 2
<div class="topnav-right">
<li><a class="contact" href="#">Contact</a></li>
</div>
</div>

CSS display block not working with anchor links

I am trying to make a dropdown-menu. So for this purpose, I've created a div and some anchor links inside, but the display: block; is not working. The cursor is default & the anchor does not seem to be a link.
Here is my HTML:
<div id="custom-wrapper">
<ul>
<li>View full profile</li>
<li>Logout</li>
</ul>
</div>
The CSS:
div#custom-wrapper
{
width: 200px;
height: auto;
position: fixed;
right: 15px;
top: 38px;
border-radius: 6px;
background: #fff;
border: 1px solid lightgrey;
}
div#custom-wrapper ul
{
list-style-type: none;
}
div#custom-wrapper ul li
{
width: 100%;
height: 50px;
line-height: 50px;
text-align: center;
}
div#custom-wrapper ul li a
{
text-decoration: none;
display: block;
color: grey;
font-family: sans-serif;
border-bottom: 1px solid lightgrey;
}
What's wrong with my code?
Display block element works perfect, Just you need to remove padding and margin for ul element.
/*** Default CSS Attributes ***/
#custom-wrapper ul {
margin: 0;
padding: 0;
}
/*** Overwrite CSS Attributes ***/
#custom-wrapper ul {
margin: 0 !important;
padding: 0 !important;
}
div#custom-wrapper {
width: 200px;
height: auto;
position: fixed;
right: 15px;
top: 38px;
border-radius: 6px;
background: #fff;
border: 1px solid lightgrey;
}
div#custom-wrapper ul {
list-style-type: none;
margin: 0;
padding: 0;
}
div#custom-wrapper ul li {
width: 100%;
height: 50px;
line-height: 50px;
text-align: center;
}
div#custom-wrapper ul li a {
text-decoration: none;
display: block;
color: grey;
font-family: sans-serif;
border-bottom: 1px solid lightgrey;
}
<div id="custom-wrapper">
<ul>
<li>View full profile</li>
<li>Logout</li>
</ul>
</div>
There is a padding for ul. Remove it:
div#custom-wrapper ul
{
list-style-type: none;
padding:0;
}
That is not the right way to build a dropdown. Check this (you would need to include Bootstrap library though, which by the way may make your life much easier).

Custom Image within LI Toolbar in HTML/CSS

So I've been trying to get my custom image to appear in a vertical toolbar, but I'm having trouble. I'm referencing http://codepen.io/nikhil/pen/sicrK which has all of the source code; I want pretty much the same toolbar, but with custom images. Here's a snippet, from the part I've been trying to adjust to get it to work:
From the HTML:
<ul class="menu">
<li title="home">menu</li>
<li title="search">search</li>
<li title="pencil">pencil</li>
<ul>
From the CSS - before (works, as in the link):
.menu li a.search:before {
content: "\f002";
}
From the CSS - with my attempted modification (doesn't work; no image appears)
.menu li a.search:before {
list-style-image: "\newImage.png";
}
So, I was trying to use list-style-image, but no image would appear. The image I'm referencing in the folder is 100x100px. I tried background-image and just using <img src="newImage.png"> inside the HTML markup, but no dice - no image appears and there are no errors logged in the console. How can I resolve this issue? The toolbar re-sizes according to the CSS based on the screen size, so I assume that means the size of my image doesn't really matter. Or, do I need to be using an SVG instead? Thanks for any help - I'm new to working with CSS.
You are misunderstanding the concept of Icon Fonts.
If you want to display an image in a pseudo-element, then you should use background property, just as with any other element. See fro more Using :before CSS pseudo element to add image to modal
Please have a look at my snippet:
$(document).ready(function() {
$(".menu-button").click(function() {
$(".menu-bar").toggleClass("open");
})
})
.menu,
.menu-bar {
position: fixed;
top: 0;
left: 0;
height: 100%;
list-style-type: none;
margin: 0;
padding: 0;
background: #f7f7f7;
z-index: 10;
overflow: hidden;
box-shadow: 2px 0 18px rgba(0, 0, 0, 0.26);
}
.menu li a {
display: block;
text-indent: -500em;
height: 5em;
width: 5em;
line-height: 5em;
text-align: center;
color: #72739f;
position: relative;
border-bottom: 1px solid rgba(0, 0, 0, 0.05);
transition: background 0.1s ease-in-out;
}
.menu li a:before {
font-family: FontAwesome;
speak: none;
text-indent: 0em;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
font-size: 1.4em;
}
.menu li a.search:before {
content: '';
background: url("http://piq.codeus.net/static/media/userpics/piq_162172_400x400.png");
background-size: contain;
background-repeat: no-repeat;
background-position: 50% 50%;
/* content: "\f002"; */
}
.menu li a.archive:before {
content: '';
background: url("http://i.imgur.com/HsZNOfb.png");
background-size: contain;
background-repeat: no-repeat;
background-position: 50% 50%;
/* content: "\f187"; */
}
.menu li a.pencil:before {
content: '';
background: url("http://thepunkeffect.com/wp-content/uploads/2013/11/01-03.jpeg");
background-size: contain;
background-repeat: no-repeat;
background-position: 50% 50%;
/* content: "\f040"; */
}
.menu li a.contact:before {
content: "\f003";
}
.menu li a.about:before {
content: "\f007";
}
.menu li a.home:before {
content: "\f039";
}
.menu-bar li a:hover,
.menu li a:hover,
.menu li:first-child a {
background: #267fdd;
color: #fff;
}
.menu-bar {
overflow: hidden;
left: 5em;
z-index: 5;
width: 0;
height: 0;
transition: all 0.1s ease-in-out;
}
.menu-bar li a {
display: block;
height: 4em;
line-height: 4em;
text-align: center;
color: #72739f;
text-decoration: none;
position: relative;
font-family: verdana;
border-bottom: 1px solid rgba(0, 0, 0, 0.05);
transition: background 0.1s ease-in-out;
}
.menu-bar li:first-child a {
height: 5em;
background: #267fdd;
color: #fff;
line-height: 5
}
.para {
color: #033f72;
padding-left: 100px;
font-size: 3em;
margin-bottom: 20px;
}
.open {
width: 10em;
height: 100%;
}
#media all and (max-width: 500px) {
.container {
margin-top: 100px;
}
.menu {
height: 5em;
width: 100%;
}
.menu li {
display: inline-block;
float: left;
}
.menu-bar li a {
width: 100%;
}
.menu-bar {
width: 100%;
left: 0;
height: 0;
}
.open {
width: 100%;
height: auto;
}
.para {
padding-left: 5px;
}
}
#media screen and (max-height: 34em) {
.menu li,
.menu-bar {
font-size: 70%;
}
}
#media screen and (max-height: 34em) and (max-width: 500px) {
.menu {
height: 3.5em;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<link href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.0.3/css/font-awesome.min.css" rel="stylesheet" />
<ul class="menu">
<li title="home">menu
</li>
<li title="search">search
</li>
<li title="pencil">pencil
</li>
<li title="about">about
</li>
<li title="archive">archive
</li>
<li title="contact">contact
</li>
</ul>
<ul class="menu-bar">
<li>Menu
</li>
<li>Home
</li>
<li>Profile
</li>
<li>Editorial
</li>
<li>About
</li>
</ul>

CSS Drop Down menu being cut off by parent div height

In my set up I have my navigation bar set horizontally and contained within my header div like this:
<div id="header-section">
<div id="main-menu-wrapper">
<ul id="main-menu">
<li>Home</li>
<li>Services
<ul id="sub-men">
<li>Service 1</li>
<li>Service 2</li>
<li>Service 3</li>
</ul>
</li>
</ul>
<div class="clear"></div>
</div>
</div>
My problem is that the sub-menu is not showing because the height on "main-menu-wrapper" is set to auto. The sub-menu is showing when I set a height like 100px. When I set the position on the sub-menu to static instead of absolute, it expands the entire main-menu-wrapper. How can I get the sub-menu to show properly?
Here's the CSS portion for my whole header section:
#header-section {
position: relative;
width: 100%;
padding: 5px 0px;
background: #740600;
}
#main-menu-wrapper {
position: relative;
width: 74%;
min-width: 600px;
height: auto;
margin: 0% auto;
}
#main-menu {
list-style: none;
font-weight: bold;
line-height: 150%;
}
#main-menu li {
position: relative;
float: right;
margin: 0px 5px;
}
#main-menu a {
padding: 3px;
color: #ffffff;
background: #740600;
text-decoration: none;
border-radius: 5px;
}
#main-menu a:hover {
padding: 3px;
color: #740600;
background: #ffffff;
text-decoration: none;
}
#main-menu li ul {
position: absolute;
display: none;
}
#main-menu li ul li{
float: none;
}
#main-menu li:hover ul {
display: block;
}
#main-menu li ul a {
padding: 3px;
color: #ccc;
background: #740600;
text-decoration: none;
border-radius: 5px;
}
#main-menu li ul a:hover {
padding: 3px;
color: #740600;
background: #ccc;
text-decoration: none;
}
#banner-wrapper {
position: relative;
padding: 5px 0 5px;
}
#banner {
position: relative;
max-width: 75%;
min-width: 600px;
margin: 0% auto;
background: #ffffff;
}
#logo {
max-width: 600px;
height: auto;
}
I'm a little confused by what you're asking here, but I created a fiddle where your menu shows.
I deleted the styles for #main-menu-wrapper and I removed the background color on #header-section.
Hopefully this can be a decent starting point for you: http://jsfiddle.net/44vRN/
#header-section {
position: relative;
width: 100%;
padding: 5px 0px;
}
You could try to use absolute positioning on the submenu to remove it from the document flow.