How to center list items for mobile screens - css

When I shrink the browser for mobile screens,lists which are in footer, doesnt seem centered.
You can see it on this link:
https://www.sac-ekimi.deniz-tasarim.site/bize-ulasin/
( "Hakkımızda" and "Destek" lists )
How to center them?
Here is the codes for these lists:
<div class="col-sm-3" style="margin-left:auto; margin-right:auto;" >
<h5 style="text-align: center;"><?php
// Using the global argment
global $redux_demo; // Same as your opt_name
echo $redux_demo['footer-text-1']; ?></h5>
<ul>
<li style="display: inline-block; "><a href="#">
<?php wp_nav_menu( array(
'theme_location' => 'menu_name',
'container' => "nav",
'container_class' => "topnav",
'container_id' => "topnav",
'menu_class' => "topmenu",
'menu_id' => "topmenu",
)
);
?>
</a></li>
</ul>
</div>
<div class="col-sm-3 footermenu" style="margin-left:auto; margin-right:auto;">
<h5 style="text-align: center;"><?php
// Using the global argment
global $redux_demo; // Same as your opt_name
echo $redux_demo['footer-text-2']; ?></h5>
<ul >
<li style="display: inline-block;"><a href="#" >
<?php wp_nav_menu( array(
'theme_location' => 'menu_name2',
'container' => "nav",
'container_class' => "topnav",
'container_id' => "topnav",
'menu_class' => "topmenu",
'menu_id' => "topmenu",
)
);
?>
</a></li>
</ul>
</div>

It appears the browser is adding padding-left: 40px; to all uls on the page as part of its default styling. You could fix this by adding a CSS Reset to your project but at this point, that will likely break a lot more code than it will fix. Its generally advised to plug in a CSS Reset at the start of a project.
To resolve this issue alone, I'd recommend overwriting the the ul#topmenu like so:
#topmenu {
padding-left: 0;
}
This will resolve the extra padding you're seeing on your uls.
This will not completely resolve the alignment issues you're seeing on smaller screens. If a single word is longer than the parent containing it, it will overflow past the edge of the parent so as to keep the text readable.
I'd recommend re-flowing your footer on smaller screen sizes to be stacked.
Should look something like this:
#media (max-width: 767px) {
#myFooter .col-sm-3 {
flex: 0 0 100%;
max-width: 100%;
}
#myFooter .col-sm-3 ul {
padding-left: 0;
text-align: center;
}
}

For media queries to work, you need to include:
<meta name="viewport" content="width=device-width, initial-scale=1.0">
Between the tags.
https://www.w3schools.com/css/css_rwd_viewport.asp

Related

How to target the hamburger <span> (WP Bootstrap Navwalker) in mobile view

I want to change icon's color to white, but can't seem to target it properly. Is there any way of targeting it from the main.css, or only in HTML class with Bootstrap (and if so, how?).
HTML:
<header class="header" id="myHeader">
<div class="container">
<nav class="navbar navbar-expand-lg navbar-dark bg-transparent" role="navigation">
<!-- Brand and toggle get grouped for better mobile display -->
<button class="navbar-toggler border-0" type="button" data-bs-toggle="collapse" data-bs-target="#bs-example-navbar-collapse-1" aria-controls="bs-example-navbar-collapse-1" aria-expanded="false" aria-label="<?php esc_attr_e('Toggle navigation', 'your-theme-slug'); ?>">
<span class="navbar-toggler-icon"></span>
</button>
<!-- <a class="navbar-brand" href="#">Navbar</a> -->
<?php
wp_nav_menu(array(
'theme_location' => 'top-menu',
'depth' => 2,
'container' => 'div',
'container_class' => 'collapse navbar-collapse',
'container_id' => 'bs-example-navbar-collapse-1',
'menu_class' => 'top-bar',
'fallback_cb' => 'WP_Bootstrap_Navwalker::fallback',
'walker' => new WP_Bootstrap_Navwalker(),
));
?>
</nav>
</div>
</header>
CSS
header .container {
height: 100%;
z-index: 10;
display: flex;
align-items: center;
position: relative;
}
header .container .top-bar {
list-style-type: none;
display: flex;
}
header .container .site-link,
.site-logo {
margin-right: auto;
}
header .top-bar li a {
/*padding: 0 2rem;*/
padding: 2.5rem 2rem 2.5rem 2rem;
color: var(--off_white);
font-size: 1.3rem;
text-decoration: none;
z-index: 1000;
}
header .top-bar li.current-menu-item a {
background: var(--secondary);
}
#media (max-width: 992px) {
/* bootstrap navwalker menu */
.navbar-toggler span {
background-color: transparent;
color: var(--off_white) !important;
border: 0;
cursor: pointer;
font-size: 2rem;
display: block;
}
}
Also, how can I expand my nav-menu after clicking the hamburger icon in mobile view, to make it fullscreen and the background blurred? The question is basically how to target it, will it work targeting .top-bar?
The reason this is happening is because you are using navbar-dark. Nothing wrong with this, perfectly normal and the same would be happening with navbar-light.
This might be worth a try in your CSS. !important I hope will over ride any Boostrap CSS (but only for the button color unless you add more CSS)
button .navbar-toggler{
color: white !important;
}
With your second question. If you can provide the code examples again to make it a properly formatted question I think the question might be worthy of it's own post. 1 post 1 question usually does work best.

How do I positioning dynamically created links using css in wordpress?

I have built the navigation in html and css but has been given back to me with wordpress installed and some of my styling hasn't rendered as expected. From my understanding there are limitations surrounding the styling of <a> tags in links.
I want to give the dynamically created a bottom margin of -15px.
The<a> is in an <li> . Adding a margin to that doesn't effect the <a> within it, not does adding margin to the <ul>. It appears to not to be inside these elements?
<div class="nav-head">
<?php
wp_nav_menu(array(
'theme_location' => 'primary',
'depth' => 2,
'container' => false,
'container_class' => 'btn',
'container_id' => '',
'menu_class' => 'nav-menu',
)
);
?>
<a type="button" class="btn secondary-btn" href="/contact">Request Demo</a>
</div>
CSS
.nav-head {
display: flex;
}
ul.nav-menu {
display: flex;
}
li.menu-item {
margin-bottom: -15px;
display: inline-block;
}
a {
color: blue;
padding: 15px;
display: inline-block;
}

CSS mobile menu design

I'm designing my page mobile friendly menu in Wordpress. I want expandable submenus to have + next to them. I'm trying to use content to add + next to it and float middle with padding but my issue is I'm getting + next to everything on the menu.
PHP:
<div class="store-menu">
<div class="store-wrapper">
<nav id="site-navigation" class="main-navigation" role="navigation">
<button class="menu-toggle" aria-controls="primary-menu" aria-expanded="false"><?php esc_html_e( '', 'eightstore-lite' ); ?></button>
<?php wp_nav_menu( array( 'theme_location' => 'primary', 'menu_id' => 'primary-menu' ) ); ?>
</nav><!-- #site-navigation -->
<div class="clear"></div>
</div>
</div>
CSS:
#media screen and (max-width: 990px) {
.sub-menu {display: none !important;}
.menu li a::after{
content:'+' !important;
color:'white' !important;
float:middle !important;
font-size:14px !important;
padding-left: 10px !important;
}
}
This is what i want
Hey so the first little bump your going to run into is that there is no float middle property. You could use flexbox for this, or just a simple text-align: center
Im guessing your other issue is that you only want the '+' icons to show on menu items that have children?
What you need to do in that case is take advantage of the 'menu-item-has-children' classes added by Wordpress to menus. Something like:
.menu li.menu-item-has-children a::after{
content:'+' !important;
color:'white' !important;
text-align: center;
font-size:14px !important;
padding-left: 10px !important;
}
Something else to point out is that are misusing the !important property. You will want to look into css specificity CSS Tricks - css specificity

Bootstrap navigation menu in wordpress mobile view

I have two navigation bar in my header and the center of it is my logo. I am using WordPress and also include the classes of bootstrap. I have a problem regarding in mobile view or something between max-width of 700+ pixels. My navigation menu got destructed when i make it below 700 pixels. I provided a screenshot to determine my problem.
Also here is my site: http://bxuwp.codebox.ph/
Here is the screenshot of my problem:
Here is my code:
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="container-fluid">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<div class="logo-wrapper">
<div class="logo">
<?php if ( get_theme_mod( 'm1_logo' ) ) : ?>
<a href="<?php echo esc_url( home_url( '/' ) ); ?>" id="site-logo" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" rel="home">
<img src="<?php echo get_theme_mod( 'm1_logo' ); ?>" alt="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>"></a>
<?php else : ?>
<img class="logo" src="<?php echo get_bloginfo('template_url') ?>/images/qmark_logo.png"/>
<?php endif; ?>
</div>
</div>
<div class="half">
<ul class="left-navlist">
<?php
$args = array(
'container' => 'div',
'container_class' => 'collapse navbar-collapse pull-right',
'container_id' => 'bs-example-navbar-collapse-1',
'menu' => 'left',
'menu_class' => 'nav navbar-nav',
'fallback_cb' => 'wp_bootstrap_navwalker::fallback',
'walker' => new wp_bootstrap_navwalker()
);
?>
<?php wp_nav_menu($args); ?>
</ul>
</div>
<div class="half">
<ul class="right-navlist">
<?php
$args1 = array(
'container' => 'div',
'container_class' => 'collapse navbar-collapse',
'container_id' => 'bs-example-navbar-collapse-1',
'menu' => 'right',
'menu_class' => 'nav navbar-nav',
'fallback_cb' => 'wp_bootstrap_navwalker::fallback',
'walker' => new wp_bootstrap_navwalker()
);
?>
<?php wp_nav_menu($args1); ?>
</ul>
</div>
</div>
</div>
Here is my little custom CSS for bootstrap navbar:
.navbar-fixed-top {
min-height: 95px;
}
.navbar-inverse .navbar-nav > .open > a, .navbar-inverse .navbar-nav > .open > a:focus, .navbar-inverse .navbar-nav > .open > a:hover {
background-color: #e1e1e1;
color: #fff;
}
.navbar-inverse {
border-radius: 0px;
margin-bottom: 0;
background-color: #e1e1e1;
border-color:#e1e1e1;
font-size: 16px;
}
.navbar-inverse .navbar-nav > .active > a, .navbar-inverse .navbar-nav > .active > a:focus, .navbar-inverse .navbar-nav > .active > a:hover {
background-color: #e1e1e1;
color: #993300;
}
.navbar-inverse .navbar-nav > li > a {
color: #252525;
}
.logo-wrapper {
text-align: center;
margin-bottom: -65px;
}
.logo {
margin-top: 5px;
max-width: 80px;
display: inline-block;
}
.half {
width: 50%;
display: block;
float: left;
}
.right-navlist {
padding-left: 60px;
}
.left-navlist {
text-align: right;
padding-right: 60px;
}
You have a media query making the nav float left only on a minimum of 768px. Some browsers render pixels slightly differently so you may have noticed it's not exactly at 768px. Remove the query (or override it) and you will be fine!
#media (min-width: 768px) {
.navbar-nav>li {
float: left;
}
}
Just an FYI though, you will have the same issue around 400px so you could make it so that your text is smaller at that window size. Basically, if the text stays that same size when it's a window size of 400px, the container of those elements is too small and bumps one of the containers down (Contact Us). Again, that's only happening right around 400px. You may want to give it alternative treatment instead like a hamburger icon controlling a nav that slides into view.

Category items won't display on a single row

I am finishing up a custom Storefront child theme for a client. Yesterday, when I began work, I noticed the homepage category row items were displaying on two rows. I had made no changes to any of the template code or CSS. No matter what I do, I cannot get them to display on a single row. I have removed the float, put float:left back, removed the margins and padding, without any of the changes correcting the way that the category items display.
site url: https://test.onyour6designs.com
CSS
.page-template-template-homepage-php .site-main .columns-3 ul.products,
.storefront-full-width-content .site-main .columns-3 ul.products {
width: 100%;
display: block;
}
.page-template-template-homepage-php .site-main .columns-3 ul.products li.product,
.storefront-full-width-content .site-main .columns-3 ul.products li.product {
display: inline-block;
float: left;
width: 29%;
margin-right: 0;
}
.page-template-template-homepage-php .site-main .columns-3 ul.products li.product:last-child,
.storefront-full-width-content .site-main .columns-3 ul.products li.product:last-child {
margin-right: 0;
}
Other CSS:
storefront style.css
ol, ul {
margin: 0 0 1.618em 3em;
padding: 0;
}
* {
box-sizing: border-box;
}
woocommerce.css
ul.products {
margin-left: 0;
clear: both;
}
ul.products:after, ul.products:before {
content: "";
display: table;
}
ul.products:after {
clear: both;
}
ul.products:after, ul.products:before {
content: "";
display: table;
}
Custom PHP (in child theme)
storefront-template-functions.php
if ( ! function_exists( 'storefront_oy6d_product_categories' ) ) {
/**
* Display Product Categories
* Hooked into the `homepage` action in the homepage template
*
* #since 1.0.0
* #param array $args the product section args.
* #return void
*/
function storefront_oy6d_product_categories( $args ) {
if ( is_woocommerce_activated() ) {
$args = apply_filters( 'storefront_oy6d_product_categories_args', array(
'limit' => 3,
'columns' => 3,
'child_categories' => 0,
'orderby' => 'name',
'title' => __( 'Shop by Category', 'storefront' ),
) );
echo '<section class="storefront-oy6d-product-categories phone">';
do_action( 'storefront_homepage_before_product_categories' );
echo '<h2 class="section-title">' . wp_kses_post( $args['title'] ) . '</h2>';
do_action( 'storefront_homepage_after_product_categories_title' );
echo storefront_do_shortcode( 'product_categories', array(
'number' => intval( $args['limit'] ),
'columns' => intval( $args['columns'] ),
'orderby' => esc_attr( $args['orderby'] ),
'parent' => esc_attr( $args['child_categories'] ),
) );
do_action( 'storefront_homepage_after_product_categories' );
echo '</section>';
}
}
}
Rendered HTML
<ul class="products">
<li class="product-category product">
<a href="https://test.onyour6designs.com/product-category/gun-holsters/">
<div class="pso-wrap">
<img src="//test.onyour6designs.com/wp-content/uploads/2016/09/custom-gun-holsters-420x350.jpg" alt="Holsters" width="420" height="535" /></a>
<div class="pso-title">
<h3>Holsters <mark class="count">(21)</mark> </h3>
</div>
</div>
</li>
<li class="product-category product first">
<a href="https://test.onyour6designs.com/product-category/magazine-holsters/">
<div class="pso-wrap">
<img src="//test.onyour6designs.com/wp-content/uploads/2014/09/OnYour6Designs_Ruger_SR22_Holster-5-420x535.jpg" alt="Mag Holsters" width="420" height="535" />
</a>
<div class="pso-title">
<a href="https://test.onyour6designs.com/product-category/magazine-holsters/">
<h3>Mag Holsters <mark class="count">(13)</mark> </h3>
</a>
</div>
</div>
</li>
<li class="product-category product last">
<a href="https://test.onyour6designs.com/product-category/on-your-6-gear/">
<div class="pso-wrap">
<img src="//test.onyour6designs.com/wp-content/uploads/2015/06/Gear-420x535.png" alt="On Your 6 Gear" width="420" height="535" />
</a>
<div class="pso-title">
<a href="https://test.onyour6designs.com/product-category/on-your-6-gear/">
<h3>On Your 6 Gear <mark class="count">(2)</mark> </h3>
</a>
</div>
</div>
</li>
</ul>
UPDATE: I disabled my child theme stylesheet, but the issue persists. I switched to the parent theme, and the category items display in a single row. I have only one stylesheet for the child theme.
UPDATE: Thoroughly checked the custom PHP function for syntax errors and found none.
UPDATE: I removed all custom functions and hooks from the child theme, but still have this problem. it seems like it might have to do with my template-homepage.php file, but I am not sure why. The only change I made to it was to substitute my hooks for the custom storefront template functions.
It's important to include the relevant HTML as well when asking a question like this. I'm including the HTML for the product category section you mentioned here:
<ul class="products">
<li class="product-category product">
<a href="https://test.onyour6designs.com/product-category/gun-holsters/">
<div class="pso-wrap">
<img src="//test.onyour6designs.com/wp-content/uploads/2016/09/custom-gun-holsters-420x350.jpg" alt="Holsters" width="420" height="535" /></a>
<div class="pso-title">
<h3>Holsters <mark class="count">(21)</mark> </h3>
</div>
</div>
</li>
<li class="product-category product first">
<a href="https://test.onyour6designs.com/product-category/magazine-holsters/">
<div class="pso-wrap">
<img src="//test.onyour6designs.com/wp-content/uploads/2014/09/OnYour6Designs_Ruger_SR22_Holster-5-420x535.jpg" alt="Mag Holsters" width="420" height="535" />
</a>
<div class="pso-title">
<a href="https://test.onyour6designs.com/product-category/magazine-holsters/">
<h3>Mag Holsters <mark class="count">(13)</mark> </h3>
</a>
</div>
</div>
</li>
<li class="product-category product last">
<a href="https://test.onyour6designs.com/product-category/on-your-6-gear/">
<div class="pso-wrap">
<img src="//test.onyour6designs.com/wp-content/uploads/2015/06/Gear-420x535.png" alt="On Your 6 Gear" width="420" height="535" />
</a>
<div class="pso-title">
<a href="https://test.onyour6designs.com/product-category/on-your-6-gear/">
<h3>On Your 6 Gear <mark class="count">(2)</mark> </h3>
</a>
</div>
</div>
</li>
</ul>
There's several things going on here:
If you inspect the output, you'll find that for some reason, the second product is getting the class of first.
Part of the styles for first are clear: both !important;, which forces it below the first product, which is float: left.
I personally dislike floats in this situation, so I would recommend adjusting the styles for .product to float: none, and keeping the display: inline-block.
Note that the styles that appeared to work for me when fiddling with it are:
.page-template-template-homepage-php .site-main .columns-3 ul.products li.product,
.storefront-full-width-content .site-main .columns-3 ul.products li.product {
display: inline-block;
float: none;
width: 29%;
margin-right: 0;
vertical-align: top;
}
Others may tell you that using flexbox is the answer, and I wouldn't disagree - it's just not my "go to" method. (If you anticipate having more than 3 categories, and there's a risk that the category items may have different heights, then flexbox is the right way to go).
As a side-note, this style that you have at line 26 in your stylesheet:
* {
box-sizing: border-box;
}
Is a very "dangerous" rule. I had a problem arise on a site that took hours to sort out which was caused by this exact rule.
I would caution you strongly against * rules. The only one I ever use * for is to reset margin and padding to 0.
Lastly - note that your markup is incorrect within your product li elements. The a tag opens, then a div tag opens, then the a tag closes before the div tag close. Assuming you are using HTML5 -the markup could be cleaned up and simplified like so:
<li class="product-category product last">
<a href="https://test.onyour6designs.com/product-category/on-your-6-gear/">
<div class="pso-wrap">
<img src="//test.onyour6designs.com/wp-content/uploads/2015/06/Gear-420x535.png" alt="On Your 6 Gear" width="420" height="535" />
<div class="pso-title">
<h3>On Your 6 Gear <mark class="count">(2)</mark></h3>
</div>
</div>
</a>
</li>
(if you are not using HTML5 then it is not legal / correct to wrap an a tag around a div tag)

Resources