On woocommerce single product page, the default for gallery thumbnails appears under active image in rows. Currently for me it's displaying 4 images per row.
I believe Woocommerce uses flexslider for product page slider.
So since we are going to have lots of images for each product, I'm looking to add slider navigation to the product gallery while avoiding another plugin. As a result, the product gallery will then show all images on only 1 single row.
Like flexslider2
What would be the best way to achieve this? - Can it be done with pure CSS or would one need to add slider navigation using WordPress filters and CSS?
CSS
flex-control-thumbs {
width: 90%;
position: absolute;
bottom: 0px;
text-align: center;
display:flex;
flex-wrap:nowrap;
border: 1px solid red;
overflow-x:auto;
padding-bottom:10px;
}
.flex-control-thumbs li {
margin: 0 6px;
display: inline-block;
zoom: 1;
}
.flex-control-thumbs li,
.flex-control-thumbs li:first-child {
width: 16%;
vertical-align: top;
margin: 5px 1% 0 0;
min-width: 100px;
}
.flex-control-thumbs img {
width: 100%;
display: block;
opacity: 0.8;
cursor: pointer;
}
.flex-control-thumbs img:hover {
opacity: 0.5;
}
.flex-control-thumbs .flex-active {
opacity: 1;
cursor: default;
}
.product_slider .flex-active-slide a:hover {
cursor: -webkit-zoom-in;
cursor: -moz-zoom-in;
}
Outer HTML from WC
<ol class="flex-control-nav flex-control-thumbs">
<li><img src="image.jpeg" class="flex-active" draggable="false" /></li>
<li><img src="image.jpeg" draggable="false" /></li>
<li><img src="image.jpeg" draggable="false" /></li>
<li><img src="image.jpeg" draggable="false" /></li>
<li><img src="image.jpeg" draggable="false" /></li>
<li><img src="image.jpeg" draggable="false" /></li>
</ol>
// Add slider navigation using WordPress filters.
add_filter( 'woocommerce_single_product_carousel_options', 'cuswoo_update_woo_flexslider_options' );
/**
* Filer WooCommerce Flexslider options - Add Navigation Arrows
*/
function cuswoo_update_woo_flexslider_options( $options ) {
$options['directionNav'] = true;
return $options;
}
UPDATE
Here is CSS for the Navigation controls / for the Fliter above (next & previous image).
ul.flex-direction-nav {
position: absolute;
top: 30%;
z-index: 99999;
width: 100%;
left: 0;
margin: 0;
padding: 0px;
list-style: none;}
li.flex-nav-prev {float: left;}
li.flex-nav-next {float: right;}
a.flex-next {visibility:hidden;}
a.flex-prev {visibility:hidden;}
a.flex-next::after {visibility:visible;content: '\f105';
font-family: FontAwesome;margin-right: 10px;font-size: 70px; }
a.flex-prev::before {
visibility:visible;
content: '\f104';
font-family: FontAwesome; margin-left: 10px;font-size: 70px;}
to solve this you need to add a horizontal slider if thumbnails are many, and some more CSS grid code to make it responsive and spaced properly, I hope you find this useful.
.woocommerce-product-gallery {
display: grid;
gap: 10px }
#media only screen and (max-width: 35.999em) {
.woocommerce-product-gallery {
gap: 6px;
}
}
.woocommerce-product-gallery .flex-control-thumbs {
display: grid;
grid-auto-flow: column;
grid-auto-columns: 17%;
gap: 1rem;
overflow-x: auto !important;
overscroll-behavior-inline: contain;
}
#media screen and (max-width: 47.999em) {
.woocommerce-product-gallery .flex-control-thumbs {
grid-auto-columns: 12.5%;
gap: 6px;
}
}
.woocommerce-product-gallery .flex-control-thumbs li {
float: none !important;
width: 100% !important;
display: grid;
}
.woocommerce-product-gallery .flex-control-thumbs li img {
inline-size: 100%;
aspect-ratio: 1/1;
-o-object-fit: cover;
object-fit: cover;
border-radius: 5px;
}
.woocommerce-product-gallery .flex-control-thumbs li img.flex-active {
border: 5px solid #f2f2f2;
}
#media screen and (max-width: 47.999em) {
.woocommerce-product-gallery .flex-control-thumbs li img.flex-active {
border: 2px solid #f2f2f2; }
}
.woocommerce-product-gallery .flex-control-nav {
-ms-scroll-snap-type: inline mandatory;
scroll-snap-type: inline mandatory;
scroll-padding-inline: 10px;
}
.woocommerce-product-gallery .flex-control-nav > * {
scroll-snap-align: start;
}
if you wish to also add the navigation the code is easy if need help I can assist
Cheers!
Related
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
I created a grid using the Pods plugin. For some reason, there are extra pixels at the bottom of each div (see the white space). I've gone through the code multiple times and cannot find a reason for this. Below is the css for the grid. Would anyone know where the white space is coming from?
link: http://test.mpluczenik.com/#work
Thank you!
Functions.php:
// Add Image size for Portfolio List
if ( function_exists( 'add_theme_support' ) ) {
add_theme_support( 'post-thumbnails' );
// additional image sizes
add_image_size('portfolio-thumb', 300, 300, true ); // (cropped)
}
Pods template:
<div class="portfolio-list">
<a href="{#permalink}">
<div class="overlay">
<a href="{#permalink}">{#post_thumbnail.portfolio-thumb}
</a>
<p>
<a href="{#permalink}">{#post_title}
</a>
</p>
</div>
</a>
CSS:
div .portfolio-list{
border: 0px;
padding: 0px;
width: calc(20%);
overflow: hidden;
position: relative;
display: inline-block;
float:left;
}
img.attachment-portfolio-thumb{
width:100% !important;
height:100%!important;
}
div .portfolio-list p{
display: none;
color:#000;
}
div .overlay:hover:after {
content: ' ';
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
background-color: rgba(234,79,38,.75);
width: 100%;
height: 100%;
border:none;
margin:0;
padding:0;
}
div .portfolio-list:hover p {
display:block;
z-index: 9999;
position:absolute;
bottom:50px;
left:0px;
text-align: center;
width:100%;
overflow:hidden;
color:#fff;
margin: 0px;
}
div .portfolio-list:hover a{
color:#fff;
font-weight: bold;
opacity: 50%;
}
Thank you!
An inline block has a line height and that is where the extra space is coming from. You can remove the line hight by adding line-height: 0 to your css selector div .portfolio-list. More info here.
I have a menu bar like this
<header>
<nav>
Home
Our Story
Tools
Technology
Pricing
Contact
Careers
</nav>
</header>
The CSS is follows
header {
position: fixed;
width: 100%;
height: 65px;
opacity: 0.8;
background-color: #fcfcfc;
border-bottom: 5px solid #53bf6b;
z-index: 10;
}
header nav {
padding-top: 10px;
text-align: center;
}
header nav a {
text-decoration: none;
font-family: 'Roboto', sans-serif;
font-weight: 300;
font-size: 26px;
padding-right: 20px;
color: #f35626;
background-image: -webkit-linear-gradient(92deg, #f35626, #feab3a);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
-webkit-animation: hue 60s infinite linear;
}
And when the user resizes I want to Nav A to be followed below (align vertically) How can I do this ?
#media only screen and (min-width: 150px) and (max-width: 550px) {
/* I must set the code to arrange the nav a items here */
}
What should I do to make the nav a items follow each other vertically when resized ?
Use display block like there:
http://jsfiddle.net/c0y518bn/
#media only screen and (min-width: 150px) and (max-width: 550px) {
nav a {display: block;}
}
Fixed border-bottom version: http://jsfiddle.net/c0y518bn/1/
header nav a {
display: block; /* you can also try position:relative; */
}
I have this code for my header.php
<!DOCTYPE html>
<html>
<head>
<title>Responsive Navigation Demo</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" href="normalize.css">
<link rel="stylesheet" href="style.css">
<link href='http://fonts.googleapis.com/css?family=PT+Sans:400,700' rel='stylesheet' type='text/css'>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script>
$(function() {
var pull = $('#pull');
menu = $('nav ul');
menuHeight = menu.height();
$(pull).on('click', function(e) {
e.preventDefault();
menu.slideToggle();
});
$(window).resize(function(){
var w = $(window).width();
if(w > 320 && menu.is(':hidden')) {
menu.removeAttr('style');
}
});
});
</script>
</head>
<body>
<div class="desktop">
<a href="index.php">
<img border="0" class="logo" src="/images/logo.png" width="15%" height="20%" /></a> <font size="15%"><div class="BDtext">title<br> Description</font></div><br>
</div>
<div class="mobile">
<a href="index.php">
<img border="0" class="mobilogo" src="/images/logo.png" width="15%" height="20%" /></a>
</div>
<nav class="clearfix">
<ul class="clearfix">
<li class="home">Home</li>
<li class="about">About</li>
<li class="me">About Me</li>
<li class="sessions">Sessions</li>
</ul>
Menu
</nav>
</body>
</html>
and this one in my style.css:
body {
background-color: #ece8e5;
}
.logo{
float: left;
}
.BDtext {
text-align: center;
}
/* Clearfix */
.clearfix:before,
.clearfix:after {
content: " ";
display: table;
}
.clearfix:after {
clear: both;
}
.clearfix {
*zoom: 1;
}
/* Menu */
#sub-header ul li:hover,
body.home li.home,
body.Ben li.Ben,
body.about li.about,
body.sessions li.sessions { background-color: #000;} /* Current Page Background Colour */
nav {
height: 40px;
width: 100%;
background: #455868; /* Menu Background Colour */
font-size: 11pt;
font-family: 'PT Sans', Arial, sans-serif;
font-weight: bold;
position: relative;
border-bottom: 2px solid #283744;
}
nav ul {
padding: 0;
margin: 0 auto;
width: 600px;
height: 40px;
}
nav li {
display: inline;
float: left;
}
nav a {
color: #fff;
display: inline-block;
width: 100px;
text-align: center;
text-decoration: none;
line-height: 40px;
text-shadow: 1px 1px 0px #283744;
}
nav li a {
border-right: 1px solid #576979;
box-sizing:border-box;
-moz-box-sizing:border-box;
-webkit-box-sizing:border-box;
}
nav li:last-child a {
border-right: 0;
}
nav a:hover, nav a:active {
background-color: #8c99a4; /* Hover Over A Page Background Colour */
}
nav a#pull {
display: none;
}
/*Styles for screen 600px and lower*/
#media screen and (max-width: 600px) {
nav {
height: auto;
}
nav ul {
width: 100%;
display: block;
height: auto;
}
nav li {
width: 50%;
float: left;
position: relative;
}
nav li a {
border-bottom: 1px solid #576979;
border-right: 1px solid #576979;
}
nav a {
text-align: left;
width: 100%;
text-indent: 25px;
}
}
/*Styles for screen 515px and lower*/
#media only screen and (max-width : 480px) {
nav {
border-bottom: 0;
}
nav ul {
display: none;
height: auto;
}
nav a#pull {
display: block;
background-color: #283744;
width: 100%;
position: relative;
}
nav a#pull:after {
content:"";
background: url('nav-icon.png') no-repeat;
width: 30px;
height: 30px;
display: inline-block;
position: absolute;
right: 15px;
top: 10px;
}
}
#media only screen and (max-width : 600px) {
.desktop {display:none;}
.mobilogo{
margin-right: 45%;
width:50%;
height: 50%;
}
}
#media only screen and (min-width : 601px) {
.mobile {display:none;}
}
/*Smartphone*/
#media only screen and (max-width : 320px) {
nav li {
display: block;
float: none;
width: 100%;
}
nav li a {
border-bottom: 1px solid #576979;
}
}
/* End Menu */
my problem is.
my .mobilogo code in my CSS will not center the image.
I need this image to appear in the center of the page and not be aligned to the left.
please can someone help tell me what is holding it back?
.mobile class could have text-align:center; if you don't want to use the text-align try the below:
Also you can give .mobilogo width and have margin:0 auto; to center it.
.mobilogo{
margin:0 auto;
width:50%;
height: 50%;
}
In order for the width and height to work with percentages you need to give the parent elements width and height.
Make your .mobilogo class block and give it margin: 0 auto like this. Even though it has a width of 50% you'll have to make it a block element to center it with margin: 0 auto, or else you'll have to specify the width in pixels.
Like this:
.mobilogo {
margin: 0 auto;
display: block;
}
I am using the Easy Slider plugin (http://cssglobe.com/post/4004/easy-slider-15-the-easiest-jquery-plugin-for-sliding) to scroll several lists. The plugin dynamically generates the controls for the lists. So there are two sets of controls showing up. I was wondering if I could bind the controls into a single set. I would like the single controls to slide/scroll both lists at the same time. The reason I am doing this I have 100% width background that I want to scroll the same time as a "feature" div inside my wrapper. The layout/css is working great - just need a hand with the js.
FUNCTION
<script>
$(document).ready(function(){
$("#slides, #slideTop").easySlider({
auto: true,
continuous: true,
numeric: true
});
});
</script>
HTML
<div id="slides">
<ul>
<li class="slideOne"></li>
<li class="slideTwo"></li>
<li class="slideThree"></li>
</ul>
</div>
<div class="container_16">
<div class="grid_16">
<div id="slideTop">
<ul>
<li>One</li>
<li>Two</li>
<li>Three</li>
</ul>
</div>
CSS
#slideTop{
width:940px;
height: 350px;
background-color: #ccc;
position: absolute;
z-index: 9999;
overflow: hidden;
}
#slides{
width:100%;
height: 350px;
background-color: blue;
margin: 0 auto;
position: absolute;
top:144px;
z-index: -9999;
overflow: hidden;
}
#slideTop ul {
padding:0;
width: 940px;
height: 350px;
}
#slideTop ul li {
height:350px;
list-style:none;
width: 940px;
}
#slides ul {
margin: 0 auto;
padding:0;
width: 100%;
height: 350px;
}
#slides ul li {
margin:0;
padding:0;
height:350px;
list-style:none;
width:4000px;
float: left;
}
.slideOne {
background: url(images/one.gif) repeat-x;
width: 100%;
height: 350px;
}
.slideTwo {
background: url(images/two.gif) repeat-x;
width: 100%;
height: 350px;
}
.slideThree {
background: url(images/three.gif) repeat-x;
width: 100%;
height: 350px;
}
ul#controls {
height:21px;
padding:0;
width:100px;
position:absolute;
z-index:500;
top:620px;
float:left;
margin-left:430px
}
ul#controls li {
float:left;
height:21px;
list-style-type:none;
margin:0;
padding:0 3px;
width:21px
}
ul#controls li a {
background:url(images/ss.png) no-repeat 0 0;
display:block;
float:left;
height:21px;
width:21px;
border:none
}