this is my code i want to give different colors to comments
like grey(#eee) to odd and blue (#e6f9ff) to even
here this line is giving me error
background-color: {{ bg_color }}
{% extends 'base.html' %}
{% block content %}
<h1>{% block title %} Comments {% endblock %}</h1>
<div style="width: 50%; margin: auto">
{% for comment in comments %}
{% if loop.index % 2 == 0 %}
{% set bg_color = '#e6f9ff' %}
{% else %}
{% set bg_color = '#eee' %}
{% endif %}
<div style="padding: 10px; background-color: {{ bg_color }}; margin: 20px">
<p>#{{ loop.index }}</p>
<p style="font-size: 24px">{{ comment }}</p>
</div>
{% endfor %}
</div>
{% endblock %}
I think jinja version is updated and my course which Im following is old
so anyone who knows to answer me
You should note the scope for the variables. If you define a variable within an if-else block, it is only valid there.
<div style="width: 50%; margin: auto">
{% for comment in comments -%}
{% set bg_color = '#e6f9ff' if loop.index % 2 == 0 else '#eee' %}
<div style="padding: 10px; background-color: {{ bg_color }}; margin: 20px">
<p>#{{ loop.index }}</p>
<p style="font-size: 24px">{{ comment }}</p>
</div>
{% endfor -%}
</div>
Instead of using jinja you can also use css to assign a different background color to every other line.
<div class="comments">
{% for comment in comments -%}
<div>
<p>#{{ loop.index }}</p>
<p class="text">{{ comment }}</p>
</div>
{% endfor -%}
</div>
<style type="text/css">
.comments {
width: 50%;
margin: auto;
}
.comments div {
padding: 10px;
background-color: #e6f9ff;
margin: 20px
}
.comments div:nth-child(odd) {
background-color: #eee;
}
.comments .text {
font-size: 24px
}
</style>
i'm trying to use htmx's infinite scroll but it doesn't work properly
<body>
<div class="container">
{% block content %}
<div
{% if products.has_next %}
hx-get="?page={{ products.next_page_number }}"
hx-trigger="revealed"
hx-swap="afterend"
{% endif %}
>
{% include 'includes/cards.html' %}
</div>
{% include 'includes/sidebar.html' %}
{% endblock content %}
</div>
</body>
when i scrolled down product cards sliding to right slightly
and gets smaller on mobile like this
and this:
to this :
can you guys help me understand what im doing wrong please?
i also tried https://infinite-scroll.com/
its perfectly working.
Edit:
views.py
def shop(request):
anabanner = AnaBanner.objects.all()
gender = Gender.objects.all()
categories = Category.objects.all()
colors = Color.objects.all()
materials = Material.objects.all()
query = request.GET.get('query','')
products = Product.objects.all().order_by('-pk')
if query:
products = products.filter(
Q(name__icontains=query)|
Q(sub_name__icontains=query)
).distinct()
paginator = Paginator(products, 8)
page = request.GET.get('page')
cards.html
{% load static %}
{% block content %}
<body>
{% for product in products %}
<div class="product-card">
<a href="{% url 'productpage' product.slug %}"><div class="main-images">
<img id="black" class="black active" loading="lazy" src="{{product.imageURL}}" alt="blue">
</div></a>
<div class="shoe-details">
<span class="shoe_name">
<a href="{% url 'productpage' product.slug %}"><p style="display: -webkit-box;-webkit-line-clamp: 1;-webkit-box-orient: vertical;font-size: 16px;
font-weight: 500;
color: #161616;width: 100%;overflow: hidden;/* white-space: nowrap; */text-overflow: ellipsis;">{{product.name}}</p></a>
</span>
</div>
<div class="price">
<span class="price_num">{{product.price|floatformat:2}}TL</span>
</div>
</div>
{% if product.stock > 0 %}
<div class="button">
<div class="button-layer"></div>
<button name="ekle"
href ="#"
hx-get="{% url 'add_to_cart' product.id %}"
hx-target="#menu-cart-button"
hx-swap="outerHTML"
class="btn btn-outline-secondary add-btn update-cart">Sepete Ekle</button>
</div>
{% else %}
<div class="button">
<div class="button-layer"></div>
<button name="ekle"
href ="#"
hx-get="{% url 'add_to_cart' product.id %}"
hx-target="#menu-cart-button"
hx-swap="outerHTML"
class="btn btn-outline-secondary add-btn update-cart">Sepete Ekle</button>
</div>
{% endif %}
</div>
{% endfor %}
</body>
{% endblock %}
cards.css ( i tried deleting paddings it didnt work. )
.product-card {
display: inline-block;
position: relative;
left: 100px;
top:150px;
max-width: 355px;
width: 100%;
border-radius: 25px;
padding: 20px 30px 30px 30px;
background: #fff;
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
z-index: 3;
overflow: hidden;
}
I'm working with a shopify theme, and I'm trying to display an Add To Cart button on top of my product image when a user hovers over it. That said, the 'hover' aspect is already active on the product image using the following CSS. In short, when I currently hover over a product image, it simply lowers the opacity to 0.7. That said, I can't seem to figure out how to write HTML for .grid-product__image-link if I want a button or an image to appear on hover instead? Help is appreciated!
Current HTML
<div class="grid__item grid-product {{ grid_item_width }}{% if sold_out %} is-sold-out{% endif %}">
<div class="grid-product__wrapper">
<div class="grid-product__image-wrapper">
<a class="grid-product__image-link{% unless featured_image.src == blank %} grid-product__image-link--loading{% endunless %}" href="{{ product.url | within: collection }}" data-image-link>
{% if featured_image.src == blank %}
<img class="grid-product__image" src="{{ featured_image.src | img_url: '1024x' }}" alt="{{ featured_image.alt | escape }}">
{% else %}
{% include 'image-style' with image: featured_image, small_style: true, width: width, height: height, wrapper_id: img_wrapper_id, img_id_class: img_id_class %}
<div id="{{ img_wrapper_id }}" class="product--wrapper">
<div style="padding-top:{{ 1 | divided_by: featured_image.aspect_ratio | times: 100 }}%;">
<img class="product--image lazyload {{ img_id_class }}"
data-src="{{ img_url }}"
data-widths="[180, 370, 590, 740, 900, 1080, 1296, 1512, 1728, 2048]"
data-aspectratio="{{ featured_image.aspect_ratio }}"
data-sizes="auto"
alt="{{ featured_image.alt | escape }}"
data-image>
</div>
</div>
<noscript>
<img class="grid-product__image" src="{{ featured_image.src | img_url: '1024x' }}" alt="{{ featured_image.alt | escape }}">
</noscript>
{% endif %}
</a>
{% if sold_out %}
<div class="grid-product__sold-out">
<p>{{ 'products.product.sold_out_html' | t }}</p>
</div>
{% elsif on_sale %}
<div class="grid-product__on-sale">
{% capture saved_amount %}{{ product.compare_at_price | minus: product.price | money_without_trailing_zeros }}{% endcapture %}
<p>{{ 'products.general.save_html' | t: saved_amount: saved_amount }}</p>
</div>
{% endif %}
</div>
CSS
.grid-product__wrapper {
text-align: center;
margin-bottom: $gutter;
.grid-collage & {
margin-bottom: 0;
}
}
.grid-product__image-wrapper {
position: relative;
width: 100%;
display: table;
table-layout: fixed;
}
.grid-product__image-link {
position: relative;
display: block;
width: 100%;
background-color: $colorProductBackground;
#include transition(opacity 0.4s ease-out);
.grid-collage & {
padding: 0 20px;
}
&:hover,
&:focus {
opacity: 0.7;
#include transition(opacity 0.15s ease-in);
}
}
If I correctly understand you, maybe this will help you :)
Html:
<a class="grid-product__image-link>
<div class = "product-overlay"></div>
</a>
Scss:
.grid-product__image-link {
position: relative;
display: block;
width: 100%;
background-color: $colorProductBackground;
#include transition(opacity 0.4s ease-out);
.grid-collage & {
padding: 0 20px;
}
.product-overlay{
display:none;
}
&:hover,
&:focus {
opacity: 0.7;
#include transition(opacity 0.15s ease-in);
.product-overlay{
display:block;
}
}
}
I would use javascript to make another html <img> or <button> element popup with a higher z-index property when your mouse gets on top of that image, but I'm not sure if that works for you.
I am using shopify theme 'Pop' which comes with a Slick Slider Hero. When the slideshow is opened on a mobile device, it automatically crops my images which I don't want because I added text to the image so it cuts it off (view pic attached)
Please let me know what code to add to what liquid/css file so that it resizes picture instead of cutting it off.
Thank you so much!
Theme code
<div data-section-id="{{ section.id }}" data-section-type="slideshow-section">
{% if section.blocks.size > 0 %}
<div class="slideshow-wrapper">
<button type="button" class="visually-hidden slideshow__pause" data-id="{{ section.id }}" aria-live="polite">
<span class="slideshow__pause-stop">
{% include 'icon-pause' %}
<span class="icon__fallback-text">{{ 'sections.slideshow.pause_slideshow' | t }}</span>
</span>
<span class="slideshow__pause-play">
{% include 'icon-play' %}
<span class="icon__fallback-text">{{ 'sections.slideshow.play_slideshow' | t }}</span>
</span>
</button>
<div class="slideshow slideshow--{{ section.settings.slideshow_height }}" id="Slideshow-{{ section.id }}" data-autoplay="{{ section.settings.autoplay }}" data-speed="{{ section.settings.autoplay_speed }}">
{% for block in section.blocks %}
{%- assign is_background_video = false -%}
{% if block.type == 'video' %}
{% if block.settings.video_type == 'background' or block.settings.video_type =='background-chrome' %}
{%- assign is_background_video = true -%}
{% endif %}
{% endif %}
<div class="slideshow__slide slideshow__slide--{{ block.id }}{% if is_background_video %} slideshow__slide--background-video{% endif %}" {{ block.shopify_attributes }}>
{% if block.settings.link != blank %}
<a href="{{ block.settings.link }}" class="slideshow__link">
{% endif %}
{% if block.type == 'video' %}
{% if block.settings.video_url != blank %}
<div class="video-loader"></div>
{% endif %}
{% unless block.settings.video_type == 'background' %}
<button type="button" class="text-link slideshow__video-control slideshow__video-control--close" data-controls="SlideshowVideo-{{ block.id }}">
{% include 'icon-close' %}
<span class="icon__fallback-text">{{ 'sections.slideshow.close_video' | t }}</span>
</button>
{% endunless %}
{% if block.settings.video_url != blank %}
<div id="SlideshowVideo-{{ block.id }}" class="slideshow__video {% if is_background_video %}slideshow__video--background{% endif %} slideshow__video--{{ block.settings.video_type }}"
data-id="{{ block.settings.video_url.id }}"
data-type="{{ block.settings.video_type }}"
data-slideshow="Slideshow-{{ section.id }}"></div>
{% endif %}
{% endif %}
{% if block.settings.image == blank %}
<div class="slideshow__image js">
<div class="placeholder-background">
{% capture current %}{% cycle 1, 2 %}{% endcapture %}
{{ 'lifestyle-' | append: current | placeholder_svg_tag: 'placeholder-svg' }}
</div>
</div>
{% else %}
<div class="slideshow__image box ratio-container lazyload{% unless forloop.first == true %} lazypreload{% endunless %} js"
data-bgset="{% include 'bgset', image: block.settings.image %}"
data-sizes="auto"
data-parent-fit="cover"
style="background-position: {{ block.settings.alignment }};{% if forloop.first == true %} background-image: url('{{ block.settings.image | img_url: '300x300' }});{% endif %}">
</div>
{% endif %}
<noscript>
<div class="slideshow__image"{% if block.settings.image %} style="background-image: url('{{ block.settings.image | img_url: '2048x' }}'); background-position: {{ block.settings.alignment }};"{% endif %}>
{% if block.settings.image == blank %}
<div class="placeholder-background">
{% capture current %}{% cycle 1, 2 %}{% endcapture %}
{{ 'lifestyle-' | append: current | placeholder_svg_tag: 'placeholder-svg' }}
</div>
{% endif %}
</div>
</noscript>
<div class="slideshow__text-wrap{% if block.settings.title != blank or block.settings.subheading != blank %} slideshow__overlay{% endif %}">
<div class="slideshow__text-content">
<div class="page-width">
{% unless block.settings.title == blank %}
<h2 class="h1 mega-title slideshow__title{% if settings.link != blank %} slideshow__title--has-link{% endif %}{% if section.settings.text_size == 'large' %} mega-title--large{% endif %}">
{{ block.settings.title | escape }}
</h2>
{% endunless %}
{% unless block.settings.subheading == blank %}
<span class="mega-subtitle slideshow__subtitle{% if section.settings.text_size == 'large' %} mega-subtitle--large{% endif %}">
{{ block.settings.subheading | escape }}
</span>
{% endunless %}
{% if block.type == 'video' %}
{% unless block.settings.video_type == 'background' %}
<div class="slideshow__video-control--play-wrapper{% if block.settings.title != blank or block.settings.subheading != blank %} slideshow__video-control--play-wrapper--push{% endif %}">
<button type="button" class="text-link slideshow__video-control slideshow__video-control--play" data-controls="SlideshowVideo-{{ block.id }}">
{% include 'icon-play-video' %}
<span class="icon__fallback-text">{{ 'sections.slideshow.play_video' | t }}</span>
</button>
</div>
{% endunless %}
{% endif %}
</div>
</div>
</div>
{% if block.settings.link != blank %}
</a>
{% endif %}
</div>
{% endfor %}
</div>
</div>
{% endif %}
{% if section.blocks.size == 0 %}
<div class="placeholder-noblocks">
{{ 'homepage.onboarding.no_content' | t }}
</div>
{% endif %}
</div>
Generated HTML Code
<div id="shopify-section-1531416277337" class="shopify-section index-section index-section--flush" data-theme-editor-section-36470275618="{"id":"1531416277337","type":"slideshow","disabled":false}">
<div data-section-id="1531416277337" data-section-type="slideshow-section">
<div class="slideshow-wrapper">
<button type="button" class="visually-hidden slideshow__pause" data-id="1531416277337" aria-live="polite">
<span class="slideshow__pause-stop">
<svg aria-hidden="true" focusable="false" role="presentation" class="icon icon-pause" viewBox="0 0 10 13"><g fill="#000" fill-rule="evenodd"><path d="M0 0h3v13H0zM7 0h3v13H7z"></path></g></svg>
<span class="icon__fallback-text">Pause slideshow</span>
</span>
<span class="slideshow__pause-play">
<svg aria-hidden="true" focusable="false" role="presentation" class="icon icon-play" viewBox="0 0 18 32"><path d="M.263 0l17.071 15.944L.264 31.89" fill="#444" fill-rule="evenodd"></path></svg>
<span class="icon__fallback-text">Play slideshow</span>
</span>
</button>
<div class="slideshow slideshow--medium slick-initialized slick-slider slick-dotted" id="Slideshow-1531416277337" data-autoplay="true" data-speed="5000">
<div class="slick-list draggable">
<div class="slick-track" style="opacity: 1; width: 750px;">
<div class="slideshow__slide slideshow__slide--1531416277337-0 slick-slide slick-current slick-active" data-slick-index="0" aria-hidden="false" role="tabpanel" id="slickSlide10" aria-labelledby="slickDot10" tabindex="-1" data-theme-editor-block-36470275618="{"id":"1531416277337-0","type":"image"}" style="width: 375px; position: relative; left: 0px; top: 0px; z-index: 999; opacity: 1;">
<div class="slideshow__image box ratio-container js lazyloaded" data-bgset="//cdn.shopify.com/s/files/1/2543/3412/files/beach_trash2_3c79e4e7-49ad-4ef3-ace0-103c1d531b66_180x.jpg?v=1531416305 180w 114h,
//cdn.shopify.com/s/files/1/2543/3412/files/beach_trash2_3c79e4e7-49ad-4ef3-ace0-103c1d531b66_360x.jpg?v=1531416305 360w 228h,
//cdn.shopify.com/s/files/1/2543/3412/files/beach_trash2_3c79e4e7-49ad-4ef3-ace0-103c1d531b66_540x.jpg?v=1531416305 540w 342h,
//cdn.shopify.com/s/files/1/2543/3412/files/beach_trash2_3c79e4e7-49ad-4ef3-ace0-103c1d531b66_720x.jpg?v=1531416305 720w 456h,
//cdn.shopify.com/s/files/1/2543/3412/files/beach_trash2_3c79e4e7-49ad-4ef3-ace0-103c1d531b66_900x.jpg?v=1531416305 900w 571h,
//cdn.shopify.com/s/files/1/2543/3412/files/beach_trash2_3c79e4e7-49ad-4ef3-ace0-103c1d531b66_1080x.jpg?v=1531416305 1080w 685h,
//cdn.shopify.com/s/files/1/2543/3412/files/beach_trash2_3c79e4e7-49ad-4ef3-ace0-103c1d531b66_1296x.jpg?v=1531416305 1296w 822h,
//cdn.shopify.com/s/files/1/2543/3412/files/beach_trash2_3c79e4e7-49ad-4ef3-ace0-103c1d531b66_1512x.jpg?v=1531416305 1512w 958h,
//cdn.shopify.com/s/files/1/2543/3412/files/beach_trash2_3c79e4e7-49ad-4ef3-ace0-103c1d531b66_1728x.jpg?v=1531416305 1728w 1095h,
//cdn.shopify.com/s/files/1/2543/3412/files/beach_trash2_3c79e4e7-49ad-4ef3-ace0-103c1d531b66.jpg?v=1531416305 1923w 1219h" data-parent-fit="cover" style="background-position: center bottom; background-image: url("https://cdn.shopify.com/s/files/1/2543/3412/files/beach_trash2_3c79e4e7-49ad-4ef3-ace0-103c1d531b66.jpg?v=1531416305");">
<picture style="display: none;">
<source data-srcset="//cdn.shopify.com/s/files/1/2543/3412/files/beach_trash2_3c79e4e7-49ad-4ef3-ace0-103c1d531b66_180x.jpg?v=1531416305 180w 114h, //cdn.shopify.com/s/files/1/2543/3412/files/beach_trash2_3c79e4e7-49ad-4ef3-ace0-103c1d531b66_360x.jpg?v=1531416305 360w 228h, //cdn.shopify.com/s/files/1/2543/3412/files/beach_trash2_3c79e4e7-49ad-4ef3-ace0-103c1d531b66_540x.jpg?v=1531416305 540w 342h, //cdn.shopify.com/s/files/1/2543/3412/files/beach_trash2_3c79e4e7-49ad-4ef3-ace0-103c1d531b66_720x.jpg?v=1531416305 720w 456h, //cdn.shopify.com/s/files/1/2543/3412/files/beach_trash2_3c79e4e7-49ad-4ef3-ace0-103c1d531b66_900x.jpg?v=1531416305 900w 571h, //cdn.shopify.com/s/files/1/2543/3412/files/beach_trash2_3c79e4e7-49ad-4ef3-ace0-103c1d531b66_1080x.jpg?v=1531416305 1080w 685h, //cdn.shopify.com/s/files/1/2543/3412/files/beach_trash2_3c79e4e7-49ad-4ef3-ace0-103c1d531b66_1296x.jpg?v=1531416305 1296w 822h, //cdn.shopify.com/s/files/1/2543/3412/files/beach_trash2_3c79e4e7-49ad-4ef3-ace0-103c1d531b66_1512x.jpg?v=1531416305 1512w 958h, //cdn.shopify.com/s/files/1/2543/3412/files/beach_trash2_3c79e4e7-49ad-4ef3-ace0-103c1d531b66_1728x.jpg?v=1531416305 1728w 1095h, //cdn.shopify.com/s/files/1/2543/3412/files/beach_trash2_3c79e4e7-49ad-4ef3-ace0-103c1d531b66.jpg?v=1531416305 1923w 1219h" sizes="789.4736842105262px" srcset="//cdn.shopify.com/s/files/1/2543/3412/files/beach_trash2_3c79e4e7-49ad-4ef3-ace0-103c1d531b66_180x.jpg?v=1531416305 180w 114h, //cdn.shopify.com/s/files/1/2543/3412/files/beach_trash2_3c79e4e7-49ad-4ef3-ace0-103c1d531b66_360x.jpg?v=1531416305 360w 228h, //cdn.shopify.com/s/files/1/2543/3412/files/beach_trash2_3c79e4e7-49ad-4ef3-ace0-103c1d531b66_540x.jpg?v=1531416305 540w 342h, //cdn.shopify.com/s/files/1/2543/3412/files/beach_trash2_3c79e4e7-49ad-4ef3-ace0-103c1d531b66_720x.jpg?v=1531416305 720w 456h, //cdn.shopify.com/s/files/1/2543/3412/files/beach_trash2_3c79e4e7-49ad-4ef3-ace0-103c1d531b66_900x.jpg?v=1531416305 900w 571h, //cdn.shopify.com/s/files/1/2543/3412/files/beach_trash2_3c79e4e7-49ad-4ef3-ace0-103c1d531b66_1080x.jpg?v=1531416305 1080w 685h, //cdn.shopify.com/s/files/1/2543/3412/files/beach_trash2_3c79e4e7-49ad-4ef3-ace0-103c1d531b66_1296x.jpg?v=1531416305 1296w 822h, //cdn.shopify.com/s/files/1/2543/3412/files/beach_trash2_3c79e4e7-49ad-4ef3-ace0-103c1d531b66_1512x.jpg?v=1531416305 1512w 958h, //cdn.shopify.com/s/files/1/2543/3412/files/beach_trash2_3c79e4e7-49ad-4ef3-ace0-103c1d531b66_1728x.jpg?v=1531416305 1728w 1095h, //cdn.shopify.com/s/files/1/2543/3412/files/beach_trash2_3c79e4e7-49ad-4ef3-ace0-103c1d531b66.jpg?v=1531416305 1923w 1219h"><img alt="" class="lazyautosizes lazyloaded" data-sizes="auto" data-parent-fit="cover" sizes="789.4736842105262px"></picture>
</div>
<noscript>
<div class="slideshow__image" style="background-image: url('//cdn.shopify.com/s/files/1/2543/3412/files/beach_trash2_3c79e4e7-49ad-4ef3-ace0-103c1d531b66_2048x.jpg?v=1531416305'); background-position: bottom;">
</div>
</noscript>
<div class="slideshow__text-wrap">
<div class="slideshow__text-content">
<div class="page-width">
</div>
</div>
</div>
</div>
<div class="slideshow__slide slideshow__slide--1531416277337-1 slick-slide" data-slick-index="1" aria-hidden="true" role="tabpanel" id="slickSlide11" aria-labelledby="slickDot11" tabindex="-1" data-theme-editor-block-36470275618="{"id":"1531416277337-1","type":"image"}" style="width: 375px; position: relative; left: -375px; top: 0px; z-index: 998; opacity: 0; transition: opacity 500ms ease;">
<div class="slideshow__image box ratio-container lazypreload js lazyloaded" data-bgset="//cdn.shopify.com/s/files/1/2543/3412/files/bottles_180x.jpg?v=1531419269 180w 120h,
//cdn.shopify.com/s/files/1/2543/3412/files/bottles_360x.jpg?v=1531419269 360w 240h,
//cdn.shopify.com/s/files/1/2543/3412/files/bottles_540x.jpg?v=1531419269 540w 360h,
//cdn.shopify.com/s/files/1/2543/3412/files/bottles_720x.jpg?v=1531419269 720w 480h,
//cdn.shopify.com/s/files/1/2543/3412/files/bottles_900x.jpg?v=1531419269 900w 600h,
//cdn.shopify.com/s/files/1/2543/3412/files/bottles_1080x.jpg?v=1531419269 1080w 720h,
//cdn.shopify.com/s/files/1/2543/3412/files/bottles_1296x.jpg?v=1531419269 1296w 864h,
//cdn.shopify.com/s/files/1/2543/3412/files/bottles_1512x.jpg?v=1531419269 1512w 1008h,
//cdn.shopify.com/s/files/1/2543/3412/files/bottles_1728x.jpg?v=1531419269 1728w 1152h,
//cdn.shopify.com/s/files/1/2543/3412/files/bottles.jpg?v=1531419269 1920w 1280h" data-parent-fit="cover" style="background-position: center top; background-image: url("https://cdn.shopify.com/s/files/1/2543/3412/files/bottles.jpg?v=1531419269");">
<picture style="display: none;">
<source data-srcset="//cdn.shopify.com/s/files/1/2543/3412/files/bottles_180x.jpg?v=1531419269 180w 120h, //cdn.shopify.com/s/files/1/2543/3412/files/bottles_360x.jpg?v=1531419269 360w 240h, //cdn.shopify.com/s/files/1/2543/3412/files/bottles_540x.jpg?v=1531419269 540w 360h, //cdn.shopify.com/s/files/1/2543/3412/files/bottles_720x.jpg?v=1531419269 720w 480h, //cdn.shopify.com/s/files/1/2543/3412/files/bottles_900x.jpg?v=1531419269 900w 600h, //cdn.shopify.com/s/files/1/2543/3412/files/bottles_1080x.jpg?v=1531419269 1080w 720h, //cdn.shopify.com/s/files/1/2543/3412/files/bottles_1296x.jpg?v=1531419269 1296w 864h, //cdn.shopify.com/s/files/1/2543/3412/files/bottles_1512x.jpg?v=1531419269 1512w 1008h, //cdn.shopify.com/s/files/1/2543/3412/files/bottles_1728x.jpg?v=1531419269 1728w 1152h, //cdn.shopify.com/s/files/1/2543/3412/files/bottles.jpg?v=1531419269 1920w 1280h" sizes="750px" srcset="//cdn.shopify.com/s/files/1/2543/3412/files/bottles_180x.jpg?v=1531419269 180w 120h, //cdn.shopify.com/s/files/1/2543/3412/files/bottles_360x.jpg?v=1531419269 360w 240h, //cdn.shopify.com/s/files/1/2543/3412/files/bottles_540x.jpg?v=1531419269 540w 360h, //cdn.shopify.com/s/files/1/2543/3412/files/bottles_720x.jpg?v=1531419269 720w 480h, //cdn.shopify.com/s/files/1/2543/3412/files/bottles_900x.jpg?v=1531419269 900w 600h, //cdn.shopify.com/s/files/1/2543/3412/files/bottles_1080x.jpg?v=1531419269 1080w 720h, //cdn.shopify.com/s/files/1/2543/3412/files/bottles_1296x.jpg?v=1531419269 1296w 864h, //cdn.shopify.com/s/files/1/2543/3412/files/bottles_1512x.jpg?v=1531419269 1512w 1008h, //cdn.shopify.com/s/files/1/2543/3412/files/bottles_1728x.jpg?v=1531419269 1728w 1152h, //cdn.shopify.com/s/files/1/2543/3412/files/bottles.jpg?v=1531419269 1920w 1280h"><img alt="" class="lazyautosizes lazyloaded" data-sizes="auto" data-parent-fit="cover" sizes="750px"></picture>
</div>
<noscript>
<div class="slideshow__image" style="background-image: url('//cdn.shopify.com/s/files/1/2543/3412/files/bottles_2048x.jpg?v=1531419269'); background-position: top;">
</div>
</noscript>
<div class="slideshow__text-wrap">
<div class="slideshow__text-content">
<div class="page-width">
</div>
</div>
</div>
</div>
</div>
</div>
<ul class="slick-dots" style="display: block;" role="tablist">
<li class="slick-active" aria-hidden="false" role="tab" aria-selected="true" aria-controls="slickSlide10" id="slickDot10">
<button type="button" data-role="none" role="button" tabindex="0">Slide 1</button>
</li>
<li role="tab" aria-selected="false" aria-controls="slickSlide11" id="slickDot11" class="">
<button type="button" data-role="none" role="button" tabindex="0">Slide 2</button>
</li>
</ul>
</div>
</div>
</div>
</div>
CSS Code
/*================ Slick Slider SCSS ================*/
.slick-slider {
position: relative;
display: block;
box-sizing: border-box;
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
-ms-touch-action: pan-y;
touch-action: pan-y;
-webkit-tap-highlight-color: transparent;
}
.slick-list {
position: relative;
overflow: hidden;
display: block;
margin: 0;
padding: 0;
&:focus {
outline: none;
}
&.dragging {
cursor: pointer;
cursor: hand;
}
}
.slick-slider .slick-track,
.slick-slider .slick-list {
-webkit-transform: translate3d(0, 0, 0);
-moz-transform: translate3d(0, 0, 0);
-ms-transform: translate3d(0, 0, 0);
-o-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0);
}
.slick-track {
position: relative;
left: 0;
top: 0;
display: block;
&:before,
&:after {
content: "";
display: table;
}
&:after {
clear: both;
}
.slick-loading & {
visibility: hidden;
}
}
.slick-slide {
float: left;
height: 100%;
min-height: 1px;
[dir="rtl"] & {
float: right;
}
img {
display: block;
}
&.slick-loading img {
display: none;
}
display: none;
&.dragging img {
pointer-events: none;
}
.slick-initialized & {
display: block;
}
.slick-loading & {
visibility: hidden;
}
.slick-vertical & {
display: block;
height: auto;
border: 1px solid transparent;
}
}
.slick-arrow.slick-hidden {
display: none;
}
Example Image
I am trying to vertically center the contents of .onesizechart, which I have working in bothChrome and Safari, but does not work in either Firefox or IE. The contents of .homepage-sizechart are displaying fine which makes me think I am missing something very simple. Any ideas?
HTML/Liquid
<div class="medium-3 small-6 columns homepage-products left" onclick="location.href='{{ product.url }}'">
<div class="product-preview-image-div">
<a href="{{ product.url | within: collection }}">
<img src="{{ product.featured_image | product_img_url: 'grande' }}" alt="{{ product.title | escape }}" />
</a>
{% assign contains_os = false %}
{% for variant in product.variants %}
{% if variant.title contains 'OS' %}
{% assign contains_os = true %}
{% endif %}
{% endfor %}
{% if contains_os %}
<div class="onesizechart">
{% for variant in product.variants %}
{% if variant.inventory_quantity == 0 %}
<img src="{{ 'onesize-triangle-outofstock.png' | asset_url }}"/>
{% else %}
<img src="{{ 'onesize-triangle.png' | asset_url }}"/>
{% endif %}
{% endfor %}
</div>
{% else %}
<div class="homepage-sizechart">
<div class="sizes">
{{ 'size-triangle.png' | asset_url | img_tag }}
{% for variant in product.variants %}
<span class="{{ variant.title }}-product {% if variant.inventory_quantity == 0 %}outofstock{% endif %} {% if variant.title contains 'OS'%}hide{% endif %}">{{ variant.title }}</span>
{% endfor %}
</div>
</div>
{% endif %}
</div>
</div>
CSS
.homepage-products {
cursor: pointer;
margin-top: 20px;
}
.homepage-sizechart {
bottom: 0;
display: table-cell;
left: 0;
margin: auto;
opacity: 0;
position: absolute;
right: 0;
text-align: center;
top: 5%;
vertical-align: middle;
width: 90%;
z-index: 999;
}
.onesizechart {
opacity: 0;
position: absolute;
display: table;
width: 90%;
z-index: 999;
top: 5%;
bottom: 0;
right: 0;
margin: auto;
text-align: center;
}
.onesize {
display: table-cell;
vertical-align: middle;
}
.sizes {
position: relative;
}
You need to set your parent container to display:table; for the child elements using display:table-cell to inherit tabular like properties such as vertical-align.
HTML:
<div class="container">
<div class="panel">
hey
</div>
<div class="panel">
hey
</div>
</div>
CSS:
.container {
display:table;
height:100px;
}
.panel {
display:table-cell;
vertical-align:middle;
border:1px solid red;
}
Although you haven't provided the CSS for the .product-preview-image-div class above, I'm guessing that this is most likely the problem at play.
JSFiddle: http://jsfiddle.net/a4fyg/