How can I add animations to my images in my Django app? - html

I´m trying to add a kind of animation to some images in my Django app, what I want to do is that when the user moves the mouse around the image it gets bigger.
I tried adding some code in my CSS but the image won't change
Thank you for your help.
My index.html
{%block contenido %}
<div id="container" class="foto_pelicula">
{% for p in peliculas %}
{% if p.genero.id == 1 %}
<img src={{p.urlPortada}} width="289" height="289"/></li>
{% endif %}
{% endfor %}
</div>
<div id="container" class="foto_pelicula">
{% for p in peliculas %}
{% if p.genero.id == 2 %}
<img src={{p.urlPortada}} width="289" height="289"/></li>
{% endif %}
{% endfor %}
</div>
<div id="container" class="foto_pelicula">
{% for p in peliculas %}
{% if p.genero.id == 3 %}
<img src={{p.urlPortada}} width="289" height="289"/></li>
{% endif %}
{% endfor %}
</div>
{% endblock %}
The Images SRCs are urls that I take from the internet, I guess it does not really matter whether they are taken from the internet or stored in your proyect.
my CSS
#container{
width: 290px;
overflow: hidden;
margin: 5px 4px 0 auto;
padding: 0;
background: #222; /* FONDO DEL RECTANGULO CONTENEDOR */
border: 3px solid #8E1600;
float: left;
}
I added this new lines to my CSS but the image won't change.
.foto_pelicula > img:hover {
transform: scale(1.1);
}
Maybe I'm not using the proper lines in the CSS as I'm a junior programmer.
Help is much appreciated

This question has no connection to Django. In future try to create working html template for your purposes and then add it to django template.
You setup .foto_pelicula > img:hover to transform image. But > selector finds only direct child. See documentation on selectors.
And in your code direct child is a, but not img. Therefore you don't see result. You can change your css rule to .foto_pelicula > a > img:hover
See demo:
#container{
width: 290px;
overflow: hidden;
margin: 5px 4px 0 auto;
padding: 0;
background: #222; /* FONDO DEL RECTANGULO CONTENEDOR */
border: 3px solid #8E1600;
float: left;
}
.foto_pelicula > a > img:hover {
transform: scale(1.1);
}
<div id="container" class="foto_pelicula">
<img src="https://via.placeholder.com/289" width="289" height="289"/>
</div>
IMPORTANT
In your html code I see several divs with id="container". You can setup only one id with certain name to each page. That's why it called identifier.
So change your ids to classes or give different id names for this divs.

Related

css only solution to hide element when page content is less than or equal to 110vh or an equivalent solution

I have implemented a css only back to top button, but on shorter pages it shows when it is not needed.
.top {
position: sticky;
bottom: 9px;
padding: 9px;
place-self: end;
margin-top: 109vh;
font-weight:700;
border-radius: 9px;
color: var(--a1);
background: var(--c2);
}
.top:hover {
color: var(--c2);
background: var(--a1);
text-decoration: none;
}
You can see it in the bottom left corner here: https://abridge.netlify.app/overview-abridge/ (don't need to see it when the page is this short)
It works fine so long as its a longer page: https://abridge.netlify.app/overview-code-blocks/
I have thought of artificially increasing the size of short pages, but that just seems kinda hacky, also I know I can easily resolve this with javascript, but I am trying to find a solution that does not rely on javascript. I tried playing around with media queries but could not find any that actually query how much content is in a viewport.
If you are familiar with zola, the repo is here: https://github.com/Jieiku/abridge
If you have zola installed you can clone the repository and run zola serve from the directory, to test changes locally.
Here is the file with the back to top: https://github.com/Jieiku/abridge/blob/master/sass/include/_top.scss
EDIT: for the moment I have discovered a creative way of resolving this, because its a SSG and zola has readtime value I did this:
{%- block gotop %}
{%- if page.reading_time %}
{%- if page.reading_time > 1 %}
&cuwed;
{%- endif %}
{%- endif %}
{%- endblock gotop %}
The only thing to resolve now is to somehow get it over on the right side of the page instead of the left side.
This is the solution I used:
.topout {
position: sticky;
bottom: 1px;
padding: 20px;
place-self: end;
margin-top: 110vh;
pointer-events: none;
}
.topleft {
margin-left: calc(100% - 80px);
}
.top {
pointer-events: all;
padding: 9px;
border-radius: 9px;
font-weight:700;
color: #FF9900;
background: #222222;
}
.top:hover {
text-decoration: none;
color: #222222;
background: #FF9900;
}
Then in Zola Template page:
{%- block gotop %}
{%- if page.reading_time %}
{%- if page.reading_time > 1 %}
<span class="topout">
<span class="topleft"> </span>&cuwed;
</span>
{%- endif %}
{%- endif %}
{%- endblock gotop %}
You can see it here: https://abridge.netlify.app/overview-code-blocks/
I would have liked to avoid using calc() however this does work without issue in: Firefox, Chrome, Android Chrome
I think the cleanest solution would be to utilize #media screen and (max-height: 110vh)
Here is my suggestion:
#media screen and (max-height: 110vh){
.top{
display:none;
}
}
The idea here is that if the page's viewport is currently within that max-height of 110vh then we want to set .top to no longer display on the page.

How to dynamically adjust width of nav-tabs so it fills up the screen

I have a nav tab that looks like this:
I am using ellipses however I don't like how my nav is scattered in second line. I don't want to use nav-justfied instead be able to squeeze my so it fits in screen and user don't have to scroll horizontally.
like below
My code so far
.nav-tabs>li:not(.active)>a {
background-color: white;
border: 1px solid #ddd;
border-bottom: none;
border-top: 3px solid #9d9d9d;
text-overflow: ellipsis;
max-width: 10em;
overflow: hidden;
display: block;
}
.nav-tabs {
padding-left: 15px;
padding-right: 15px;
padding-top: 15px;
white-space: nowrap;
}
<ul class="nav nav-tabs">
<div class="btn-toolbar pull-right">
{% block tab_buttons %}
{% endblock %}
</div>
<li role="presentation" class="{% if '/hosts' in request.path %}active {% endif %}inverse">Hosts</li>
{% for tab in event.benchmarks.all %}
<li role="presentation" class="{% if 'summary' in request.path and tab == benchmark %}active {% endif %}inverse">{{ tab.name }}</li>
{% endfor %}
</ul>
I'm not 100% sure what you're asking but it sounds like you could benefit from using:
display flex on your nav.
If you're loading the content on the same page (like an admin panel), I'd highly recommend Jquery Tabs.
Use Display:inline-flex; css property on tabs.

css - right link in navigation is lower

I have problem with right link in my bottom navigation.
This link is a little bit lower.
I am not css specialist, please for help.
My html code:
<div class="header container">
{% if is_paginated %}
{% if page_obj.has_previous %}
<h4>Previous</h4>
{% endif %}
<span class="header-label"><h4>Page {{ page_obj.number }} of {{ page_obj.paginator.num_pages }}.</h4></span>
{% if page_obj.has_next %}
<h4>Next</h4>
{% endif %}
{% endif %}
</div>
My css code:
.arrow {
position: absolute;
}
.right {
right: 0;
}
.left {
left: 0;
}
.container {
margin: 0 auto;
}
.header {
text-align: center;
}

django forms: styling widget when field is required or has an error

I'm creating a django form and I can't seem to access each field's widget to style it differently when there's an error or when the field is required (eg: highlight the field's box).
HTML:
{% block content %}
<form action="" method="POST" class="form"> {% csrf_token %}
{% for field in form %}
<div class="fields-container">
<p class="label">{{ field.label }}</p>
{{ field }}
</div>
{{ field.errors }}
{% endfor %}
<button type="submit" id="form-button">Submit</button>
</form>
{% endblock %}
CSS:
.label {
margin: 0 5px 0 0;
width: 20%;
text-align: left;
}
#id_full_name, #id_email, #id_message {
margin: 0;
flex: 1 1;
}
#id_message {
resize: none;
overflow: auto;
}
.errorlist { /*default css class for form errors*/
color: 999999;
font-size: 75%;
font-weight: bold;
list-style: none;
margin-bottom: 5px;
align-self: flex-start;
}
I've been accessing and styling the widgets using #id_fieldname, but I've tried the following and it didn't work:
#id_fieldname.required, id_fieldname.error { border: 2px solid red; }
Thanks in advance!
You could add a class 'required' in your container <div>:
<div class="fields-container {% if field.field.required %}required{% endif %}">
Using django form methods form.as_p, form.as_ul, form.as_table, this would be done automatically if you declare a specific css class for required fields in your Form, for example:
class myForm(forms.Form):
required_css_class = 'required'
...
More in documentation

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>