I am working site built on the basic structure of the underscores WP theme. I have a submenu item with a long line of text. I want the text to automatically wrap if the line exceeds the width of the li. (The effect I want can be seen at youthconnectionwilmette.org under "programs")
Here is what I have now, at puckpros.edkatzman.com under "Schedule Lessons." The first submenu item is supposed to read "New Customers: Evaluation and Lesson - 50% Off" but it's getting truncated at "New Customers: Evaluation and"
My WP generated html is:
<nav class="site-navigation main-navigation" role="navigation">
<h1 class="assistive-text">Menu</h1>
<div class="assistive-text skip-link">
<ul id="menu-puckpros" class="menu">
<li id="menu-item-798" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-798">
<li id="menu-item-866" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-866">
Schedule Lessons
<ul class="sub-menu">
<li id="menu-item-924" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-924">
New Customer: Evaluation & Lesson – 50% OFF
</li>
</ul>
</li>
</li>
</ul>
</div>
</nav>
And the css I'm using is:
.main-navigation {
list-style-type: none;
margin: 0;
padding: 0;
height: 30px;
background-color: #00497e;
clear:both;
width: 100%;
}
.main-navigation li {
float: left;
height: 30px;
line-height: 30px;
display: block;
position:relative;
}
.main-navigation li a {
display:block;
color:#fde218;
text-decoration:none;
height: 30px;
line-height: 30px;
padding: 0 70px;
}
.main-navigation a:hover {
color: #004973;
background-color: #fde218;
}
.main-navigation ul ul li {
float: left;
width: 150px;
background-color:maroon;
top: 5px;
position:relative;
display:block;
}
.main-navigation ul ul li a {
background-color:#00497e;
color: #ffffff;
width: 200px;
display:block;
}
I've tried different value for display:, but have found nothing that makes any difference, except display: table-cell; which wraps the second submenu choice but splits the top one and puts part of it below the third menu item.
I must be missing something simple, but after a few hours of googling and trying any suggestions I found, nothing works. (I looked at the css of the site that works in Firebug, but I couldn't see where the line wrap is being made to happen.)
The key to making list-based menus:
1 - DO NOT STYLE THE LIST (other than display, position and float and clearing margins and padding)
2 - Use display:block and put ALL STYLING on the A-tag (this includes your hover and active states).
You are putting a height on everything. If you want two lines, you need the height to grow automatically.
Related
I have built this Vertical Menu with hidden submenus however I cannot get the submenu to display when the user hovers. How could I go about doing this? Also how can I get the text to be formatted all the way left, since they are lists I can get rid of the bullets, however I cannot get the text to go where the bullets used to be. Also, I am wondering what the best way would be to set the width of the "main-nav". I don't want anything to be over the text except the logo. The body of the site would be next to the navigation. I want the side of the logo to also line up with the left side of the text, and I cannot figure out how to do this. The red border is just for testing purposes (obviously).
Here is the link to my codepen.
[BONUS] I am trying to create my own site from scratch with wordpress and a custom theme. How does one create it so that the logo image is taken from the site identity tab in the customize sidebar? And also just display text if no logo is chosen in the identity bar. Would it be some wordpress php function? Also, I would want the logo to be apart of the main-navigation by default. I have the register_nav_menu() function in my functions.php file and it assigns a menu to Main Navigation, also giving it a class main-navigation. How could I get the logo to by default appear above this menu? Any tips on this would be greatly appreciated. (Wordpress/coding noob here)
HTML:
<div id="container">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/2/2f/Google_2015_logo.svg/2000px-Google_2015_logo.svg.png" class="logo-branding" />
<nav id="site-navigation" class="main-navigation">
<ul>
<li class="active">Overview</li>
<li>About</li>
<li>Submenu</li>
<ul class="sub-menu">
<li>Item 1</li>
<li>Item 2</li>
</ul>
<li>Contact</li>
</ul>
</nav>
CSS:
.main-navigation {
bottom: 2%;
margin-left: 4%;
display: block;
float: left;
border: 1px solid red;
position: fixed;
overflow: hidden;
width: 15%;
}
.main-navigation li, .main-navigation a {
list-style-type: none;
text-align: left;
text-decoration: none;
color: black;
text-transform: lowercase;
font: 16pt helvetica, sans serif;
padding: 1%;
}
.main-navigation a:hover, .main-navigation .active {
color: tan !important;
font-weight: bold !important;
}
.main-navigation .sub-menu {
display: none;
}
.main-navigation .sub-menu:hover {
display: block;
}
#container {
height: 10000px;
}
.logo-branding {
display: block;
position: fixed;
margin-top: 8%;
transform: rotate(90deg);
width: 15%;
}
JS:
/* No JS */
I believe that this is your desired behaviour?
To do this, you need to place your ul submenu inside the li for the menu item that is displayed. This is the only change I made to the HTML.
You can then add a CSS rule so that when you hover over the li, its ul child becomes visible. i.e: .main-navigation li:hover {display: block; }.
The reason it didn't work when you did .main-navigation .sub-menu:hover is because when it is not being displayed, you cannot hover over it, so the hover state is never triggered. In the rule which I added, it is triggered when you hover over the containing li.
.main-navigation {
bottom: 2%;
margin-left: 4%;
display: block;
float: left;
border: 1px solid red;
position: fixed;
overflow: hidden;
width: 15%;
}
.main-navigation li,
.main-navigation a {
list-style-type: none;
text-align: left;
text-decoration: none;
color: black;
text-transform: lowercase;
font: 16pt helvetica, sans serif;
padding: 1%;
}
.main-navigation a:hover,
.main-navigation .active {
color: tan !important;
font-weight: bold !important;
}
.main-navigation .sub-menu {
display: none;
}
.main-navigation li:hover ul {
display: block;
}
#container {
height: 10000px;
}
.logo-branding {
display: block;
position: fixed;
margin-top: 8%;
transform: rotate(90deg);
width: 15%;
}
<div id="container">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/2/2f/Google_2015_logo.svg/2000px-Google_2015_logo.svg.png" class="logo-branding" />
<nav id="site-navigation" class="main-navigation">
<ul>
<li class="active">Overview
</li>
<li>About
</li>
<li>Submenu v
<ul class="sub-menu">
<li>Item 1
</li>
<li>Item 2
</li>
</ul>
</li>
<li>Contact
</li>
</ul>
</nav>
EDIT: I may have made a mistake regarding WordPress, so I deleted that part of the answer so that I do not mislead anyone. E. Shio, however, found a link which explains it almost step by step. I'll summarise what this link says, just in case it someday gets deleted or the page url gets moved.
First, you check if there is a custom logo, for which you use has_custom_logo (). You then output that custom logo with the_custom_logo(). This is a relatively new feature to Wordpress though, so to maintain backwards compatibility, you should check if the function exists with function_exists( 'the_custom_logo' ). If there was no custom logo, you can output the text to display inside an else statement. Here's an example:
if( function_exists('the_custom_logo') ) {
if( has_custom_logo() ) {
the_custom_logo();
} else {
$blogname = get_bloginfo('name');
echo "<h1>$blogname</h1>";
}
}
If you have any questions about the CSS for the menu, I'm more than happy to help! (I'm no expert in Wordpress though, so I probably can't help with any Wordpress specific things, but I can try! XP)
I'm tearing my hair out here.
I have horizontal dropdown menu on a site I am building. The menu is made up of an unordered list, with the dropdown part made up of hidden child elements that pop up when you roll over the parents.
In Firefox everything appears to be fine, but, in Chrome and Safari, while the last child element in each menu is acting as expected, all other child elements are shunted left by one pixel. So, in the example below, Child A3, Child B4, and Child C2 are aligned perfectly with their respective parents, while the rest are not.
Can someone please shed some light on what is going wrong here?
Code and screenshots below...
How it should look...
How it actually looks...
I have included the entire nav block of the CSS just in case I have missed something outside of the actual parent/child part.
HTML
<nav>
<div id="menu" class="menustrip">
<ul>
<li class="page_item">
Parent A
<ul class='children'>
<li class="page_item">Child A1</li>
<li class="page_item">Child A2</li>
<li class="page_item">Child A3</li>
</ul>
</li>
<li class="page_item">Parent B
<ul class='children'>
<li class="page_item">Child B1</li>
<li class="page_item">Child B2</li>
<li class="page_item">Child B3</li>
<li class="page_item">Child B4</li>
</ul>
</li>
<li class="page_item">Parent C
<ul class='children'>
<li class="page_item">Child C1</li>
<li class="page_item">Child C2</li>
</ul>
</li>
</ul>
</div>
</nav>
CSS
#menu, #main-nav{
width: 950px;
margin: 0 30px 0 0;
padding-right: 30px;
border-bottom-style: solid;
border-bottom-width: 8px;
border-bottom-color: #78B2E2;
text-align: right;
}
ul#main-nav{
list-style: none;
padding-top: 10px;
margin-right:30px;
}
.page_item, .navlink{
display: inline-block;
background-color: #243488;
height: 34px;
width: 110px;
margin-left: 1px;
text-align: center;
}
.page_item a, .navlink a{
padding-top: 4px;
display: block;
height: 34px;
width: 110px;
}
.page_item:hover, .navlink:hover{
background-color: #78B2E2;
}
.page_item:active, .navlink:active{
background-color: #78B2E2;
}
/* Hide Sub Menus by default */
#menu ul li ul.children {
display:none;
z-index:100;
}
/* Display Sub Menus on rollover of parent */
#menu ul li:hover ul.children {
display:block;
position:absolute;
top:205px;
margin: 0 0 0 -11px; /*pull child menus in line with parent */
width: 132px;
list-style: none;
}
/* Style sub menu items not to float like parent items */
#menu ul li ul.children li {
float:none;
width:110px;
height: 34px;
background-color:#243488;
border-top: 3px solid #ffffff;
font-size: 11px;
}
#menu ul li ul.children li:hover {
background-color:#78B2E3;
color:#243488;
}
/* Sub Menu link color */
#menu ul li ul.children li a:hover {
color:#243488;
}
#menu ul li ul.children li a {
color:#ffffff;
}
Not sure what causes it exactly, but it has to do with the fact that the list items in <ul class="children"> are inline-blocks and the ul itself is centered.
So you have two solutions: either align the ul to the left instead of centering it
.children {text-align:left;}
or, make its list items blocks instead of inline blocks.
.children > li {display:block;}
Either of those adjustments will get rid of the display anomaly. In both cases, you will also have to increase the left margin, but I'm sure that won't be a problem.
Changing .children .page_item to display:block rather than display:inline-block seemed to fix it in my Chrome. This also required a bit more margin-left to re-align things.
.children .page_item {
display:block;
margin-left:10px;
}
I am doing a website for school, and it's been going well. The only problem I am stuck on is this: The navbar changes size on different sized screens. It's most readily apparent when zooming out, but it is slightly off on different screens.
Here is a screenshot of what I mean:
https://docs.google.com/a/g.ccsd.net/file/d/0B_Sda_-LouAKbnVKVHhMSW5yeXc/edit?usp=sharing
Please note that the left side, which is the problem, moves around a lot depending on the scale. The above image is only one example.
This is my CSS:
ul {
font-family: 'Open Sans', Times;
font-size: 14px;
margin: 0;
padding: 0;
list-style: none;
position: relative;
float: right;
z-index: 150;
/* min-width: 739px;
max-width: 739px; */
}
ul li {
display: block;
position: relative;
float: right;
}
li ul { display: none; }
ul li a {
display: block;
text-decoration: none;
color: #ffffff;
border-top: 7px solid #CC4D4D;
padding: 25px 26.45px 30px 26.45px; /*top right bottom left*/
background: #333333;
margin-left: 0px;
white-space: nowrap;
}
ul li a:hover { background: #757575; }
li:hover ul {
display: block;
position: absolute;
}
li:hover li {
float: none;
font-size: 11px;
}
li:hover a { background: #757575; }
li:hover li a:hover { background: #757575; }
This is my HTML:
<ul id="menu">
<li>Showcase</li>
<li>Contact</li>
<li>FAQ</li>
<li>Faculty
<ul>
<li>Mrs. Rosarita Olvina</li>
<li>Mrs. Christine Pavesich</li>
<li>Mr. Francisco Virella</li>
<li>Mrs. Susan Williams</li>
</ul>
</li>
<li>Program Areas
<ul>
<li>Graphic Design</li>
<li>Photography</li>
<li>Video Production</li>
<li>Animation</li>
<li>Art</li>
</ul>
</li>
<li>About
<ul>
<li>What We Do</li>
<li>Where We Go</li>
</ul>
</li>
<li>Home</li>
</ul>
Thank you for any help.
***I tried first answer, it didn't work, but I may be doing it very wrong.
The problem is not necessarily within the menu. Rather the whole menu (or its container) needs to be placed properly.
As far as I can tell from the code you've given, the floats may also play a part in fixing this. The whole menu and nested ULs are floating. My suggestion would be to avoid these floats and work with "display: inline-block" instead to get the horizontal arrangement.
After streamlining the menu entries like that, you can properly position your whole menu container in the surrounding HTML.
In case you don't already use it: Firebug or Chromebug plugins are really handy for identifying errors like this.
I'm having problems with my navigation bar, its not stretching across the page.
Here's the code:
#nav {
list-style: none;
font-weight: bold;
margin-bottom: 10px;
width: 100%;
text-align: center;
}
#nav ul {
list-style-type: none;
margin: 0px;
padding: 0;
}
#nav li {
margin: 0px;
display:
}
#nav li a {
padding: 10px;
text-decoration: none;
font-weight: bold;
color: #FFFFFF;
background-color: #000000;
float: left
}
#nav li a:hover {
color: #FFFFFF;
background-color: #35af3b;
}
<div id="nav">
<ul>
<li>Home
</li>
<li>Music
</li>
<li>Education
</li>
<li>Fun
</li>
<li>Entertainment
</li>
<li>Utilities
</li>
</ul>
</div>
It isn't exactly clear what you want here. If you're wanting the nav bar to continue across the page you need to add the background color to the parent div and make this div the same height as the ul list elements:
#nav {
list-style: none;
font-weight: bold;
margin-bottom: 10px;
width: 100%;
text-align: center;
background-color: #000000;
height:40px;
}
I did a fiddle - http://jsfiddle.net/F6nMg/
Put the background color on the container of the navigation bar (the div). Then, apply a clearfix to the div because the contents are floated. You could probably also use display: inline-block, but you don't have to.
#nav {
background-color: #000000;
}
#nav:after {
content: "";
clear: both;
display: table;
}
http://jsfiddle.net/ExplosionPIlls/DY6Nb/
I understand your problem. this can be achieved by putting display:table on parent div and display:table-cell on all lis in navbar.Then all will behave like teable-cells and take width according to provided space. Read my article at: http://www.aurigait.com/blog/how-to-make-navigation-bar-stretch-across-the-page/
Or Look at the below structure for example:
<nav class="main-menu">
<ul>
<li>Small Link</li>
<li>Another Link</li>
<li>One Another Link</li>
<li class="sp-width">A long link with 40% of total width</li>
</ul>
</nav>
And CSS
ul, li{ list-style:none; margin:0; padding:0;}/*1.1*/
.main-menu ul{background-color:black;} /*1.2*/
.main-menu a{color:white; display:block; padding:5px; text-decoration:none;} /*1.2, 1.3*/
.main-menu a:hover{background -color:#333333; text-decoration:none; color:white;}/*1.2*/
.main-menu > ul{ display:table; width:100%;} /*2.1, 2.2*/
.main-menu > ul > li{ display:table-cell; border-right:1px solid #d4d4d4;} /*3.1, 3.2 */
.main-menu > ul > li:last-child{ border-right:none;}/*3.2*/
.main-menu > ul > li > a{ text-align:center;}/*2*/
.sp-width{ width:40%;}
Now lets add 3 more links in it, so HTML Structure will now:
<nav class="main-menu">
<ul>
<li>Small Link</li>
<li>Another Link</li>
<li>One Another Link</li>
<li>Another Link</li>
<li>Another Link</li>
<li>Another Link</li>
<li class="sp-width">A long link with 40% of total width</li>
</ul>
</nav>
So CSS changes:
.main-menu > ul > li{ display:table-cell; border-right:1px solid #d4d4d4; width:10%;} /*4*/
.sp-width{ width:40%!important;} /*5*/
Points to be noted:
1.1. Global Definition
1.2. Global Definition for Main menu all uls and links. (In case of Sub-menu it will be applied on that sub-menu also)
1.3. Using display:block, so it will cover entire area of li and whole li will be click-able.
2.
2.1. I am using ‘>’(Direct Child) here so if we define any sub-menu inside, this CSS will not work on that.
2.2. ‘Width’ property is necessary with ‘display:table’. Because default width of display:table is ‘Auto’ means as per the inside content.
3.
3.1.Display:table-cell, divides the total width / remaining width(the un-divided width. In our case it is 100%-40%=60%) equally. It always need display:table on its parent container.
3.2. I am using border-right for showing links separately and removing extra border on last-child in the next line.
4. How width is distributed, if we define it explicitly:
4.1. If width is more than the average width(100% / No. of links) then it will give that width to first link and then from remaining if possible then to second link and then rest to other link and if no width left then to rest of the links as per content (with text wrapping as default) and remaining width in proportion as we provided. Example: we have 4 links and we define 50% width for each. So it will assign 3rd and 4th link as per the content and to 2nd and 1st link remaining width’s 50 %.
4.2. If width is less than the average width, it will distribute the width equally in all links.
4.3. If one link is having some specific width and we want all other links with a particular width (Our Case), It will provide the given width to that link(s) and then remaining width will be divided equally to all links including the specific width link.
5. We provide ‘!important’ here because of ‘order of precedence’. The hierarchical definitions have more weight than the class definitions. And ‘!important’ provides supreme power to class definition so it will be applied. I will discuss on Order of Precedence in my later blog.
Make sure in your HTML code, the list elements are under a separate container element, Assign background color to this new container.
For e.g.
.container-nav {
background: #ff3300;
}
<header class="container">
<h1> Monthly Resolutions </h1>
<h2 class=header-h> Dreaming out loud. Take 30 days at a time</h2>
</header>
<div class="container-nav">
<nav class="container">
<ul>
<li>Home
</li>
<li>Archives
</li>
<li>About Me
</li>
</ul>
<div class="clear"></div>
</nav>
<!--nav-->
</div>
<!--container-nav-->
Use this if you want the nav bar to always appear on the top of the screen (Just like stackoverflow's navbar ;)
#nav {
overflow: hidden;
display: flex;
flex-direction: row;
position: fixed !important;
left: 0 !important;
top: 0 !important;
width: 100%;
}
you should use
#nav {
width:100%;
}
Here is my code:
HTML
<div class="menu">
<ul>
<li class="active">HOME</li>
<li class="active">COMPANY</li>
<li class="active">SOLUTIONS</li>
<li class="active">SERVICES</li>
<li class="active">NEWS & EVENTS</li>
<li class="active">BLOGS</li>
<li class="active">CONTACTS</li>
</ul>
</div>
CSS
.header .menu ul { margin:33px 10px 0 0; padding:0; float:right; width:auto; height:12px; list-style:none;}
.header .menu ul li { margin:0 4px; float:left;}
It does not recognize the height feature. Why? How can I set the height of menu item?
You're missing a semicolon :-)
You can also try setting the line-height property of the li tags to change the position of the text in the element:
.line-height-li {
line-height: 30px;
}
Just increase the padding-top and padding-bottom as you want. Line height effect other. I found out it by testing it. It work for me.
.header .menu ul { margin:33px 10px 0 0; padding:0; float:right; width:auto;list-style:none;}
.header .menu ul li { margin:0 4px; float:left;}
.active{height:50px;}
ul is set to a height of 12 pixels, at least in Firefox.
Is the height set on the correct element? You're asking how to set the height of a menu item (presumably, an li) but your CSS says you're setting the height of the ul. Perhaps, moving height: 12px; from where it is to .header .menu ul li could help.
The height of the list does not necessarily change the height of the visible list items. I created a small example to show how those heights look like, if you hover on the items, you'll see the height's changing. That because of the overflow attribute of the list.
.menu ul {
margin: 10px 10px 10px 5px;
padding: 10px;
float: right;
width: auto;
height: 12px;
list-style: none;
background: cyan;
overflow: hidden;
}
.menu ul:hover {
overflow: visible;
}
.menu ul li {
margin: 4px;
padding: 4px;
float: left;
background: yellow;
}
<div class="menu">
<ul>
<li class="active">HOME</li>
<li class="active">COMPANY</li>
<li class="active">SOLUTIONS</li>
<li class="active">SERVICES</li>
<li class="active">NEWS & EVENTS</li>
<li class="active">BLOGS</li>
<li class="active">CONTACTS</li>
</ul>
</div>
Anyway, in your example, there's no div with a class "header" in your HTML, that's confusing for beginners. Your CSS rules begin with ".header".