Add Hover Feature On Product Image - html

I am trying to add a feature to show an alternative product picture when the cursor hovers over the product image in a collection view.
Whenever I view the page with the code below, the product images have shifted to the bottom of the container and also cover the Title/Price that was below them.
What can I correct to keep the pictures in their original alignment and have only the hover effect work?
Thank you!
Here is what I currently have in product-card-grid.liquid --
<div id="{{ wrapper_id }}" class="grid-view-item__image-wrapper js">
<div style="padding-top:{% unless product.featured_image == blank %}{{ 1 | divided_by: product.featured_image.aspect_ratio | times: 100}}%{% else %}100%{% endunless %};">
<div class="reveal">
<img id="{{ img_id }}"
class="grid-view-item__image lazyload"
src="{{ product.featured_image | img_url: '300x300' }}"
data-src="{{ img_url }}"
data-widths="[180, 360, 540, 720, 900, 1080, 1296, 1512, 1728, 2048]"
data-aspectratio="{{ product.featured_image.aspect_ratio }}"
data-sizes="auto"
alt="">
<img id="{{img_id}}"
class="hidden"
src="{{ product.images.last }}"
data-src="{{ img_url }} "
data-widths="[180, 360, 540, 720, 900, 1080, 1296, 1512, 1728, 2048]"
data-aspectratio="{{ product.featured_image.aspect_ratio }}"
data-sizes="auto"
alt="{{ product.images.last.alt | escape }}">
</div>
</div>
</div>
The css for "Reveal" is below:
/* ===============================================
// Reveal module
// =============================================== */
.reveal .hidden { display: block !important; visibility: visible !important;}
.product:hover .reveal img { opacity: 1; }
.reveal { position: relative; }
.reveal .hidden {
position: absolute;
z-index: -1;
top: 0;
width: 100%;
height: 100%;
opacity: 0;
-webkit-transition: opacity 0.3s ease-in-out;
-moz-transition: opacity 0.3s ease-in-out;
-o-transition: opacity 0.3s ease-in-out;
transition: opacity 0.3s ease-in-out;
}
.reveal:hover .hidden {
z-index: 100000;
opacity: 1;
}
.reveal .caption {
position: absolute;
top: 0;
display: table;
width: 100%;
height: 100%;
background-color: white; /* fallback for IE8 */
background-color: rgba(255, 255, 255, 0.7);
font: 13px/1.6 sans-serif;
text-transform: uppercase;
color: #333;
letter-spacing: 1px;
text-align: center;
text-rendering: optimizeLegibility;
}
.reveal .hidden .caption .centered {
display: table-cell;
vertical-align: middle;
}
#media (min-width: 480px) and (max-width: 979px) {
.reveal .caption {
font-size: 11px;
}
}

There's a lot going on in your CSS, but if I understand the sitaution correctly you want to achieve an effect like the one in this Codepen, right?
In your CSS, absolutely position two images inside of a div (with top: 0px and left: 0px) and change the opacity of the top image in the stack by hovering on the parent.
HTML:
<div class='reveal'>
<img src='image_src' class='bottom'>
<img src='image_src' class='top'>
</div>
CSS:
.top, .bottom {
position: absolute;
opacity: 1;
top: 0px;
left: 0px;
}
.frame:hover .top {
opacity: 0;
}
EDIT: Implementation w/ grid, as requested.
HTML:
<div class='grid'>
<div class='reveal'>
<img src='image_src' class='bottom'>
<img src='image_src' class='top'>
</div>
<div class='reveal'>
<img src='image_src' class='bottom'>
<img src='image_src' class='top'>
</div>
</div>
CSS:
.grid {
display: flex;
flex-wrap: wrap; /*makes the grid "responsive"*/
}
.reveal {
display: flex;
flex: 1 1 200px; /*last value must be picture width*/
height:200px; /* picture height*/
margin: 20px; /*aesthetic only*/
position: relative;
}
.top, .bottom {
position: absolute;
opacity: 1;
top: 0px;
left: 50%; /*centers pictures inside flex children (.reveal divs)*/
transform: translate(-50%, 0); /*see above*/
}
.reveal:hover .top {
opacity: 0;
}
Demo on Codepen
The above example uses flexbox to create a simple grid which will work with the (slightly modified) .reveal divs from my original post. If you're unfamiliar with flexbox syntax, there's an awesome free video course from Wes Bos that I highly recommend.
P.S. Note that the grid will only work "out of the box" if the images have a set pixel width, although you could easily support different images sizes with a little media query magic.

Got it to work with the following
In the CSS, I had the #media (hover:hover){} so that users do not have to double click an image on mobile to go to the product page.
CSS:
/* ===============================================
// Reveal module
// =============================================== */
#media (hover:hover) {
.has-secondary.grid-view-item__link img.secondary{
display:none;
}
}
#media (hover:hover) {
.has-secondary.grid-view-item__link:hover img.secondary{
display:block;
}
}
#media (hover:hover) {
.has-secondary.grid-view-item__link:hover img.grid-view-item__image{
display:none;
}
}
#media screen and (min-width:767px){
.has-secondary.grid-view-item__link img.secondary{
display:none;
}
.has-secondary.grid-view-item__link:hover img.secondary{
display:block;
}
.has-secondary.grid-view-item__link:hover img.grid-view-item__image{
display:none;
}
}
#media screen and (max-width:767px){
.has-secondary.grid-view-item__link img.secondary{
display:none;
}
}
Changed product-card-grid.liquid HTML/Liquid to the following:
{% unless grid_image_width %}
{%- assign grid_image_width = '600x600' -%}
{% endunless %}
<div class="grid-view-item{% unless product.available %} product-price--sold-out grid-view-item--sold-out{% endunless %}">
<a class="grid-view-item__link {% if product.images.size > 1 %} has-secondary{% endif %}" href="{{ product.url | within: collection }}">
<img class="grid-view-item__image" src="{{ product.featured_image.src | img_url: grid_image_width }}" alt="{{ product.featured_image.alt }}">
{% if product.images.size > 1 %}
<img class="secondary" src="{{ product.images.last | img_url: grid_image_width }}" alt="{{ product.images.last.alt | escape }}">
{% endif %}
</a>
</div>
<div class="h4 grid-view-item__title">
{{ product.title }}
</div>
{% if section.settings.show_vendor %}
<div class="grid-view-item__vendor">{{ product.vendor }}</div>
{% endif %}
<div class="grid-view-item__meta">
{% include 'product-price', variant: product %}
</div>

Related

changing background-color has no effect

I can't change the background color with my css stylesheet.
Here is the HTML (using Django); there are at present three listings in listings.
{% for listing in listings %}
<ul>
<li class="item"><img src="{{ listing.pic}}"> {{ listing }}</li>
<div class="item-description">{{ listing.description }}</div>
</ul>
{% endfor %}
Here is the CSS
body {
padding: 10px;
background-color: green !important;
}
ul {
list-style: none;
background-color: green !important;
}
.item {
background-color: blue !important;
height: 200px;
}
.item-description {
background-color: purple !important;
}
As you can see I have already tried adding !important and giving elements a height. There is also a link for bootstrap which I tried deleting. However, nothing has any effect; the page and all elements remain white.

Dual videos to stack on mobile

I am working on a shopify page and customized the video section template to post dual videos. So I was able to create the two videos side by side but when I display them on my phone it displays the video side by side instead of being stacked. below is a snipet of the code. If yall need the all the text I can send it. I made it short for space. I would like to thank you for y'alls help in advance.
I am assuming that the changes will need to be done in css, but I not sure how to format the #media tag.
<!-- Beginning first video -->
<div class="mvideo-layout">
<div class="video-container">
<div id="multiple-left" class="video-item--multiple" data-action="play-video">
<div class="video-wrapper">
<div class="video-wrapper__image-wrapper">
{%- if section.settings.image -%}
{%- capture supported_sizes -%}{%- render 'image-size', sizes:
'300,400,500,600,700,800,900,1000,1200', image:
section.settings.image -%}{%- endcapture -%}
{%- assign image_url = section.settings.image | img_url: '1x1' |
replace: '_1x1.', '_{width}x.' -%}
This begins the next video on the side
<!-- Beginning second video -->
<div id="multiple-right" class="video-item" data-action="play-video">
<div class="video-wrapper">
<div class="video-wrapper__image-wrapper">
{%- if section.settings.image2 -%}
{%- capture supported_sizes -%}{%- render 'image-size', sizes:
'300,400,500,600,700,800,900,1000,1200', image:
section.settings.image2 -%}{%- endcapture -%}
{%- assign image_url = section.settings.image2 | img_url: '1x1' |
replace: '_1x1.', '_{width}x.' -%}
Here is the CSS code
.mvideo-layout{
max-width: auto;
}
.video-container{
position: relative;
padding-bottom: auto;
}
#multiple-left{
float: left;
padding: 5px;
width: 47.5%;
box-sizing: border-box;
}
#multiple-right{
float: left;
padding: 10px;
width: 47.5%;
box-sizing: border-box;
Everyone after a little more research I found my answer. I add the following to my CSS file.
#media (max-width:767px) {
.video-container {
width: 100%;
height: auto;
}
#multiple-left {
width: 100%;
height: auto;
float: none;
}
#multiple-right {
width: 100%;
height: auto;
float: none;
}
}

Django templates not rendering CSS when template variables are used

I am trying to build a paywall using HTML and CSS in Django, but somehow the CSS that is supposed to fade portions of the text does not render. Here is what I have:
<style>
.adjust-image {
display: block;
width: auto;
max-width: 100%;
max-height: 1000px;
}
.blur-text {
filter: blur(5px);
user-select: none;
pointer-events: none;
}
.fade-out {
user-select: none;
position: relative;
}
.fade-out:after {
content: "";
height: 75%;
width: 100%;
position: absolute;
bottom: 0;
left: 0;
background: linear-gradient(to bottom, rgba(255,255,255,0), #fff);
}
#paywall-wrapper {
padding: 35px;
border-radius: 5px;
position: relative;
margin-bottom: 30px;
box-shadow: 0px 0px 20px -1px rgba(0,0,0,0.20);
}
#paywall-wrapper * {
text-align: center;
}
#paywall-wrapper .btn {
left: 50%;
transform: translateX(-50%);
position: relative;
}
</style>
<div class="display-margins">
<div>
<h5>{{solution.questionToProblem}}</h5>
<h6><b>Solution</b></h6>
{% if request.user.is_anonymous or solution.free != True and request.user.is_subscriber != True %}
<p class= "format-paragraph fade-out:after">{{solution.solutionToProblem|safe}}</p>
<div id="paywall-wrapper">
<h4>Premium Subscription</h4>
<p>To view this solution, get our subscription for just <strong>$17</strong>.</p>
<a class="btn btn-primary text-light" href = "{% url 'subscribe' %}">Subscribe</a>
</div>
{% else %}
<p class="noselect format-paragraph">{{solution.solutionToProblem|safe}}</p>
{% for s in solution_images %}
<img class = "adjust-image noselect" src="{{ s.photo.url }}">
<br></br>
{% endfor %}
{% endif %}
{% render_comments solution request %}
<br class= "extra_spacing"></br>
</div>
</div>
Ideally, the text for paywall is supposed to fade out like this:
But it doesn't render when I have template variables in my <p> tags:
Surprisingly enough, if I type out content in my <p> tags manually, it works. But when I use <p>{{random content}}</p>, it doesn't work.
What am I doing wrong with my CSS or my HTML when I say <p class= "format-paragraph fade-out:after">{{solution.solutionToProblem|safe}}</p>?
Make sure when you want CSS integrated in Django, and you have HTML in your template variable, use:
{{put_your_template_variable|striptags}}
instead of safe.

div dropdown not showing

I am attempting to create a dropdown for a user. The problem is that it doesn't show up at all.
<div class="account-wrap">
<div class="inside-account trade-sell-div">
<a class = "trade-sell-button" href="{% url 'product' %}">Trade/Sell</a>
</div>
{% if user.is_authenticated %}
<div class = "inside-account chat-box-dropdown">
<a class="imgs-signed-in"><img style="height:45px !important;" src = "{% static "imgs/chat-box.png" %}" alt="Chat Box"></a>
</div>
<div class="inside-account user-dropdown">
<a class="imgs-signed-in user-icon-dropdown"><img src="{% static "imgs/user-icon.png" %}" alt="User"></a>
<div class="dropdown-frame">
<div id="triangle"></div>
<div class="dropdown-wrapper">
<hr>
</div>
</div>
</div>
{% else %}
<div class="inside-account">
Login
</div>
{% endif %}
</div>
css
.dropdown-frame{
position: absolute;
height: 40rem;
width: 10rem;
outline: 1px solid black;
}
#triangle {
width: 0;
height: 0;
content: '';
border-left: 20px solid transparent;
border-right: 20px solid transparent;
border-bottom: 20px solid white;
}
.dropdown-wrapper {
right: 0;
height: 40rem;
width: 10rem;
top: 56px;
border: 1px solid red;
z-index: 122;
}
Basically the triangle shows up on the nav bar but the part under the triangle does not show up at all. When I move the div elements outside the nav, it actually shows up. Does anyone have any explanation as to why my div dropdown-wrapper does not show up?
I believe you missed the . before dropdown-frame class
It should be {% if request.user.is_authenticated %} instead of {% if user.is_authenticated %}

How do I target unknown <div>s from the CSS

how do you add :target {opacity: 1} onto the href"#pop{{user.user_id}}" below?
the user_id is unknown until the page generates
The for loop as follows;
{% for user in pull %}
Link: {{user.user_name}} {{ user.user_id }}
<div style="opacity:0" id="pop{{user.user_id}}">
{{ user.info }}
</div>
{% endfor %}
Which looks like this after its translated onto a web page from Django.
Link: tom 10
<div style="opacity:0" id="pop10">
this is my info
</div>
Link: ann 8
<div style="opacity:0" id="pop8">
i am an apple
</div>
Link: mike 3
<div style="opacity:0" id="pop3">
i like pears
</div>
if the styles for all of them are same then you can add a class in the loop for each div and anchor and then add style to these anchors and divs which have this added class. If you want different styles for these divs and anchors then you need to have the id's .Hope it helps
{% for user in pull %}
<a class="styled_class" href="#pop{{user.user_id}}">Link: {{user.user_name}} {{ user.user_id }}</a>
<div class="styled_div" style="opacity:0" id="pop{{user.user_id}}">
{{ user.info }}
</div>
{% endfor %}
Okay, after a lot of thinking i figured it out by myself, all you need to do is make a style tag in the same template which is encased in the same for loop to generate the individual unique css Ids pointing to each div
<style type="text/css">
{% for i in pull %}
#pop{{i.user_id}}:target {
opacity: 1;
z-index: 1;
}
#pop{{i.user_id}} {
width: 58.8em;
min-height: 10em;
background: none repeat scroll 0% 0% #FFA500;
top: 9em;
border-radius: 16px;
opacity: 0;
position: absolute;
z-index: -1;
transition: opacity 1s ease 0s, z-index 1s cubic-bezier(0, 1, 1, 0) 0s;
max-height: 34em;
padding: 1em;
margin-left: 1em;
}
#pop_close{{i.user_id}}:target {
opacity: 0;
z-index: -1;
}
{% endfor %}
</style>