I'm trying to make a dropdown menu on my website. I want to be able to click on a down arrow and have a menu pop up below it. Right now the menu only shows up part way on the screen.
Here's a picture to show what is going on now:
I would like to have the right side of the menu items lined up with the down arrow, instead of the left side like it is.
Here's the CSS that i'm using right now.
* {
margin: 0;
padding: 0;
border: 0;
}
body {
background-image: url(bg.jpg);
background-position: center;
background-repeat: repeat;
}
#top {
background-color: #333;
height: 30px;
margin-bottom: 10px;
}
#menu {
color: #CCC;
height: 30px;
font-family: Arial, Helvetica, sans-serif;
font-weight: bold;
font-size: 12px;
position: absolute;
}
#top_right {
height: 30px;
width: auto;
text-align: left;
float: right;
margin-right: 5px;
color: #CCC;
font-family: Arial, Helvetica, sans-serif;
font-weight: bold;
font-size: 12px;
}
.menu {
padding-left: 10px;
}
a.mlink:hover {
color: #FFF;
text-decoration: none;
}
a.mlink:link {
color: #CCC;
text-decoration: none;
}
a.mlink:visited {
color: #CCC;
text-decoration: none;
}
a.mlink:hover {
color: #FFF;
text-decoration: none;
}
a.mlink:active {
color: #CCC;
text-decoration: none;
}
#selected {
color: #6C0;
}
#content {
background-color: #CCC;
}
/*
START OF MENU TEST
*/
#esempio{
margin:0;
padding:0;
}
#esempio ul{
padding:0;
margin:0;
}
#esempio li{
position: relative;
float: left;
list-style: none;
margin: 0;
padding:0;
}
#esempio li a{
width:auto;
height: 30px;
display: block;
text-decoration:none;
text-align: center;
line-height: 30px;
background-color: black;
color: white;
}
#esempio li a:hover{
background-color: #666;
}
#esempio ul ul{
position: absolute;
top: 30px;
width: 100px;
visibility: hidden;
}
#esempio ul li:hover ul{
visibility:visible;
}
/*
END OF MENU TEST
*/
The containing element needs to be positioned:
li {
position: relative;
}
Then your dropdown element can be positioned to be flush to the right of its container:
li .submenu {
position: absolute;
right: 0;
}
Without seeing markup, or an example of how your page operates, I cannot be much more specific.
Fiddle: http://jsfiddle.net/jonathansampson/CXbTX/
Sidenote
As an aside, I would avoid doing this:
* { margin: 0; padding: 0; border: 0 }
This will cause you some frustration down the line, especially when it comes to styling form elements and such. I would encourage you instead to use something that will normalize the CSS in a more intuitive manner, like Meyer's Reset.
Related
I am trying to remove the white space in the dropdown menu. I have tried padding:0 and margin:0, but both do not seem to work. I am currently using Bootstrap 3.3.7.
My HTML:
HTML Navbar code
My CSS:
.topnav {
width: 100%;
height: 50px;
background-color: transparent;
opacity: 0.7;
margin: 0;
padding-left: 0;
padding-right: 0;
border: none;
}
.topnav ul {
list-style: none;
margin: 0;
padding: 0;
position: absolute;
}
.topnav li {
float: left;
list-style-type: none;
}
.topnav li a {
width: 150px;
color: #FFFFFF;
display: block;
text-decoration: none;
font-size: 20px;
text-align: center;
padding: 10px;
font-family: Montserrat;
font-weight: bold;
}
.topnav li ul li a {
background-color: #000000;
color: #FFFFFF;
padding: 8px;
}
White Space in Navbar
I am stuck with an extra close curry bracket in CSS that I accidentally put prior writing other lines. If I leave it there, it acually does no harm to the result. However, when I remove it, the position of other elements are repositioned.
(( In lines of code, the extra close curly bracket is where the arrow pointing ))
Please click on the links below to see both results.
Question: Is there any way to remove it without repositioning other elements?
Without the Close Curly Bracket
With the Close Curly Bracket
body{
font: 15px/1.5 Helvetica, Arial, sans-serif;
padding: 0;
margin: 0;
p(color#282f38);
background-color: #F5F2ED;
font:696863;
}
/*Global*/
.container{
width:80%;
margin:auto;
overflow:hidden;
}
ul{
margin:0;
padding:0;
}
/* Header */
#fixed{
position: fixed;
}
header{
position: fixed;
width: 100%;
background:#282f38;
color:#F5F2ED;
padding-top: 10px;
min-height:50px;
border-bottom:#F5F2ED 3px solid;
}
header a{
color:#F5F2ED;
text-decoration:none;
text-transform:uppercase;
font-size: 18px;
}
header li{
float:left;
display: inline;
padding: 0 20px 0 20px;
}
header #resume{
float: left;
}
header #resume h1{
margin: 0;
padding: 0;
}
header nav{
position: relative;
left: 30%;
float: right;
margin-top: 10px;
}
header .highlight, header .current a{
color:#696863 ;
font-weight: bold;
}
header a:hover{
color:#696863;
font-weight: bold;
}
/* Showcase */
#showcase {
min-height: 350px;
background: url('../Resources/Photographer.png') no-repeat 0 -120px;
align-items: center;
color: #ffffff;
overflow: auto;
}
#showcase h1{
text-align: center;
margin-top: 100px;
font-size: 40px;
margin-bottom: 10px;
}
#showcase p{
text-align:justify;
margin:0;
padding:0;
font-size: 14;
text-indent: inherit;
}
/* Social Medias*/
#socialmedias{
position:fixed;
padding-top: : 5px;
right: 20px;
top: 130px;
display: block;
vertical-align: baseline;
font: inherit;
list-style-type: none;
}
} <<-----------------------------------------------------------------------
/* Message Me Box */
#box{
width: 30%;
overflow: hidden;
padding: 1px;
}
/* Box Border */
.fieldset{
display: inline-block;
border: 3px solid;
float: right;
}
/* Message Me Title */
#legend{
font-size: 20px;
font-weight: bold;
color:#282f38;
}
/* Name Input */
#form-name{
display: block;
width: 200px;
margin-bottom: 10px;
}
/* Email Input */
#form-email{
display: block;
width: 200px;
margin-bottom: 10px;
}
/* Message Input */
#form-message{
display: block;
margin-bottom: 10px;
}
/* Contact */
.button_contact{
position: relative;
height: 30px;
width: 100%;
background:#696863;
color: #F5F2ED;
font-size: 14px;
text-transform: uppercase;
border: 0;
}
The extra curly bracket is being treated as part of the selector for the next rule. i.e. the rule is
} #box {
width: 30%;
overflow: hidden;
padding: 1px;
}
So } #box matches nothing. When you remove the }, the selector is #box and matches the element with id "box".
If you don't want the effect you get when removing the extra }, remove the entire rule.
Not just one error,
Check the comments I added in your code.
Best way to avoid these errors are using an IDE.
There are so many open source tools available. For example NetBeans.
They can help you to identify your errors.
Check this screenshot, they are easy to use also.
/* Social Medias*/
#socialmedias{
position:fixed;
padding-top: : 5px; // Error 1,
right: 20px;
top: 130px;
display: block;
vertical-align: baseline;
font: inherit;
list-style-type: none;
}
} // Error 2
body{
font: 15px/1.5 Helvetica, Arial, sans-serif;
padding: 0;
margin: 0;
p(color#282f38); // Error 3
background-color: #F5F2ED;
font:696863;
}
You have many errors in your css. I've validated your css on W3C CSS Validator
I've changed your CSS. See below:
body {
font: 15px/1.5 Helvetica, Arial, sans-serif;
padding: 0;
margin: 0;
background-color: #F5F2ED;
}
p {
color: #282f38;
}
/*Global*/
.container {
width: 80%;
margin: auto;
overflow: hidden;
}
ul {
margin: 0;
padding: 0;
}
/* Header */
#fixed {
position: fixed;
}
header {
position: fixed;
width: 100%;
background: #282f38;
color: #F5F2ED;
padding-top: 10px;
min-height: 50px;
border-bottom: #F5F2ED 3px solid;
}
header a {
color: #F5F2ED;
text-decoration: none;
text-transform: uppercase;
font-size: 18px;
}
header li {
float: left;
display: inline;
padding: 0 20px 0 20px;
}
header #resume {
float: left;
}
header #resume h1 {
margin: 0;
padding: 0;
}
header nav {
position: relative;
left: 30%;
float: right;
margin-top: 10px;
}
header .highlight, header .current a {
color: #696863;
font-weight: bold;
}
header a:hover {
color: #696863;
font-weight: bold;
}
/* Showcase */
#showcase {
min-height: 350px;
background: url('../Resources/Photographer.png') no-repeat 0 -120px;
align-items: center;
color: #ffffff;
overflow: auto;
}
#showcase h1 {
text-align: center;
margin-top: 100px;
font-size: 40px;
margin-bottom: 10px;
}
#showcase p {
text-align: justify;
margin: 0;
padding: 0;
font-size: 14px;
text-indent: inherit;
}
/* Social Medias*/
#socialmedias {
position: fixed;
padding-top: 5px;
right: 20px;
top: 130px;
display: block;
vertical-align: baseline;
font: inherit;
list-style-type: none;
}
/* Message Me Box */
#box {
width: 30%;
overflow: hidden;
padding: 1px;
}
/* Box Border */
.fieldset {
display: inline-block;
border: 3px solid;
float: right;
}
/* Message Me Title */
#legend {
font-size: 20px;
font-weight: bold;
color: #282f38;
}
/* Name Input */
#form-name {
display: block;
width: 200px;
margin-bottom: 10px;
}
/* Email Input */
#form-email {
display: block;
width: 200px;
margin-bottom: 10px;
}
/* Message Input */
#form-message {
display: block;
margin-bottom: 10px;
}
/* Contact */
.button_contact {
position: relative;
height: 30px;
width: 100%;
background: #696863;
color: #F5F2ED;
font-size: 14px;
text-transform: uppercase;
border: 0;
}
/* Header */
----------------->#fixed{<------------------
position: fixed;
}
Try to change the id where the arrow is pointed, use class for that, because there are so many conflicts, if we use IDs directly. For more information please find the link below:
https://github.com/CSSLint/csslint/wiki/disallow-ids-in-selectors
i think there is something to do with "#fixed" id name in the html and css.
try to change the name to something else. The property and your name might be colliding with each other. So change it...
I'm trying to let my menu stick to the bottom of my header. I've already tried getting it down, with deleting the float's, adding some, playing with padding/margin (this isn't an option seems to me?
<div id="header">
<div id="logo">
<h1>blah</h1>
<h3>Blah</h3>
</div>
<div id="menu">
<ul>
<li>qsdfqsdfqsdf</li>
<li>qsdfqdsfqsdf!</li>
<li>qdsf</li>
<li>qdsf</li>
</ul>
</div>
</div>
CSS:
/** HEADER */
#header {
height: 125px!important;
background: #000;
position: fixed;
top: 0;
width: 100%;
}
/* Logo */
#logo
{
float: left;
width: 250px;
padding: 20px 0px 0px 50px;
text-transform: uppercase;
}
#logo h3{
color: #fff;
margin-left: 1em;
font-size: 1em;
}
#logo h1
{
padding: 5px 10px 0px 0px;
}
#logo h1 span, #logo h3 span{
color: #000;
}
#logo h1 a
{
text-decoration: none;
font-size: 1.5em;
font-weight: 300;
color: #FFFFFF;
}
#logo p
{
display: block;
margin-top: -10px;
padding: 0px 0px 0px 0px;
letter-spacing: 1px;
font-size: 1.2em;
color: #FFFFFF;
}
#logo p a
{
color: #FFFFFF;
}
/* Menu */
#menu{
float: right;
width: 600px;
margin: 2em 2em 0 0;
}
#menu ul{
float: right;
margin: 0;
padding: 0;
list-style: none;
line-height: normal;
position: relative;
display: inline-table;
}
#menu li
{
float: left;
}
#menu a
{
display: block;
letter-spacing: 1px;
text-decoration: none;
text-transform: uppercase;
font-size: 18px;
font-weight: 300;
color: #FFFFFF;
padding: 1em;
text-decoration: none;
}
#menu a:hover{
color: #000;
text-decoration: none;
background: #fff;
}
#menu ul li {
float: left;
}
#menu ul li:hover {
}
Here an example:
http://jsfiddle.net/2wmSt/
Almost there mate, just position the menu absolute to the bottom of the header.
#menu{
position:absolute;
bottom:0;
right:0;
}
jsfiddle example
I'm currently writing a website from scratch and I'm having some problems with my css and html. I not sure how to create a space between my navigation bar and my content box.
Here is my html:
http://pastebin.com/cTVCx0gm
and my css:
http://pastebin.com/w61aTmHv
Since I'm a novice programmer, I'm not really sure what I'm doing wrong...
Thanks!
All you need to do is change your "li" class to this:
li
{
display:inline-block;
}
I've created this fiddle here so you can see the output. You can move the center bar left and right to see the behavior.
http://jsfiddle.net/ninja1/ALKPP/
try this
Demo
ul {
list-style-type: none;
margin: 0;
padding: 0;
width: 100%;
}
li {
display: inline;
float: left;
}
a {
display: block;
width: 150px;
height: 30px;
background-color: #024c68;
text-align: center;
padding: 10px;
font-size: 20px;
display: inline;
}
a:link {
color: #ffffff;
text-decoration: none;
font-family: verdana;
} /* unvisited link */
a:visited {
color: #ffffff;
text-decoration: none;
font-family: verdana;
} /* visited link */
a:hover {
color: #ffffff;
text-decoration: none;
font-family: verdana;
background: #226078;
} /* mouse over link */
a:active {
text-decoration: underline;
text-decoration: none;
font-family: verdana;
} /* selected link */
/*this is the body css*/
body {
background-color: #62b1d0;
}
div.box {
background-color: #99CCFF;
border: 5px solid #99CCFF;
clear: left;
margin: 9px 0 0 0;
padding: 8px 10px;
width: 900px;
}
.clrboth {
clear: both;
}
Here you can see the code: http://jsfiddle.net/LQSK3/1/
I can't get display: inline; working there for every li element.
Also got the problem width the line.png image, as it's height is the same as the font height, I want it to has 35px height with margin left and right set to 5px.
Where is the problem?
You need to update your style sheet. Please add this new style:
#menu {
position: relative;
clear: both;
top: -3px;
background-color: coral;
border: 1px solid black;
width: 800px;
height: 35px;
float:left;
}
li { display: inline;float:left; }
#menu ul {
position: absolute;
font-family: Century Gothic, sans-serif;
font-size: 14px;
list-style-type: none;
padding: 0;
margin: 9px 0 0 123px;
width: 649px;
height: 39px;
color: #FFF;
float:left;
}
a { font-weight: bold; color: red; text-decoration: none; }
a:hover { text-decoration: underline; }
#menu a {
background: url('http://i.imgur.com/rzNj0.png') top right no-repeat;
width: 65px;
height: 18px;
float: left;
margin: 0px 5px;
}
You need to add float: left; to menu div,ul,li and a . Also should set width and height and margin of the a tag.
Here is a working sample : http://jsfiddle.net/YjeBs/
Hope this helps :)
EDIT:
If you want your line to extend from top to bottom of the menu div you can change your styles to:
#menu {
position: relative;
clear: both;
top: -3px;
background-color: coral;
border: 1px solid black;
width: 800px;
height: 35px;
float:left;
}
li {
float: left;
height: 35px;
display:inline;
}
#menu ul {
color: #FFFFFF;
float: left;
font-family: Century Gothic,sans-serif;
font-size: 14px;
height: 35px;
list-style-type: none;
margin: 0 0 0 123px;
padding: 0;
position: absolute;
width: 649px;
}
a { font-weight: bold; color: red; text-decoration: none; }
a:hover { text-decoration: underline; }
#menu a {
background: url("http://i.imgur.com/rzNj0.png") no-repeat scroll right top transparent;
float: left;
height: 29px;
margin: 0 5px;
padding-top: 8px;
width: 65px;
}
Hope this is you want :)
just change li { diplay: inline; } with li { display: inline; } it works.