Setting dropdown width longer than menu - html

I have been trying different things and still have been able to get exactly what I wanted. I want to create a menu. I want the menu to be about 20px wide and the dropdown to be 80-100px.
<div id="menulevel2grouping2">
<ul>
<li>T
<ul>
<li>Type 1</li>
<li>Type 2</li>
<li>Type 3</li>
<li>Type 4</li>
</ul>
</li>
<li>S
<ul>
<li>Small</li>
<li>Medium</li>
<li>Large</li>
</ul>
</li>
</ul>
</div>
#menulevel2grouping2{
margin: 0px;
padding: 0px;
}
#menulevel2grouping2 ul{
margin: 0px;
padding: 0px;
line-height: 30px;
}
#menulevel2grouping2 li{
margin: 0px;
padding: 0px;
list-style: none;
float: left;
position: relative;
}
#menulevel2grouping2 ul li a{
text-align: center;
font-family: Helvetica, Verdana Arial, sans-serif;
font-size: 12px;
background-color: blue;
width: 60px;
text-decoration: none;
display: block;
color: #000000;
}
#menulevel2grouping2 ul ul{
position: absolute;
display: none;
top: 30px
}
#menulevel2grouping2 ul li:hover ul{
display: block;
}
Any ideas on how I could get it done?
Thanks!
Drjay

Is this the effect you want? See fiddle here: http://jsfiddle.net/scTgZ/
I have revised your css. See the fiddle.

First of all, whenever possible you should provide a class or id to your elements to avoid complications. That's the purpose of CSS, to facilitate things, not to complicate them.
Anyway, something like this should work:
#menulevel2grouping2 ul li{width:20px; position:relative; z-index:10}
#menulevel2grouping2 ul li ul li{width:200px; position:relative; z-index:10}
you may not need the position and z-index (I'm not testing it) and you may need some float for the upper li, but this should be more than enough to give you an idea

Related

css aligning listed blocks

I am trying to make a navigation menu for a simple html/css site, it uses blocks and unorganized lists to add items to the navigation.
The problem is that I want my navigation to be centered, right now it floats from left to right, is there another way of aligning the listed div other than making it float right? I tried using left:20; but didn't work, here is the code.
As I say, just need that to center slightly to the right, I am making it float to the left so that it organizes the list properly, without it, it'd be a messy list, try it and you'll see what I mean... Thanks for help! :D
body {
font-family: Arial;
}
#nav { /*indexed so I can see it over a content div.*/
z-index:0;
}
ul {
margin: 0px;
padding: 0px;
list-style: none;
}
ul li {
float: left;
width: 8%;
height: 40px;
background-color: #000000;
opacity: 0.8;
line-height: 40px;
text-align: center;
font-size: 90%;
}
ul li a {
text-decoration: none;
color: white;
display: block;
}
ul li a:hover {
background-color: green;
}
ul li ul li{
display: none;
}
ul li:hover ul li {
display: block;
margin-left: 0%;
width: 100%;
background-color: #000000;
}
<div id="nav">
<ul>
<li>Attractions
<ul>
<li>Our Team</li>
<li>Camp Sites</li>
<li>Mission & Vision</li>
<li>Resources</li>
</ul>
</li>
<li>Plan Visit
<ul>
<li>Activities</li>
<li>Parks</li>
<li>Shops</li>
<li>Events</li>
</ul>
</li>
<li>Birthdays
<ul>
<li>Map</li>
<li>Directions</li>
</ul>
</li>
</ul>
</div>
This, I think, gives the nicest result:
#nav {
left:40%
position:relative;
}
When using float, be careful using it without a clearfix hack. A float could end up collapsing your entire site. Link for it here, also an explanation: https://www.w3schools.com/howto/howto_css_clearfix.asp

Center list in div (for navigation bar)

Going off of the note at the top of this tutorial (http://css-tricks.com/centering-list-items-horizontally-slightly-trickier-than-you-might-think/), I tried to center a list of two links in the page, but it is centering only the first list item, not the entire list.
li{
font-family: Futura, Arvo, sans-serif;
display: inline-block;
}
ul{
text-align: center;
}
div#nav-list {
left: 0;
right: 0;
margin-right: auto;
margin-left: auto;
width: auto;
height: auto;
background: #E8E8E8;
}
"nav-list" is the container for the navigation bar, shown in the picture colored grey.
Here is the issue- you can see that "about" is centered, but not the entire list.
Thanks in advance!
Edit: Here's the HTML:
<div id="center_content">
<h1 id="page-heading">Title</h1>
<hr id="first-rule"></hr>
<div id="nav-list">
<ul>
<li>about</li> <li>work</li>
</ul>
</div>
<hr></hr>
<p>Here is a paragraph. </p>
</div>
Remove the list padding. By default, list have a 40px padding-left. Try to use ul{ padding:0; }
Try apply these styles :
ul {
margin: 0 auto;
padding: 0;
text-align: center;
width: 170px; /*as per your need*/
}
Hows this for you: http://jsfiddle.net/theStudent/6UnNs/
CSS
li {
font-family: Futura, Arvo, sans-serif;
display: inline-block;
padding: 10px;
}
ul {
text-align: center;
background:red;
width: 25%;
margin:0 auto;
}
ul li:first-child {
background:#ccc;
display:block;
margin:0 0 0 -40px;
}
HTML
<ul>
<li>TITLE</li>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 2</li>
</ul>
Just play with settings I added some color so you can see
Here you go:
1) Set text-align: center; on the nav-list element
2) Set display: inline-block on the list
FIDDLE
li {
font-family: Futura, Arvo, sans-serif;
display:inline-block;
padding: 0 10px;
}
ul{
list-style: none;
display: inline-block;
padding:0;
}
div#nav-list {
text-align: center;
background: #E8E8E8;
}
try this
<div>
<ul>
<li>one</li>
<li>two</li>
<li>three</li>
</ul>
div ul li{float:left;list-style:none;margin:0 10px}
div ul{display: inline-block;margin: 0 auto;}
div{text-align:center}
JSFiddle

How to increase the font size of first two letters of any word/sentence?

I am trying to make the font size bigger for first two letters of nav links. I know for first letter it can be achieved using :first-letter. However I have tried it using span like below and it's increasing the font size but not getting aligned horizontally. About and Contact links are moving to top, both should be aligned with rest of the links (from bottom). I don't want to set line-height to the main container because the sub links are supposed to display below the main links. Any idea about this?
<li><span>01</span> Architectural Design</li>
CSS
ul li a span {
font-size: 25px;
}
.nav {
font-family: arial;
background: #dddddd;
overflow: hidden;
padding: 10px;
}
a {
color: #000;
text-decoration: none;
}
ul {
margin: 0;
padding: 0;
list-style: none;
}
li {
font-size: 12px;
float: left;
margin-right: 30px;
}
ul li a span {
font-size: 25px;
}
<div class="nav">
<ul>
<li>About</li>
<li><span>01</span> Architectural Design</li>
<li><span>02</span> Media</li>
<li><span>03</span> Developments</li>
<li>Contact</li>
</ul>
</div>
you may try this... old school but useful
<div class="nav">
<ul>
<li><span> </span>About</li>
<li><span>01</span> Architectural Design</li>
<li><span>02</span> Media</li>
<li><span>03</span> Developments</li>
<li><span> </span>Contact</li>
</ul>
</div>
If you add vertical-align:top to the span, it will align the words after the span to the top of the span
Fiddle
Other properties include
middle
bottom
baseline
I would set the line-height of the li elements.
li{
font-size:12px;
float:left;
margin-right:30px;
line-height: 25px;
}
JSFiddle
I know you mentioned that you
don't want to set line-height to the main container
but will this work for you?
It can only be used with the pseudo elements :before that make your code much cleaner and easy to read.
.empty:before {
content: "";
font-size: 25px;
}
.nav {
font-family: arial;
background: #dddddd;
overflow: hidden;
padding: 10px;
}
a {
color: #000;
text-decoration: none;
}
ul {
margin: 0;
padding: 0;
list-style: none;
}
li {
font-size: 12px;
float: left;
margin-right: 30px;
}
ul li a span {
font-size: 25px;
}
<div class="nav">
<ul>
<li><a class='empty' href="#">About</a></li>
<li><span>01</span> Architectural Design</li>
<li><span>02</span> Media</li>
<li><span>03</span> Developments</li>
<li><a class='empty' href="#">Contact</a></li>
</ul>
</div>

Pure CSS menu - submenu covering up other choices

I have a pure CSS menu (no javascript desired for this), with the HTML:
<ul id="nav">
<li>
<div>First Menu
</div>
<ul>
<li>First Option</li>
<li>Second Option</li>
<li id="subnav">Sub Menu —>>
<ul>
<li>First Sub Option</li>
<li>Second Sub Option</li>
<li>Third Sub Option</li>
<li>Fourth Sub Option</li>
</ul>
</li>
<li>Third Option
</li>
<li id="subnav">Second Sub Menu —>>
<ul>
<li>Second Sub Menu, First Sub Option</li>
<li>Second Sub Menu, Second Sub Option</li>
</ul>
<li>Fourth Option</li>
</li>
</ul>
</li>
<li>
<div>Second Menu
</div>
<ul>
<li>Next First Option</li>
<li>Next Second Option</li>
</ul>
</li>
</ul>
And the CSS:
#nav, #nav a {
text-decoration: none;
text-transform: uppercase;
color: #000;
padding: 0px 1px 0px 1px;
margin: 0px;
border: black thin solid;
text-decoration: none;
font-weight: bold;
font-style: italic;
font-size: 115%;
list-style-type: none;
font-family: sans-serif;
margin-left: none;
background-color: #EFAA0D;
z-index:100;
}
#nav>li {
float: left;
}
#nav li ul {
list-style-type: none;
display: none;
width:20em;
position: absolute;
left: 4px;
font-weight: normal;
}
#nav li>ul {
top: auto;
left: auto;
}
#nav li:hover>ul {
display: block;
}
#nav li a:hover {
background-color: #fdca2e;
}
#nav li a:link, #nav li a:visited {
padding: 0em .25em 0em 0.25em;
border: black thin solid;
text-decoration: none;
display: block;
left:2px;
}
#nav li>a {
font-weight: normal;
}
#subnav li a:link, #subnav li a:visited {
color: #EFAA0D;
padding: 0em .25em 0em 0.25em;
border: green thin solid;
display: block;
left:2px;
background-color: black;
}
#subnav li a:hover {
background-color: #555;
position: relative;
left: 1px;
}
Please see the fiddle: http://jsfiddle.net/sablefoste/wRK9v/7/
My concern is viewing the "Third Option" and beyond. When trying to access these options, it is covered by the sub-menu of the "Second Option". The only way to access is to skate the mouse over the padding.
Is there a way to fix this?
You have left the default padding for unordered list elements, which is what is indenting your menu. Padding is considered part of the element regarding the :hover state. You first want to zero out the padding for your UL elements, then add a margin [-left] of the amount you wish for it to indent. In this case, you would add (or I should say, merge):
#nav li ul {
padding: 0;
margin-left: 40px;
}
Demo: http://jsfiddle.net/wRK9v/8/
You have not overridden the default padding on the ULs, so in your Fiddle you can see how the menu is moved over to the left, but when you mouseover the area "outside" of the UL you are still technically moused over the third UL and it will not disappear.
If you override the default padding that space on the left will go away, but now all of your UL elements will be lined up and you still won't be able to view the rest of the menu.
#nav li > ul {
top: auto;
left: auto;
padding-left: 0;
}
If you then set the left positioning, you will be able to display the sub menus with as much or as little spacing as you want. You can apply this to all of the menus:
#nav li > ul {
top: auto;
left: 100px;
padding-left: 0;
}
Or specifically add it to the 3rd level menu:
#nav li #subnav > ul {
padding-left: 0px;
left: 150px;
}
Here's the Fiddle
I tend to want to solve everything in code, but a quick change is to increase the left-hand margin:
#nav li ul li ul
{
margin-left: 17.5em;
margin-top: -1.5em;
}
I'd assume you actually want the submenu to be just on the right of the second menu, right? I'd rework your indents to use hard pixels instead of ems. You are already specifying your width as 20em, so you can work with that and have your submenus show up to the right of the main menu.
The fiddle: http://jsfiddle.net/wRK9v/12/

submenu items won't line up with parent item

I am trying to create a drop down menu, however whenever I hover over a parent menu the child menu won't line up with it. I have gone through many examples and I always get the same result.
My CSS code is
#mainNav {
margin-top: 20px;
width: 800px;
margin-left: auto;
margin-right: auto;
padding: 0;
overflow: hidden;
background-color: #BBFFFF;
zoom: 1;
}
#mainNav li {
float: left;
list-style: none;
}
#mainNav li a {
color: #000000;
display: block;
width: 80px;
font-size: 14px;
text-align: center;
text-transform: uppercase;
text-decoration: none;
padding: 7px 0px 7px 0px;
border-right: 1px solid #999;
zoom: 1;
}
#mainNav li ul {
display: none;
}
#mainNav a:hover {
background-color: #66FF66;
}
#mainNav li:hover ul {
display: block;
position: absolute;
}
#mainNav li:hover li {
float: left;
width: 80px;
background-color: #BBFFFF;
margin: 0;
padding: 0;
}
My HTML is
<div>
<ul id="mainNav">
<li>Page One</li>
<li>Page Two</li>
<li>Page Three
<ul>
<li><a href="threePageOne.html" name="threePageOneLink>Sub Page One</a></li>
</ul>
</li>
</ul>
</div>
You could use a negative margin-left to pull it back in line. Add it to:
#mainNav li:hover ul {}
Or you can set padding: 0; on the same element.
Also, you are missing a closing '"' in:
<li><a href="threePageOne.html" name="threePageOneLink>Sub Page One</a></li>
Copy paste and try this. Something from this example will help you.
<html>
<head>
<style type="text/css">
#mainNav{
/* Your mainNav decoration here */
}
#mainNav li{
list-style:none;
display:inline-block;
background-color:#0FF;
padding:10px;
border:1px solid #000;
}
#mainNav ul{
position:absolute;
display:none;
padding:0px;
top:50px;
}
#mainNav li:hover ul{
display:inline-block;
}
</style>
</head>
<body>
<ul id="mainNav">
<li>Page One
<br />
<ul>
<li>Sub Page One</li>
</ul>
</li>
<li>Page Two</li>
<li>Page Three
<br />
<ul>
<li>Sub Page One</li>
</ul>
</li>
</ul>
</body>
</html>
There is a lot of css in there that is not specific enough and some stuff that is just in the wrong place.
I have written out a jsfiddle for you here: A DISTILED VERSION OF YOUR CODE
You have list style on li instead of ul where it belongs. You are also not specific enough about the sub lists and so one. Using > like,
.main-nav > li > a { } will say target the first layer of li only, and in that, the only a in that li etc.
I would give the ul's classes etc. See the fiddle for what I think is the most simple approach. For the other people, please let me know if my fiddle could be more concise.