I am trying to create a vertical drop-down menu but i am failing to align drop-down content properly. I is appearing as if indented, which i don't want.
Drop-down Text should be vertically aligned
#sidenav{
margin-top:25%;
margin-left:25%;
width:250px;
max-width:250px;
background:#454545;
}
#sidenav input {
box-sizing: inherit;
width:100%;
padding:5px;
margin-top: 5px;
border:none;
border-bottom: 2px solid #666666;
background: transparent;
color:white;
font-size: 18px;
font-style: italic;
opacity: 0.8;
}
#sidenav li{
list-style:none;
font-size: 18px;
width:inherit;
padding:5px 0px 5px 5px;
position: relative;
color:#ffffff;
}
#sidenav li::first-letter,#sidenav a::first-letter{
text-transform: uppercase;
}
#sidenav a{
text-decoration: none;
display: block;
color:#ffffff;
margin:0px;
}
.dropdown-content{
background:#666666;
display: none;
}
.dropdown-bt:hover .dropdown-content{
display: block;
}
<section id='sidenav'>
<input type="text"placeholder="search..."id='mysearch'onkeyup="filterSearch()">
<li>item 1</li>
<li>item 2</li>
<li class="dropdown-bt">dropdown - content
<ul class="dropdown-content">
<li>test 1</li>
<li>test 2</li>
<li>test 3</li>
<li>test 4</li>
</ul>
</li>
<li>item 3</li>
<li>item 4</li>
</section>
Drop-down content is giving some kind of margin on its left
which i don't want.
If I understood you correctly, remove the padding from unordered list:
ul {
padding:0;
}
In your case:
.dropdown-content{
background:#666666;
display: none;
padding:0;
}
There is a 5px padding from its parent (#sidenav li) so you will need to compensate somehow, one way is to do margin-left: -5px in the child (.dropdown-content)
#sidenav{
margin-top:25%;
margin-left:25%;
width:250px;
max-width:250px;
background:#454545;
}
#sidenav input {
box-sizing: inherit;
width:100%;
padding:5px;
margin-top: 5px;
border:none;
border-bottom: 2px solid #666666;
background: transparent;
color:white;
font-size: 18px;
font-style: italic;
opacity: 0.8;
}
#sidenav li{
list-style:none;
font-size: 18px;
width:inherit;
padding:5px 0px 5px 5px;
position: relative;
color:#ffffff;
}
#sidenav li::first-letter,#sidenav a::first-letter{
text-transform: uppercase;
}
#sidenav a{
text-decoration: none;
display: block;
color:#ffffff;
margin:0px;
}
.dropdown-content{
background:#666666;
display: none;
margin-left:-5px; /*compensate to the 5px padding from its parent*/
padding: 0; /*optional if you don't want padding inside*/
}
.dropdown-bt:hover .dropdown-content{
display: block;
}
<section id='sidenav'>
<input type="text"placeholder="search..."id='mysearch'onkeyup="filterSearch()">
<li>item 1</li>
<li>item 2</li>
<li class="dropdown-bt">dropdown - content
<ul class="dropdown-content">
<li>test 1</li>
<li>test 2</li>
<li>test 3</li>
<li>test 4</li>
</ul>
</li>
<li>item 3</li>
<li>item 4</li>
</section>
You never declared the unordered list for your top level list and the padding on your input field (search) was causing the field to be wider than the max width that you set in you container. To adjust for this padding I modified how the padding was being applied (top and bottom padding has 5px and left and right have 0).
#sidenav{
margin-top:25%;
margin-left:25%;
width:250px;
max-width:250px;
background:#454545;
}
#sidenav input {
box-sizing: inherit;
width:100%;
padding:5px 0px;
margin-top: 5px;
border:none;
border-bottom: 2px solid #666666;
background: transparent;
color:white;
font-size: 18px;
font-style: italic;
opacity: 0.8;
}
#sidenav li{
list-style:none;
font-size: 18px;
width:inherit;
padding:5px 0px 5px 5px;
position: relative;
color:#ffffff;
}
#sidenav li::first-letter,#sidenav a::first-letter{
text-transform: uppercase;
}
#sidenav a{
text-decoration: none;
display: block;
color:#ffffff;
margin:0px;
}
.dropdown-content{
background:#666666;
display: none;
}
.dropdown-bt:hover .dropdown-content{
display: block;
}
<section id='sidenav'>
<input type="text"placeholder="search..."id='mysearch'onkeyup="filterSearch()">
<ul>
<li>item 1</li>
<li>item 2</li>
<li class="dropdown-bt">dropdown - content
<ul class="dropdown-content">
<li>test 1</li>
<li>test 2</li>
<li>test 3</li>
<li>test 4</li>
</ul>
</li>
<li>item 3</li>
<li>item 4</li>
</ul>
</section>
Related
I am new to css
I am trying to develop a navigation bar for website it works fine when it is in full screen, but when i decrease the size of window few elements came down but the background colour remain intact to first row only.
Here's the code
.navbar {
background-color: rgb(11, 29, 66);
height: 60px;
border-radius: 0px;
}
.navbar ul {
margin: 0px;
padding: 0px;
overflow: auto;
}
.navbar li {
float: left;
list-style: none;
margin: 10px 10px;
border-right: 2px solid gold;
}
.navbar li a {
text-decoration: none;
color: khaki;
padding-right: 0.5cm;
font-family: 'Big Shoulders Stencil Display', cursive;
font-size: 28px;
}
<nav class="navbar">
<ul>
<li>
<img src="favicon-32x32.png" alt="Home">
</li>
<li>Element 1</li>
<li>Element 2</li>
<li>Element 3</li>
<li>Element 4</li>
<li>Element 5</li>
</ul>
</nav>
It's your height property on the navbar. I removed it, run the snippet below:
.navbar {
background-color: rgb(11, 29, 66);
border-radius: 0px;
}
.navbar ul {
margin: 0px;
padding: 0px;
overflow: auto;
}
.navbar li {
float: left;
list-style: none;
margin: 10px 10px;
border-right: 2px solid gold;
}
.navbar li a {
text-decoration: none;
color: khaki;
padding-right: 0.5cm;
font-family: 'Big Shoulders Stencil Display', cursive;
font-size: 28px;
}
<nav class="navbar">
<ul>
<li>
<img src="favicon-32x32.png" alt="Home">
</li>
<li>Element 1</li>
<li>Element 2</li>
<li>Element 3</li>
<li>Element 4</li>
<li>Element 5</li>
</ul>
</nav>
You can add the background color to your .navbar ul
like this :
.navbar ul {
margin: 0px;
padding: 0px;
overflow: auto;
background-color: blue;
}
Created a navigation menu with one drop menu. For some reason I am unable to get the correct CSS dropping the menu on "Main 3." Would someone mind looking at my CSS to see if there is something I may have missed.
HTML
<ul class="navmenu">
<li>Main 1</li>
<li>Main 2</li>
<li>
Main 3
<ul>
<li>Sub 1</li>
<li>Sub 2 </li>
<li>Sub 3</li>
<li>Sub 4</li>
</ul>
</li>
<li>Main 4</li>
<li>Main 5</li>
<li>Main 6</li>
<li>Main 7</li>
</ul>
CSS
.navmenu{
background: #510E2A;
height: 35px;
margin: 0;
padding: 0;
list-style-type: none;
overflow: hidden;
text-align: justify;
}
.navmenu li{
float: left;
}
.navmenu li a{
display: block;
padding:9px 20px;
text-decoration: none;
font-family: THCFontSemiBold;
color: #f3ac3f;
font-weight: bold;
}
.navmenu ul{
list-style-type: none;
position: absolute;
z-index: 1000;
left: -9999em;
}
.navmenu li:hover{
position: relative;
}
.navmenu li:hover ul {
left:0px;
top:30px;
background:#5FD367;
padding:0px;
}
.navmenu li:hover ul li a {
padding:5px;
display:block;
width:168px;
text-indent:15px;
background-color:red;
}
.navmenu li:hover ul li a:hover { background:#005555; }
Fiddle is here
Just remove overflow from navmenu
.navmenu{
background: #510E2A;
height: 35px;
margin: 0;
padding: 0;
list-style-type: none;
text-align: justify;
}
Updated Fiddle
I'm trying to create a navigation menu similar to the picture attached but I'm having trouble with the CSS. I have a basic nested unordered list but I can't figure out how to styles it to look as close as possible to the specifications. Any help/links would be appreciated.
nav {
border-bottom:1px solid #ccc;
}
nav ul {
list-style:none;
padding:0.35em;
margin:0 0.5em;
}
nav li {
border-right:1px solid black;
display:inline-block;
padding:0.15em 0.25em;
position:relative;
}
nav li:first-child {
border-left:1px solid black;
}
nav ul ul {
background:white;
border:1px solid #ccc;
box-shadow:2px 2px 4px rgba(0,0,0,0.5);
display:none;
left:-0.25em;
min-width:200px;
padding:0.5em;
position:absolute;
top:1.5em;
}
nav li:hover {
font-weight:bold;
}
nav li:hover ul {
font-weight:normal;
}
nav li:hover ul {
display:block;
}
nav li li {
border:none !important;
display:block;
margin:0;
padding:0;
white-space:nowrap;
}
<nav>
<ul>
<li>Item 1
<ul>
<li>Subitem 1</li>
<li>Subitem 2</li>
<li>Subitem 3</li>
</ul>
</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
<li>Item 5</li>
<li>Item 6</li>
</ul>
</nav>
I have a drop down menu where I want some of the list items to be in one line.
See demo
You will notice that under Tab One, there are 9 rows. I want there to be three rows with three items in each row. How can this be done in CSS?
HTML:
<div id="wrapper">
<ul id="menu">
<li>Tab One
<ul style="width: 300%;">
<li>Column one</li>
<li>Column one</li>
<li>Column one</li>
<li>Column two</li>
<li>Column two</li>
<li>Column two</li>
<li>Column three</li>
<li>Column three</li>
<li>Column three</li>
</ul>
</li>
<li>Tab Two
<ul style="position: relative; left: -100%; width: 300%">
<li>Tab 2</li>
<li>Tab 2</li>
<li>Tab 2</li>
</ul>
</li>
<li>Tab Three
<ul style="position: relative; left: -200%; width: 300%">
<li>Tab 3</li>
<li>Tab 3</li>
<li>Tab 3</li>
</ul>
</li>
</ul>
</div>
CSS:
body {
font-family: arial;
margin: 0px;
padding-left: 40px;
padding-right: 40px;
}
#wrapper {
text-align: center;
height: auto;
margin: auto;
min-width: 500px;
}
#wrap {
display: inline;
}
ul {
font-family: Arial, Verdana;
font-size: 14px;
margin: 0;
padding: 0;
list-style: none;
}
#menu > li {
display: block;
position: relative;
float: left;
width: 33.3%;
}
li ul {
display: none;
}
ul li a {
display: block;
text-decoration: none;
color: #ffffff;
border-top: 1px solid #ffffff;
padding: 5px 15px 5px 15px;
background: #1e7c9a;
margin-left: 1px;
white-space: nowrap;
}
ul li a:hover {
background: #3b3b3b;
}
li:hover ul {
display: block;
position: absolute;
}
li:hover li {
float: none;
font-size: 14px;
}
li:hover a {
background: #3b3b3b;
}
li:hover li a:hover {
background-color: black;
opacity: .7;
}
Working example: http://jsfiddle.net/w7a3N/5/
Remove > from #menu > li { and set inner <li> to <li style="width: 33%;">
Not sure if the style="width:33%;" is absolutely necessary since it works in Firefox 20 without it, but just to be safe.
UPDATE
You asked for a version that only does multiple columns under the first tab. Here you go:
http://jsfiddle.net/w7a3N/6/
Gave First tab an id like so <ul id="tab1" and then added this to CSS:
#tab1 li{
display: block;
position: relative;
float: left;
width: 33%;
}
I have a ul with a title in a div and I'm trying to make the ul scroll while keeping the title fixed. I also want to have the title match the width of the ul. I'm able to do one of those at a time, but not both together. Either I get a ul with a title that is 100% of the ul width, or I get a title that stays put when the list scrolls, but it doesn't match the ul width. Can someone point out what I'm doing wrong?
fiddle here: http://jsfiddle.net/9zcRy/2/
The HTML
<div class="talkingPointsHolder">
<div class="genericScriptsHolder">
<span class="listHeader">List One</span>
<ul
class="scrollingList">
<li>item 1.1</li>
<li>item 1.2</li>
<li>item 1.3</li>
<li>item 1.4</li>
<li>item 1.5</li>
<li>item 1.6</li>
<li>item 1.7</li>
<li>item 1.8</li>
<li>item 1.9</li>
<li>item 1.10</li>
<li>item 1.11</li>
<li>item 1.12</li>
</ul>
</div>
<div class="genericScriptsHolder">
<span class="listHeader">List Two</span>
<ul
class="scrollingList">
<li>item 2.1</li>
<li>item 2.2</li>
<li>item 2.3</li>
<li>item 2.4</li>
<li>item 2.5</li>
<li>item 2.6</li>
<li>item 2.7</li>
<li>item 2.8</li>
<li>item 2.9</li>
<li>item 2.10</li>
<li>item 2.11</li>
<li>item 2.12</li>
</ul>
</div>
The CSS
.talkingPointsHolder {
border: 1px solid black;
background: #eeeeee;
height: 200px;
overflow: auto;
}
.genericScriptsHolder {
float: left;
width: 48%;
margin: 0px 2px 0px 2px;
/* uncomment to make the title match the ul width (see listHeader too)*/
/*position: relative;*/
}
.listHeader {
color: #ffffff;
background: #444444;
padding: 10px 0px 10px 0px;
text-transform: uppercase;
font-weight:bold;
font-size:11px;
text-align: left;
text-indent: 1em;
position: absolute;
z-index:10;
/* uncomment to make the title match the ul width (see genericScriptsHolder too)*/
/*width: 100%;*/
}
.scrollingList {
position: relative;
top: 31px;
}
.scrollingList li {
overflow: auto;
height: 20px;
color: #666666;
background-color: #cccccc;
font-weight: lighter;
padding: 10px;
margin: 2px;
list-style-type: none;
}
You need to define the width of an element if you're using position: absolute;
I set the width your .list-header to match the width of your .genericScriptsHolder and then adjusted the padding accordingly.
Here's the fiddle: http://jsfiddle.net/9zcRy/15/
Notice that I removed the horizontal margins that you created for the scrolling list line items and instead edited the styling on the parent .genericScriptsHolder element.
.genericScriptsHolder {
float: left;
width: 48%;
margin: 0px 5px 0px 5px;
/* uncomment to make the title match the ul width (see listHeader too)*/
/*position: relative;*/
}
.listHeader {
color: #ffffff;
background: #444444;
padding: 10px 0px 10px 0px;
text-transform: uppercase;
font-weight:bold;
font-size:11px;
text-align: left;
text-indent: 1em;
position: absolute;
width: 48%;
z-index:10;
.scrollingList li {
overflow: auto;
height: 20px;
color: #666666;
background-color: #cccccc;
font-weight: lighter;
padding: 10px;
margin: 2px 0 0 0;
list-style-type: none;
}
http://jsfiddle.net/9zcRy/9/
.listHeader {
color: #ffffff;
background: #444444;
padding: 10px 0px 10px 0px;
text-transform: uppercase;
font-weight:bold;
font-size:11px;
text-align: left;
text-indent: 1em;
position: absolute;
z-index:10;
width:46%;