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;
}
Related
My mobile menu has large gaps in between the list items, my code does not help me, can anyone else see something?
This is most likely due to px or some other screen-scaled metric not translating properly onto the mobile resolution.
I have tried unsuccessfully to upload a supporting image.
html, body
{
font-family: "Lato", sans-serif;
width: 100%;
height: auto; margin: 0;
}
.nav {
background-color: #3333FF;
width: 100%;
height: 40px;
line-height: 40px;
}
.menu {
font-family: Monserrat, sans-serif;
font-size: 18px;
color: white;
list-style-type: none;
padding: 0;
position: relative;
z-index: 1;
}
.menu a {
text-decoration: none;
color: #fff;
line-height: 40px; /* Line height 40px, not 40-px */
}
.menu ul li {
text-align: center;
display: inline;
padding: 10px;
width: 11.11%;
}
.menu li:visited, .menu li:active, .active, .menu li:hover
{
background: #0000EE;
color: #fff;
}
label {
margin: 0 14px 0 0;
font-size: 20px;
display: none;
}
#toggle {
display: none;
}
/* Show Hamburger */
#media screen and (max-width: 500px) {
label {
cursor: pointer;
display: block;
color: #fff;
}
.menu {
text-align: center;
width: 100%;
display: none;
}
.menu a {
display: block;
background-color: #999;
margin:0;
padding: 0;
}
#toggle:checked + .menu {
display: block;
}
} /* A finishing bracket was missing */
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'm working on my final project for my HTML/CSS class. I'm trying to (potentially over ambitious) create a collapsible accordion style menu. I've managed to get it hid and only show up with a hover, but for some reason, there is an element causing the boxes to have spaces between them, and I'm unsure how to contain the text in the boxes. Thank you in advance for any ideas you have!
Screenshot:
How to remove the area with the red background?
EDIT: Sorry first time posting here, wasn't sure how much code to post.
HTML Code
#charset "utf-8";
/* HTML Styles */
/*Body Styles*/
html {
background-image: url(../images/sushi_wallpaper.jpeg);
}
body {
display:block;
width: 100%;
max-width: 1040px;
margin-left: auto;
margin-right: auto;
background-color: white;
border: 7px solid rgb(149,54,0);
border-top: none;
border-bottom: none; /* BODY BORDER, RE-ADDRESS WITH COLORS */
position: static;
border-collapse: collapse;
}
/*Navigation Styles*/
nav {
font-family: 'Times New Roman', serif;
text-align: center;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
}
nav.horizontalnavigation li {
/*BUTTON SIZES */
display: block;
float: left;
width: 25%;
text-decoration: none;
line-height: 2;
padding-bottom: 1em;
}
nav.horizontalnavigation li a:hover {
background-color:rgb(255,198,73);
}
/* COLLAPSE ABLE MENU */
ul.collapse {
display: none;
}
a.accord:hover+ul.collapse, ul.collapse:hover {
display: block;
float: left;
width: 100%;
}
.collapse > .submenu {
width: 100%;
background-color: red; }
ul.collapse li {
width: 80%;
float: right;
border: none;
line-height: initial;
}
nav.horizontalnavigation > ul > li:hover:nth-of-type(4):after {
text-decoration: underline;
content: #collapse;
}
nav.horizontalnavigation > ul > li:target {
display: block;
}
nav.horizontalnavigation a {
/*"BUTTONS" STYLES HERE */
display: block;
color: black;
text-decoration: none;
background-color: white;
border: 3px solid rgb(149,54,0);
box-shadow: 0 0 1em .3em rgb(255,198,73) inset;
}
/* Header Styles */
h1 {
font-family: 'Times New Roman', Times, serif;
font-size: 2.2em;
font-weight: normal;
margin: 0.5em 0;
}
/*Font Styles */
#font-face {
font-family: speedingBrush;
src: url("../fonts/SpeedingBrush.ttf") format("truetype");
}
cite {
font-style: italic;
}
/* Paragraph Styles */
p {
display:block;
font-size: 1em;
line-height: 1.375;
text-indent: 8%;
}
/*Images Styles*/
body > header > img.banner {
display:block;
width: 100%;
}
/* DIV & Section Styles */
/*List Styles */
/*Footer Styles*/
footer {
display: block;
text-align: center;
width: 100%;
border: 2px solid rgb(149,54,0);
line-height: 2;
margin-top: 15em;
clear: both;
}
<nav class="horizontalnavigation">
<ul>
<li>Popular Types of Sushi</li>
<li>Where can I get sushi?</li>
<li>FREE Sushi Catalog</li>
<li>Additional Resources
<ul class="collapse">
<li class="submenu">WWWWWWWWWWWWWWW</li>
<li class="submenu">WWWWWWWWWWWWWWWWWWWWWWWWW</li>
<li class="submenu">WWWWWWWWWWWW</li>
</ul>
</li>
</ul>
</nav>
Just add
ul.collapse li.submenu{
padding: 0;
}
Remove padding-bottom: 1em; and it will solve your issue.
nav.horizontalnavigation li {
/*BUTTON SIZES */
display: block;
float: left;
width: 25%;
text-decoration: none;
line-height: 2;
padding-bottom: 1em; // <----- This is causing the spacing
}
I'm trying to position the main content to the left and the nav to the right. Currently the nav is sitting at the bottom. Anyone tell me where I went wrong?
The Code (http://codepen.io/kiddigit/pen/PNXRVE)
* {
font-family: garamond;
line-height: 1.9em;
color: #212121;
}
.wrapper {
width: 75%;
margin: 0 auto;
border: 1px solid blue;
padding: 10px;
overflow: hidden;
}
.wrapper2{
overflow: scroll;
}
.main_content {
float: left;
}
.main_text {
float: left;
}
.nav {
float: right;
padding-top: 10px;
width: 25%;
}
header {
border-bottom: 5px solid;
margin-bottom: 10px;
overflow: hidden;
}
header ul {
list-style-type: none;
margin-top: 20px;
display: inline;
}
header li {
float: right;
margin-right: 20px;
width: 110px;
}
header li:first-child {
margin-right: 0;
}
header li a {
display: block;
color: black;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
header li a:hover {
background-color: #111;
color: white;
}
header h1 {
float: left;
text-align: left;
margin: 0 170px .5em 0;
line-height: 0;
font-size: 2em;
}
h1 a {
text-decoration: none;
color: black;
}
/*drop-down menu styles begin*/
.dropbtn {
color: black;
padding: 13px;
font-size: 16px;
border: none;
cursor: pointer;
}
.dropdown {
display: inline-block;
float: right;
}
.dropdown-content {
display: none;
position: absolute;
}
.dropdown-content a {
color: white;
padding: 0 27.5px ;
text-decoration: none;
display: block;
background-color: #3f3f3f;
}
.dropdown-content a:hover {
color: #a9a9a9;
}
.dropdown:hover .dropdown-content {
display: block;
}
.dropdown:hover .dropbtn {
background-color: black;
color: white;
}
/*drop-down menu styles end*/
/*Right nav content starts here*/
.nav li {
list-style-type:none;
font-size: 1em;
}
.nav ul {
padding-left: 10%;
font-size: 1em;
}
.nav ul a:link {
text-decoration: none;
color: black;
font-size: 1em;
}
.nav ul a:visited {
text-decoration: none;
color: black;
font-size: 1em;
}
.nav ul a:hover {
text-decoration: none;
background-color: black;
color: white;
padding:3px;
font-size: 1em;
}
/*Right nav ends here*/
Add width: 75%; to .main_content. It's a div so it will, by default take up 100% of its parent container.
You have .main-text but your element doesnt have that class. It has an id of main-text. Also, it should have a width, and .main_content shouldn't be floated:
http://codepen.io/anon/pen/eZbrPd
Floats are messy. Consider using inline-block instead:
http://codepen.io/anon/pen/dMweQe
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.