How to vertically center Wordpress navigation bar - php

I have a navigation bar at following wordpress site: http://tarjom.ir/demo/pwp
I have two major issues with this navigation bar:
1- I can't vertically align it at the middle.
2- There is a div wrapper as the parent of the <ul> tag that I can't remove it. However I have already set 'container' => '', but it does not work.
<!-- Navigation bar-->
<div id='wp_nav_section' class='grid-100 black-gray-bg font-roya' style='min-height: 100px; display: block;height:100%;'>
<?php wp_nav_menu(array("container" => 'nav')); ?>
</div>
<!-- End of navigation bar. -->
Here is my wordpress navigation code:
Here is all my CSS related to the wordpress navigation:
.menu
{
height: 65px;
min-height: 60px;
padding: 0px;
text-align: right;
background-color: #111;
margin-bottom: 10px;
}
.menu ul
{
direction: rtl;
width: 70%;
margin-right: auto;
margin-left: auto;
overflow: hidden;
height: auto;
padding-top: 0px;
}
.menu li
{
padding: 0px 0px;
display: inline-block;
}
.menu li a
{
color: white;
text-decoration: none;
display: block ;
height: 45px;
background-color: black;
border-right: 2px #333 solid;
padding: 16px 7% 3px 3%;
box-sizing: border-box;
width: 100px;
margin: 0px 0px;
font-size: 110%;
}
.menu li a:hover
{
background-color: #333;
border-right: 2px #F90 solid;
}
I need the <ul> tag to be centered vertically in the <div> wrapper.
Thanks in advanced.

Remove height from .menu{} class. this will solved your vertical align issue.

I would try this, if you haven't already:
<?php wp_nav_menu(
array (
'container' =>false,
'items_wrap' => '%3$s', //"%3$s" is the li list itself. See below for the default value.
) ); ?>
The default values for these two parameters are:
'container' => 'div',
'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>',
So I would make sure to define those the way you want them in your call to wp_nav_menu().
You can read more info on my post at http://icode4you.net/wordpress-tricks-customizing-the-output-of-wp_nav_menu/
To center the UL within a div, I would use this code:
<style>
div {
text-align:center;
}
ul {
display:inline-block;
}
</style>
Let me know if you would like any more information or help :)

Related

wordpress wp nav menu() do not have style

I can't style my WordPress function correctly, and the sub-menu and menu are displayed together and on top of each other. I want to separate these two, what should I do? My codes are as follows:
i do not know about html vs css code please help me or if you have any details about nav menu in wordpress template so please Guide me
<?php wp_nav_menu( array( 'theme_location' => 'primary_menu', 'container' =>'', 'menu_class' =>'meno' ) ); ?>
<style>
.meno{
list-style-type: none;
padding-right:20px;
width:800px;
}
.meno li{
display: inline-block;
margin-left:50px;
border-radius: 5px 5px 5px 5px;
background-color: #fff;
padding:-3px ;
}
.meno li a {
display: block;
padding: 0;
text-decoration: none;
/* this is the width of the menu items */
line-height: 35px;
/* this is the hieght of the menu items */
/* list item font color */
text-align: center;
}
.meno li li a {
font-size: 80%;
width: 200px;
transition: all 0.2s;
}
.meno li:hover {
background: #e0d5d5;
border-radius: 5px 5px 5px 5px;
transition: all 0.4s;
box-shadow: 0 0.125rem 0.125rem -0.125rem rgba(31, 27, 45, 0.08), 0 0.25rem 0.75rem rgba(31, 27, 45, 0.08);
}
.meno ul {
padding: 0;
left: 0;
/* hides sublists */
width: 100px;
height: 100px;
transition: all 0.4s;
position: absolute;
display: none;
}
.meno li:hover ul ul {
display: none;
background: #493131;
transition: all 0.4s;
}
.meno li:hover ul {
position: relative;
display:block;
width: 200px;
height: auto;
}
/* shows sublist on hover */
.meno li li:hover ul {
display: block;
/* shows sub-sublist on hover */
margin-left: 200px;
/* this should be the same width as the parent list item */
margin-top: -35px;
/* aligns top of sub menu with top of list item */
background: #8a7c7c;
}
</style>

Why is the text in my menu shifted to the right?

I'm currently setting up a sidebar menu for my Wordpress website. I'm running into 2 issues. The 1st one is that the text in the menu isn't lining up to the left side properly. I have tried to use the text-align attribute but it doesn't work.
The 2nd problem is that there is a bit of random space at the bottom of the menu that I don't know why is there.
Problem is happening here: http://dreamedbig.com/our-services/
My HTML/PHP:
<div class="page-content">
<div id="services-menu" class="services-sidebar">
<?php dynamic_sidebar('services'); ?>
</div>
</div>
The CSS:
#services-menu {
border: 1px solid black;
align-items: left;
float:left;
height: auto;
display: inline-block;
top:0;
left:0;
background-color: #BCE6FB;
}
#services-menu li{
list-style-type:none;
border-bottom: 1px solid black;
}
#services-menu a {
text-decoration: none;
color: #08203D;
}
#services-menu ul {
}
#services-menu ul li a {
position: relative;
display: block;
box-sizing: border-box;
z-index: 1;
margin: 5px;
padding-left: 5px;
padding-right: 5px;
}
#services-menu ul li a::after
{
content: "";
position: absolute;
top:0;
left: 0;
background-color: #00A2DA;
width: 0%;
height: 100%;
transition: all 1s;
z-index: -1;
}
#services-menu ul li a:hover::after
{
width: 100%;
}
#services-menu ul li:nth-child(odd) a::after
{
background-color: #00A2DA;
}
#services-menu ul li:nth-child(even) a::after
{
background-color: #FFFFFF;
}
It looks like you have some inherited styles from classes called .widget and there is margin and padding added to ul. This is common is your using something like WordPress or underscores that come with some stylesheets.
I think these styles will correct it
.widget, #services-menu ul{
margin:0;
padding:0;
}
I found the unwanted margin and padding by using inspect in my chrome browser. I highly recommend it for frontend styling because it makes troubleshooting these kinds of issue easier to resolve.
Here is an article to better explain how it works

Bootstrap dropdown menu broken for pages in folder while working for pages in root. Both groups php_include the same external header file

I run some of the web stuff at work on the side, not exceptionally experienced at this stuff. I don't know what element of the process I've gone through has caused the hiccup so if you bear with me, I'll try and explain in-depth.
Recently our site (basic bootstrap template) has begun expand out from just a few pages, and to stay on top of things I opted to pull the header and footer files out into their own includes folder, and use...
<!--Header include-->
<?php $path = $_SERVER['DOCUMENT_ROOT'] . "/includes/"; include ( $path . 'header.html' ); ?>
...for easier management. Went through the site and stripped out old code and changed page extensions to php (and now began testing site on MAMP).The structure of the site is 75% of pages living in root, 25% living in a folder called services. All pages pull the same header.html So far so good.
The problem arrises when I test the site. All pages that live in root (public_html) work as expected, the nav drop down menu contained in the header works fine. But when you click into any of the pages that live in /services/ the dropdown (and only the dropdown), breaks. By breaks, I mean that a dropdown should appear on mouse hover over and it doesn't. All of the other CSS, the theme, the code for a picture slider, works ok. It's just this one element of the nav bar that breaks for these pages that live in the /services/ folder.
I compared the elements of a working page and a broken page by inspecting them firefox, and this is the only place I can see any differences..
On a working page, the working dropdown html shows as...
ul class="dropdown-menu bold" style="display:none;"
With CSS rules of...
element {
display: none;
}
.navbar .nav li .dropdown-menu {
z-index: 1000;
}
header ul.nav li ul {
z-index: 1000;
margin-top: 20px;
}
.bold {
font-weight: 900;
}
.dropdown-menu {
position: absolute;
top: 100%;
left: 0px;
z-index: 1000;
display: none;
float: left;
min-width: 180px;
padding: 0px;
margin: 2px 0px 0px;
list-style: outside none none;
background: none repeat scroll 0% 0% #343434;
box-shadow: none;
border-right: 2px solid #302F2F;
border-width: medium 2px 2px;
border-style: none solid solid;
border-color: -moz-use-text-color #302F2F #302F2F;
-moz-border-top-colors: none;
-moz-border-right-colors: none;
-moz-border-bottom-colors: none;
-moz-border-left-colors: none;
border-image: none;
}
.dropdown-menu {
border-radius: 0px;
}
.dropdown-menu {
position: absolute;
top: 100%;
left: 0px;
z-index: 1000;
display: none;
float: left;
min-width: 160px;
padding: 5px 0px;
margin: 2px 0px 0px;
list-style: outside none none;
background-color: #FFF;
border: 1px solid rgba(0, 0, 0, 0.2);
border-radius: 6px;
box-shadow: 0px 5px 10px rgba(0, 0, 0, 0.2);
background-clip: padding-box;
}
ul ul, ul ol, ol ol, ol ul {
margin-bottom: 0px;
}
ul ul, ul ol, ol ol, ol ul {
margin-bottom: 0px;
}
ul, ol {
padding: 0px;
margin: 0px 0px 10px 25px;
}
ul, ol {
padding: 0px;
margin: 0px 0px 10px 25px;
}
li {
line-height: 1.6em;
}
li {
line-height: 20px;
}
.nav {
list-style: outside none none;
}
body {
font-family: "Open Sans",sans-serif;
font-size: 14px;
font-weight: 400;
line-height: 1.6em;
color: #656565;
}
body {
font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
font-size: 14px;
line-height: 20px;
color: #333;
}
html {
font-size: 100%;
}
The broken page(s) shows html of...
<ul class="dropdown-menu"></ul> <<< I think this might be a red flag??
and CSS of....
element {
}
.navbar .nav li .dropdown-menu {
z-index: 1000;
}
header ul.nav li ul {
z-index: 1000;
margin-top: 20px;
}
.dropdown-menu {
position: absolute;
top: 100%;
left: 0px;
z-index: 1000;
display: none;
float: left;
min-width: 180px;
padding: 0px;
margin: 2px 0px 0px;
list-style: outside none none;
background: none repeat scroll 0% 0% #343434;
box-shadow: none;
border-right: 2px solid #302F2F;
border-width: medium 2px 2px;
border-style: none solid solid;
border-color: -moz-use-text-color #302F2F #302F2F;
-moz-border-top-colors: none;
-moz-border-right-colors: none;
-moz-border-bottom-colors: none;
-moz-border-left-colors: none;
border-image: none;
}
.dropdown-menu {
border-radius: 0px;
}
.dropdown-menu {
position: absolute;
top: 100%;
left: 0px;
z-index: 1000;
display: none;
float: left;
min-width: 160px;
padding: 5px 0px;
margin: 2px 0px 0px;
list-style: outside none none;
background-color: #FFF;
border: 1px solid rgba(0, 0, 0, 0.2);
border-radius: 6px;
box-shadow: 0px 5px 10px rgba(0, 0, 0, 0.2);
background-clip: padding-box;
}
ul ul, ul ol, ol ol, ol ul {
margin-bottom: 0px;
}
ul ul, ul ol, ol ol, ol ul {
margin-bottom: 0px;
}
ul, ol {
padding: 0px;
margin: 0px 0px 10px 25px;
}
ul, ol {
padding: 0px;
margin: 0px 0px 10px 25px;
}
li {
line-height: 1.6em;
}
li {
line-height: 20px;
}
.nav {
list-style: outside none none;
}
body {
font-family: "Open Sans",sans-serif;
font-size: 14px;
font-weight: 400;
line-height: 1.6em;
color: #656565;
}
body {
font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
font-size: 14px;
line-height: 20px;
color: #333;
}
html {
font-size: 100%;
}
(I can manually change the broken dropdown in firefox inspect to element { display:inline } and the dropdown reappears, with working links to the other pages.)
Overall, I can't understand why this is happening.
All of the other CSS is working on the broken pages, so the links to that location must work.
All pages share the same header.html which uses the same html to create the working dropdowns.
All CSS is called individually at the start of each page in the head (not in the header.html file).
If all pages look at the same header file, and they all point to the same CSS, how am I getting different results?
Thanks,
Found the answer to this a while ago and I figured I'd update. The javascript that animates the nav bar was written out and contained in the footer with relative links to the js folder, which hadn't been updated when the pages were moved into the services folder. So the animations would fail because the javascript files couldn't be located.
Fixed this by making the footer as its own file in an includes folder with explicit links to the js folder from there, then used a php document root include (same as the code above) to bring it into the other pages.

CSS editing two nav bars (Adelle theme)

I added second nav menu (nav2), however it adopts the look of first (nav1) menu and I cannot fix it. On the other hand its content is different.
piece of header.php:
<nav class="nav" role="navigation">
<?php wp_nav_menu( array( 'theme_location' => 'extra_menu&container_class=menu&fallback_cb=false&show_home=1' ) ); ?>
</nav><!-- .nav -->
<nav2 class="nav" role="navigation">
<?php wp_nav_menu( array( 'theme_location' => 'top_menu', 'menu' => 'nav2')); ?>
<form role="search" method="get" class="header-form" action="<?php echo esc_url( home_url() ); ?>">
<fieldset>
<input type="text" name="s" class="header-text uniform" size="15" title="<?php esc_attr_e( 'Search','adelle-theme' ); ?>" />
<input type="submit" class="uniform" value="<?php esc_attr_e( 'Search','adelle-theme' ); ?>" />
</fieldset>
</form>
</nav2><!-- .nav2 -->
css:
/* .nav */
.mobile-nav {display: none;}
.tinynav {display: none;}
.nav {position: relative; top: 0px; width: 970px; display: inline-block; background: #000; padding: 0 25px; margin-top: 0px; clear: both; line-height: 1em; text-transform: uppercase;}
.nav:before,
.nav:after {border: 1.6em solid #000; content: ""; display: block; position: absolute; bottom: 0; top: 0; z-index: 1;}
.nav:before {border-left-color: #fff; border-right-width: 1.4em; left: 0;}
.nav:after {border-left-width: 1.4em; border-right-color:#fff; right: 0;}
.nav ul {list-style: none; max-width: 780px; display: inline-block;}
.nav a {display: block; padding: 14px; color: #fff;}
.nav a:hover {text-decoration: underline; color: #fff;}
.nav ul ul a {display: block; padding: 14px; position: relative;}
/* .nav2 */
.mobile-nav {display: none;}
.tinynav {display: none;}
.nav2 {position: fixed; top: 10px; width: 2000px; display: inline-block; background: #fff; padding: 0 25px; margin-top: 40px; clear: both; line-height: 1em; text-transform: uppercase;}
.nav2:before,
.nav2:after {border: 1.6em solid #000; content: ""; display: block; position: absolute; bottom: 0; top: 0; z-index: 1;}
.nav2:before {border-left-color: #fff; border-right-width: 1.4em; left: 0;}
.nav2:after {border-left-width: 1.4em; border-right-color:#fff; right: 0;}
.nav2 ul {list-style: none; max-width: 780px; display: inline-block;}
.nav2 a {display: block; padding: 14px; color: #fff;}
.nav2 a:hover {text-decoration: underline; color: #fff;}
.nav2 ul ul a {display: block; padding: 14px; position: relative;}
If you want 2 navs, one looking different that the other, I'd suggest you use the nav tag for both, but add a unique ID for the second nav and use that ID in your css to overwrite the styles you need to change for the second nav:
<nav>stuff here</nav>
<nav id="secondary-nav">stuff here</nav>
You don't necessarily need the class on the main nav. You can style as such:
nav {
position: relative;
top: 0px;
width: 970px;
}
nav#secondary-nav {
top: 10px;
width: 2000px;
}

Resizable table area PHP

I am trying to show a lot of results at once (like 25) but my program cut the results around the 5th record having area space still available, the results are in a table
created dynamically but seems that the area doesn't expand accordingly.
<div id="contenido" class="contenido">
<div id="Tabs">
<ul style="cursor:pointer;">
<li id="li_tab1" onclick="tab('tab1')" >
<a>Últimas alertas</a> </li>
<li id="li_tab2" onclick="tab('tab2')"> <a>otras</a> </li>
</ul>
<div id="Content_Area">
<div id="tab1">
<p class="notas">Showing last alerts</p>
<table>
<tr>
<td style="color:blue">Alert</td>
<td style="color:blue">User</td>
</tr>
<?php
while ( $row = $result->fetch_array() ){
echo "<tr><td>".$row['DESCRIPTION']."</td>";
echo "<td>".$row['EMAIL']."</td>";
echo "<td>".$row['SUB_SECCION']."</td></tr>";
}
}
else
echo "error on query: ".$conx->error;
}//else
?>
</table>
</div>
<div id="tab2" style="display: none;">
<!-- We set its display as none because we don’t want to make this
tab visible by default. The only visible/active tab should
be Tab 1 until the visitor clicks on Tab 2. -->
<p>This is the text for tab 2.</p>
</div>
</div> <!-- End of Content_Area Div -->
</div> <!-- End of Tabs Div -->
</div>
CSS creates tabs, but for the moment only the first has the table the other just one line of text, but the table is inside this tab div
archivo css
.contenido {
color: black;/*#333*/
background-color: #F2F2E6;
margin: 0px 0px 5px 0px;
padding: 10px;
border: 1px solid #ccc;
width: 75%;/*678px;*/
height: 480px;
float: right;
display: inline;
}
#Tabs ul {
padding: 0px;
margin: 0px;
margin-left: 10px;
list-style-type: none;
}
#Tabs ul li {
display: inline-block;
clear: none;
float: left;
height: 24px;
}
#Tabs ul li a {
position: relative;
margin-top: 16px;
display: block;
margin-left: 6px;
line-height: 24px;
padding-left: 10px;
background: #f6f6f6;
z-index: 9999;
border: 1px solid #ccc;
border-bottom: 0px;
/* make the top left and top right corners of each tab rounded. */
-moz-border-radius-topleft: 4px;
border-top-left-radius: 4px;
-moz-border-radius-topright: 4px;
border-top-right-radius: 4px;
/* end of rounded borders */
width: 130px;
color: #000000;
text-decoration: none;
font-weight: bold;
}
#Tabs ul li a:hover {
text-decoration: underline;
color:red;
}
#Tabs #Content_Area {
/* this is the css class for the content displayed in each tab */
padding: 0 15px;
clear:both;
overflow:hidden;
line-height:19px;
position: relative;
top: 20px;
z-index: 5;
height: 150px;
overflow: hidden;
}
p { padding-left: 15px; }
The problem is inside your CSS.
height: 150px; and overflow: hidden; in #Tabs #Content_Area could be factor.
Since you have overflow: hidden; set to "hidden", it could be a factor.
Try changing it to overflow:scroll; or overflow:visible; to see if that works, and/or changing the heights to a higher number for those IDs.
Try different variations.
I see a two possible causes:
The database query only returns 5 results
the DIV is not large enough, and even though the table ends up in,
say, 25 records, the first 5 are only displayed and the rest are
hidden by the boundaries of DIV.
It would help if you put some more PHP code or even the CSS of the #area.

Categories