php string to choose different navigation's classes by max width - php

I have main navigation that change by max-width.
.main-navigation {
border-left: 1px solid #cccccc;
display: block;
float: right;
font-family: "Open Sans Condensed", Helvetica, Arial, sans-serif;
font-weight: bold;
max-width: 50%;
position: relative;
text-align: right;
text-transform: uppercase;
}
#media screen and (max-width: 885px) {
.main-navigation {
border: 0;
float: none;
max-width: 100%; }
as you can see, the second code is when the width is lower then 885px (like mobile).
I have tried many ways to give other style to each one with the css code but with no seceded.
So, i want to make another main navigation code for the smaller navigation and to call him main navigation2.
I need some php code to add to the original that take to navigation class by the width. is that possible?
this is the original code:
<nav id="site-navigation" class="main-navigation" role="navigation">
<h1 class="menu-toggle"><span class="screen-reader-text"><?php _e( 'Menu', 'pictorico' ); ?></span></h1>
<a class="skip-link screen-reader-text" href="#content"><?php _e( 'Skip to content', 'pictorico' ); ?></a>
<?php wp_nav_menu( array( 'theme_location' => 'primary' ) ); ?>

you can't get screen width using PHP unfortunately.
You could do it in javascript by obtaining the screen width and applying it to the nav tag by selecting it by ID
<script type='text/javascript'>
var screenWidth = window.screen.width;
var element = document.getElementById('site-navigation');
if (screenWidth < 885) {
element.className = navigation1;
}
else
{
element.className = navigation2;
}
</script>

Related

Having trouble aligning navigation bar and logo

I'm having trouble aligning the navigation bar and logo for a site I'm building. I would be able to do it if WordPress wasn't involved, but there are a bunch of classes that my wordpress theme generated that I'm not sure how to work with.
This is what I currently have:
I'd like to have the logo stay on the left while moving the menu items to the right of the logo. My site is invictus-together.com if you want to check out the site to inspect it.
My php/html is:
<div id="page">
<a class="skip-link screen-reader-text" href="#content"><?php esc_html_e( 'Skip to content', 'invictus' ); ?></a>
<header id="masthead" class="site-header">
<img src="<?php echo get_template_directory_uri(); ?>/invictus-together-logo-white.png"/>
<nav id="site-navigation" class="main-navigation">
<button class="menu-toggle" aria-controls="primary-menu" aria-expanded="false"><?php esc_html_e( 'Primary Menu', 'invictus' ); ?></button>
<?php
wp_nav_menu( array(
'theme_location' => 'menu-1',
'menu_id' => 'primary-menu',
) );
?>
</nav><!-- #site-navigation -->
<div class="login-section">
</div>
</header><!-- #masthead -->
</div>
Also, my current CSS is this:
.site-header {
background-color: black;
color: white;
align-items:center;
}
#masthead {
display: float-left;
}
.main-navigation {
clear: none;
float:left;
padding-top: 36px;
}
.main-navigation a{
color:white;
margin:5px;
}
If anyone could help me out, I'd really appreciate it.
#masthead {
display: float-left;
}
This is invalid CSS.
header a:first-child {
float: left;
width: 25%;
display: block;
}
header a:first-child img {
width: 100%;
height: auto;
}
.main-navigation {
clear: none;
float:left;
padding-top: 36px;
width: 75%;
}
Remove padding-top from .main-navigation and add display: flex; to .site-header. The logo and navigation will be side-by-side and aligned.
A simple solution would be to make the #masthead container a flex container in which the (two) child elements (the link wrapping the image and the navigation container)are aligned left and right, by using this CSS:
#masthead {
display: flex;
justify-content: space-between;
}
you can use this code
body {
margin: 0;
padding: 0;
}
#page a {
float: left;
}
.site-header {
background-color: black;
color: white;
align-items: center;
padding: 30px;
}
#masthead {
display: block;
}
.main-navigation {
padding-left: 36px;
display: inline-block;
}
.main-navigation a {
color: white;
margin: 5px;
}
<div id="page">
<a class="skip-link screen-reader-text" href="#content">
<?php esc_html_e( 'Skip to content', 'invictus' ); ?>
</a>
<header id="masthead" class="site-header">
<img src="<?php echo get_template_directory_uri(); ?>/invictus-together-logo-white.png"/>
<nav id="site-navigation" class="main-navigation">
<button class="menu-toggle" aria-controls="primary-menu" aria-expanded="false">
<?php esc_html_e( 'Primary Menu', 'invictus' ); ?>
</button>
<?php
wp_nav_menu( array(
'theme_location' => 'menu-1',
'menu_id' => 'primary-menu',
) );
?>
</nav>
<!-- #site-navigation -->
<div class="login-section">
</div>
</header>
<!-- #masthead -->
</div>
I ended up using grid display, and it worked out pretty well.
HTML:
<div id="page">
<a class="skip-link screen-reader-text" href="#content"><?php esc_html_e( 'Skip to content', 'invictus' ); ?></a>
<header id="masthead" class="site-header" role="banner">
<div class="container-header">
<div class="site-branding">
<?php dynamic_sidebar('header'); ?>
</div><!-- .site branding -->
<div class="site-logo">
<img src="<?php echo get_template_directory_uri(); ?>/site-photos/invictus-together-logo-white.png"/>
</div><!-- .site logo -->
<nav id="site-navigation" class="main-navigation" role="navigation">
<button class="menu-toggle" aria-controls="primary-menu" aria-expanded="false"><?php esc_html_e( 'Primary Menu', 'invictus' ); ?></button>
<?php wp_nav_menu( array('theme_location' => 'menu-1', 'menu_id' => 'primary-menu') ); ?>
</nav><!-- #site-navigation -->
</div><!-- .container -->
</header><!-- #masthead -->
</div>
CSS:
header {
margin-top: 10px;
}
#masthead {
background-color:black;
margin: 0px;
}
.container-header {
display: grid;
grid-template-columns: 1fr 2fr 1fr;
justify-items: stretch;
align-items: stretch;
}
/*social media*/
.site-branding::after {
content:"";
clear:both;
}
.site-branding .widget {
margin-bottom:0;
}
.site-branding{
grid-column:3;
grid-row:1/2;
align-self: stretch;
justify-self:center;
}
/*logo*/
.site-logo {
margin:20px;
grid-column: 1;
grid-row:1/2;
align-self: stretch;
justify-self:center;
}
.site-logo a img {
margin:0;
}
/* Main Navigation */
.main-navigation {
clear: both;
display: block;
float: none;
text-align: center;
grid-column: 2;
grid-row:1/2;
align-self: center;
}
.main-navigation li {
display: inline-block;
float: none;
}
.main-navigation a {
display: block;
font-size: 22px;
font-weight: 700;
padding: 0 20px;
text-decoration: none;
text-transform: uppercase;
color:white;
}
.menu-header-menu-container {
display: flex;
justify-content: center;
align-items: center;
}
Here's what it looks like,all I need to do is change the font:

how do i remove white spaces in between these images in bootstrap 3

Good day,
Am in the process of building a free wordpress theme for entrepreneurs but encountered this challenges:
I want to get rid of white spaces in between the post containers as show in the image above.
in the posts in between, the post dates are not displaying, i don't know why.
here are my code:
HTML/PHP
<div class="container-fluid">
<div class="navbar">
<div>
<a class="navbar-brand" href="<?php bloginfo('url'); ?>" title="<?php bloginfo('name'); ?>" >
<?php bloginfo('name'); ?></a>
</div>
<div>
<!--<h1 class="blog-title"><?php bloginfo( 'name' ); ?></h1>-->
<?php $description = get_bloginfo( 'description', 'display' ); ?>
<?php if($description) { ?><p class="blog-description"><?php echo $description ?></p><?php } ?></p>
<?php wp_nav_menu (array(
'theme_location' => 'header-menu',
'menu_class' => 'nav navbar-nav pull-right'
) ); ?>
</div>
CSS:
.layerit {
width: 100%;
height: 100%;
padding-top: 170px;
margin: 0 auto;
background: rgba(0, 0, 0, .3);
position: relative;
bottom: 0;
right: 0;
text-align: center;
transition: background-color .9s ease;
}
.home-title {
color: white;
}
.home-author {
color: white;
padding-top: 20px;
padding-bottom: 90px;
}
div.no-margin {
}
Thanks for the help.
For vertical lines:
font-size: 0; on parent element
OR
ul {
padding: 0;
}
li{
display: inline-block;
background: red;
width: 20px;
height: 20px;
}
<ul>
<li></li>
<li></li>
</ul>
SHOULD BE
ul {
padding: 0;
}
li{
display: inline-block;
background: red;
width: 20px;
height: 20px;
}
<ul>
<li></li><li></li>
</ul>
For horizontal lines:
vertical-align: top; for child elements
EDIT: Putting all <li> tags in a single line removes the whitespace in the markup, which is what's causing the spaces in the original question. Another more manageable way to fix it is to use html comments between the closing tag and the next opening one, like this:
<li>...</li><!--
--><li>...</li><!--
--><li>...</li>

Duplicating a wordpress navigation menu

I am making my first steps learning to code. I made some courses of html, php, css, javascript and MySql. Now I decided to continue learning from the practice while I build a Wordpress child theme.
The thing is that I'm trying to learn how to overlay two different font families in the same div. I mean something like this:
I discover that it's something possible to do with css using content: attr(data-title);
For example:
.button {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
background: transparent;
display: inline-block;
height: 42px;
padding: 0 1.5em;
position: relative;
border: none;
outline: 0;
text-align: center;
font-family: 'Open Sans', sans-serif;
font-size: 40px;
line-height: 44px;
color: #000000;
font-weight: 800;
letter-spacing: 1.5px;
text-transform: uppercase;
}
.button:after {
content: attr(data-title);
z-index: 1;
font-size: 30px;
color: #f00;
font-weight: 100;
display: block;
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
}
<link href="https://fonts.googleapis.com/css?family=Open+Sans:100,800" rel="stylesheet">
ABC
Now my big problem is that I'm working with Wordpress and the php is a little more complex. What I would like to do is to have two different fonts for each menu item. For example:
This is the code php of my menu:
<?php if ( has_nav_menu( 'primary' ) ) : ?>
<nav id="site-navigation" class="main-navigation" role="navigation" aria-label="<?php esc_attr_e( 'Primary Menu', 'twentysixteen' ); ?>">
<?php
wp_nav_menu( array(
'theme_location' => 'primary',
'menu_class' => 'primary-menu',
) );
?>
</nav>
<?php endif; ?>
And this is the css:
.main-navigation {
font-family: pcablack;
font-size: 30px;
word-spacing: -5px;
/*position: relative;*/
position: absolute;
z-index: 1000;
padding-bottom: 20px;
margin-top: 48px;
margin-left: 40px;
}
I tried to make this but it doesn't work as I expect. It seems that maybe there is a syntax problem:
<?php if ( has_nav_menu( 'primary' ) ) : ?>
<nav id="site-navigation" class="main-navigation" role="navigation" aria-label="<?php esc_attr_e( 'Primary Menu', 'twentysixteen' ); ?>"
data-title= '
<?php
wp_nav_menu( array(
'theme_location' => 'primary',
'menu_class' => 'primary-menu',
) );
?>'
>
<?php
wp_nav_menu( array(
'theme_location' => 'primary',
'menu_class' => 'primary-menu',
) );
?>
</nav>
<?php endif; ?>
then the css:
.main-navigation {
font-family: pcablack;
font-size: 30px;
word-spacing: -5px;
/*position: relative;*/
position: absolute;
z-index: 1000;
padding-bottom: 20px;
margin-top: 48px;
margin-left: 40px;
}
.main-navigation:after {
content: attr(data-title);
font-family: pcabold;
color: green;
font-size: 30px;
word-spacing: -5px;
/*position: relative;*/
position: absolute;
z-index: 1100;
padding-bottom: 20px;
margin-top: 48px;
margin-left: 40px;
}
It doesn't work. It only shows me console errors. Do you have some recommendation?
Maybe there is an easiest way to duplicate the font of a menu item and overlay it?
Other problem is that my menu is an accordion menu. So if I open a section of one of the menus that I duplicate the other menu should be automatically open too.
OMG, you doing this wrong.
You need copy only menu items titles to data attribute. SO for example:
$('.main-menu ul a').each(function() {
var text = $(this).html();
$(this).attr('data-title', text);
});
.main-menu li a {
position:relative;
font-family: "Arial Black";
font-size: 15px;
}
.main-menu li a:after {
content: attr(data-title);
position:absolute;
font-family: "Arial Black";
display:block;
font-size: 14px;
z-index:1;
left:0;
top:0;
color:red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<nav class="main-menu">
<ul class="menu">
<li>Home</li>
<li>About</li>
<li>Why</li>
<li>Contacts</li>
</ul>
</nav>

Wordpress selectively applying css rules following wp_enqueue_style

I'm in the process of transferring an HTML/CSS/jquery mockup of a website into a wordpress theme. The site runs perfectly as an HTML site and all of the css rules are selecting the correct html elements.
However, when I enqueue the scripts to Wordpress and look at the site, only certain rules are being applied, resulting in the website having a broken look. I know the css is being correctly enqueued since I can see it showing up in the page source for the website. When I look at specific elements with web inspector it shows that only certain rules are being implemented but not others. Why would transferring my css to Wordpress change how the css rules apply to almost identical HTML?
Below the code for how I'm enqueuing scripts. Note the dependency on normalize:
<?php
//
function theme_styles() {
wp_enqueue_style( 'normalize', get_template_directory_uri() . '/normalize.css' );
wp_enqueue_style( 'main', get_template_directory_uri() . '/style.css', array( 'normalize' ) );
}
// Load the theme JS
function theme_js() {
wp_register_script('stickynav',get_template_directory_uri() . '/js/stickynav.js', array('jquery'), '', true);
wp_register_script('nouislider',get_template_directory_uri() . '/js/nouislider.js', array('jquery'), '', true);
wp_register_script('bootstrap2',get_template_directory_uri() . '/js/bootstrap2.js', array('jquery'), '', true);
wp_register_script('foundation',get_template_directory_uri() . '/js/foundation.js', array('jquery'), '', true);
wp_register_script('orbit',get_template_directory_uri() . '/js/foundation.orbit.js', array('jquery'), '', true);
wp_register_script('modernizr',get_template_directory_uri() . '/js/modernizr.custom.49510.js', array('jquery'), '', true);
wp_enqueue_script('stickynav');
wp_enqueue_script('nouislider');
wp_enqueue_script('bootstrap2');
wp_enqueue_script('modernizr');
wp_enqueue_script('theme_js', get_template_directory_uri() . '/js/theme.js', array('jquery'), '', true);
if (is_home() && !is_paged() ) {
wp_enqueue_script('foundation');
wp_enqueue_script('orbit');
}
}
add_action( 'wp_enqueue_scripts', 'theme_js');
add_action('wp_enqueue_scripts','theme_styles');
// Enable custom menus
add_theme_support ('menus');
?>
This is the html/php I have in header.php:
<!DOCTYPE html>
<html>
<head>
<title>
<?php
wp_title( '-', true, 'right' );
bloginfo('name');
?>
</title>
<meta name="viewport" content="width=device-width, initial-scale = 1.0">
<?php wp_head(); ?>
</head>
<body>
<div id="header_top_wrapper">
<!-- header and subheader -->
<div class="row" id="header-top">
<div class="large-12 columns" id="my_logo">
<?php bloginfo( 'name'); ?>
</div>
<div class="large-6 columns large-uncentered" id="subheader">
<h4><?php bloginfo( 'description'); ?></h4>
</div>
</div>
<!-- sticky navigation bar -->
<div id="sticky_navigation_wrapper">
<div id="sticky_navigation">
<div class="navigation_items">
<li class="nav-left">HOUSEPLANS.INFO</li>
<li class="nav-left">SEARCH PLANS</li>
<li class="nav-left">MOST VIEWED</li>
<li class="nav-right">ABOUT</li>
<li class="nav-right" id="site-search">
<form action="/search" method="get">
<input type="text" name="s" data-provide="typeahead" autocomplete="off" placeholder="Search";>
<i class="icon-search"></i>
</form>
</li>
</div>
</div>
</div>
</div><!-- end #header_top_wrapper -->
As an example of the selective application, these are the rules that are being applied to a link nested inside of an list item li on the HTML mockup
#sticky_navigation ul li a {
float: left;
margin: 0 0 0 5px;
height: 36px;
padding: 0;
line-height: 36px;
font-size: 12px;
font-weight: normal;
color: white;
}
#sticky_navigation ul {
list-style: none;
}
body {
font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;
font-style: normal;
}
And this is what is being applied to the same link in the Wordpress version of the same HTML and CSS
a {
color: inherit;
text-decoration: none;
line-height: inherit;
}
li {
text-align: -webkit-match-parent;
}
body {
font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;
font-size: 12px;
font-weight: normal;
font-style: normal;
}
Below is the CSS style for the area in question:
/* Logo and subheader */
#my_logo {
font:45px Georgia, Times, serif;
padding-left: 8px;
}
#subheader h4{
margin: 6px 0 0 0;
}
/* our menu styles */
#sticky_navigation_wrapper {
width:100%;
height:36px;
}
#sticky_navigation {
width:100%;
height:36px;
/* background: rgba(65, 105,255,.4); */
background: black;
z-index: 1030;
}
.navigation_items {
width:960px;
margin:0 auto;
}
.navigation_items ul{
padding-left: 0;
}
.navigation_items ul.pull-left:after {
clear: both;
}
#sticky_navigation ul {
list-style:none;
margin: 0;
/* padding:0; */
}
#sticky_navigation ul li{
margin:0;
display:inline-block;
}
#sticky_navigation ul li a{
/* float:left; */
/*margin:0 0 0 5px;*/
height:36px;
/* padding: 0; */
line-height:36px;
font-size:12px;
font-weight:normal;
color:white;
}
.nav-left{
padding-left: 10px;
padding-right: 20px;
}
.nav-right {
float: right !important;
padding-right: 10px;
padding-left: 20px;
}
What is going on here? I've been up all night trying to figure this out.
I'm enqueuing correctly, and according to the page source the exact same css is in the header as in my non-Wordpress version.
You have:
add_action('wp_enqueue_scripts','theme_styles');
But probably you should change it to:
add_action('wp_enqueue_style','theme_styles');
Ref: http://codex.wordpress.org/Function_Reference/wp_enqueue_style
Change
add_action('wp_enqueue_scripts','theme_styles');
to
add_action('wp_enqueue_style','theme_styles');
Also please remember that if you change or edit the css, you need to delete your cache and your visitors also needs to delete their browser's cache. But of course there's a better way to do it. Just fill in the "version" arguments on the wp_enqueue_style.
Do it like this:
add_action('wp_enqueue_style','theme_styles', array(), '1.0.0');
Every time you edit your css. Just change the version to '1.0.1' or '1.0.2' and so on. This will force your visitor's browser to get the latest version of the css.
Figured it out...
UL tags were missing for the li's - somehow deleted while inserting PHP.
DOH!

Centering my css3 menu of changing widths...?

I have a css menu which has a width of 400 for non-Admins... and a width of 500 for Admins. If I set the UL width to 500, the menu centers fine and nicely for Admins. But for non-admins, whose mneu is really only 400 wide... it's off-kilter.
So I removed the width attribute from the UL to try and remove this and then it lost centering altogether; the whole menu is now stuck to the left side of the container.
Anyone have a simple idea for how to make it always centered? Site is here:
http://www.runic-paradise.com/
ul.menu{
height: 40px;
list-style: none outside none;
margin: 0 auto;
/*width: 500px;*/
}
/*li{
width:100px;
height:50px;
float:left;
color:#191919;
text-align:center;
overflow:hidden;
}*/
a.menu{
color:#FFF;
text-decoration:none;
}
p.menu{
padding-top: 10px;
padding-right: 5px;
padding-left: 5px;
}
.subtext{
padding-top: 10px;
}
ul.menu li{
width: 100px;
height: 40px;
float: left;
color: #191919;
text-align: center;
overflow: hidden;
}
/*Menu Color Classes*/
.green{
background:#6AA63B url('/img/menu/green-item-bg.jpg') top left no-repeat;
}
.yellow{
background:#FBC700 url('/img/menu/yellow-item-bg.jpg') top left no-repeat;
}
.red{
background:#D52100 url('/img/menu/red-item-bg.jpg') top left no-repeat;
}
.purple{
background:#5122B4 url('/img/menu/purple-item-bg.jpg') top left no-repeat;
}
.blue{
background:#0292C0 url('/img/menu/blue-item-bg.jpg') top left no-repeat;
}
<ul class="menu">
<li class="green">
<p class="menu">Home</p>
<p class="subtext">The front page</p>
</li>
<li class="yellow">
<p class="menu">-</p>
<p class="subtext">More info</p>
</li>
<li class="red">
<p class="menu">Forums</p>
<p class="subtext">Get in touch</p>
</li>
<li class="blue">
<p class="menu">-</p>
<p class="subtext">Send us your stuff!</p>
</li>
<?php
if ($user->data['group_id'] == 5)
{
echo ' <li class="purple">
<p class="menu">Admin</p><p class="subtext">Legal things</p>
</li>';
}
?>
</ul>
Your CSS sets the ul.menu width to 400px. If the user is admin, the php script adds another 100px wide li to ul.menu. When this happens, you have to set the ul.menu width to 500px. If you do this, the css rule margin:0px auto; will handle the centering as expected.
A simple jQuery fix would be something like this:
<script>
$(document).ready(function() {
var menu=$('ul.menu');
if(menu.find('li')>4) {
//if there are more then 4 menu items, reset menu width to 500px
menu.css('width','500px');
}
});
</script>
Use max-width:500px;for UL.Demo for these http://jsfiddle.net/dhanith/ZMB93/
Can you please try this,
In animated-menu.css (demo url: http://www.runic-paradise.com/), Change margin style as like below
ul.menu {
height: 40px;
list-style: none outside none;
margin: auto 25%;
}

Categories