Bootstrap: card-image-overlay is out of the image - html

Sorry for this question, I hate CSS. It makes no sense to me.
I'm trying to overlay some text and a button on top of an image but it comes out of the image;
This is the code for the whole card;
<div class="col-md-6 col-lg-4 mb-4">
<div class="card listing-preview">
<h4 class="text-primary">{{ listing.title }}</h4>
<div>
<img class="card-img-top" src="{{ listing.map_url }}" alt="">
<div class="card-img-overlay">
<h2>
<span class="badge badge-secondary text-white">£{{ listing.price|floatformat }}</span>
</h2>
</div>
</div>
<div class="card-body">
<div class="listing-heading text-center">
<p>
<i class="fas fa-map-marker text-secondary"></i> {{ listing.city }} {{ listing.state }}, {{ listing.zipcode }}</p>
</div>
<hr>
<div class="row py-2 text-secondary">
<div class="col-6">
Bills Inc: &nbsp {% if listing.bills_inc %}
<i class="fas fa-check"></i> {% else %}
<i class="fas fa-times"></i> {% endif %}
</div>
<div class="col-6">
Deposit: {% if listing.deposit %} £{{ listing.deposit|floatformat }} {% else %}
<i class="fas fa-times"></i> {% endif %}
</div>
</div>
<div class="row py-2 text-secondary">
<div class="col-6">
<i class="fas fa-bed"></i> Type: {{ listing.type|title }}</div>
<div class="col-6">
<i class="fas fa-bath"></i> Bathrooms: {{ listing.bathrooms }}</div>
</div>
<hr>
<div class="row py-2 text-secondary">
<div class="col-12">
<i class="fas fa-user"></i> by {{ listing.advertiser_type }} {{ listing.advertiser_name|title }}</div>
</div>
<div class="row text-secondary pb-2">
<div class="col-6">
<i class="fas fa-clock"></i> {{ listing.list_date | timesince }}</div>
</div>
<hr>
More Info
</div>
</div>
</div>
Bonus points (upvote) if you can overlay 'London, N20' at the bottom of the map as well.
Thanks in advance.

You are looking for the z-index attribute:
#first {
width: 60px;
height: 60px;
background-color: red;
position: absolute;
z-index: 1;
}
#second {
width: 60px;
height: 60px;
background-color: green;
position: absolute;
left: 30px;
top: 30px;
}
<div id="first"></div>
<div id="second"></div>
The item having larger z-index will be displayed over the item having a lower z-index.

Related

elements in a foreach loop getting different css/bootstrap styles in laravel

am getting this weird bug whereby css styles are only applying to the first 2 items in my foreach loop.here is my code.
//html code
<div class="row">
#if ($housescategory->isEmpty())
<div class="col-lg-4">
No houses Found At the Moment
</div>
#else
#foreach ($housescategory as $rentalhse)
<div class="col-lg-4">
<section class="card hsecard">
<figure>
<div class="img-overlay hot-home">
#if($rentalhse->vacancy_status==1)
<span class="badge badge-info p-2 rounded-0 statusbadge">Vacants Available</span>
#elseif($rentalhse->vacancy_status==2)
<span class="badge badge-success p-2 rounded-0 statusbadge">Fully Booked</span>
#endif
<img src="{{ asset ('imagesforthewebsite/rentalhouses/rentalimages/medium/'.$rentalhse->rental_image) }}" alt="{{ $rentalhse->rental_name }}">
</div>
{{ $rentalhse->id }}<figcaption>{{ $rentalhse->rental_name }}
</figcaption>
<div class="pricelocation" style="display: flex;
justify-content: space-between;">
<section class="location">
<a class="disabled font-italic h6"><i class="fa fa-map-marker"></i>{{ $rentalhse->houselocation->location_title }}</a>
</section>
<section class="pricelink">
<span class="btn btn-dark">sh.{{ $rentalhse->monthly_rent }}</span>
</section>
</div>
</figure>
<div class="card-content">
<p>{!! Str::limit($rentalhse->rental_details, 80)!!}</p>
<section class="icons-home">
<div class="name-icon">
#if ($rentalhse->cctv_cameras == 'yes')
<span>CCtv Security Cameras</span>
<div class="icon">
<i class="fa fa-camera-retro"></i>
<span>Available</span>
</div>
#endif
</div>
<div class="name-icon">
#if ($rentalhse->parking == 'yes')
<span>Parking</span>
<div class="icon">
<i class='fas fa-parking'></i>
<span>Available</span>
</div>
#endif
</div>
<div class="name-icon">
#if ($rentalhse->generator == 'yes')
<span>Backup Generator</span>
<div class="icon">
<i class="fa fa-bolt"></i>
<span>Available</span>
</div>
#endif
</div>
</section>
</div>
<div class="viewprice" style="display: flex;
justify-content: space-between; margin:0px !important;">
<section class="viewlink">
Contact Admin
</section>
<section class="viewlink">
<a class="btn-sm btn-warning" href="{{ url('rentalhse/'.$rentalhse->rental_slug.'/'.$rentalhse->id) }}" role="button" >
View Details
</a>
</section>
</div>
</section>
</div>
#endforeach
#endif
here its how it looks like in the page .here the paragraph starts getting itaicised which is a different style from the first one.. here is the other part here the column gets smaller different from the set one in the row.its been giving me headache i havent understood why its coming up.

<a> element appearing inside even though I put it outside

I have django template file called card.html
In this file the anchor tag is on the outside.
<a class="url d-block" href="{% if content_type == 'book' %} {% url 'book' content.id|default:1 %} {% else %} {% url 'article' content.id|default:1 %} {% endif %}">
<div class="card d-flex flex-column border border-1 rounded">
<div class="p-5 bg-light">
<img src="{{ content.thumbnail }}" class="thumbnail img-fluid rounded">
</div>
<div class="flex-grow-1 p-4 border-top border-1">
<h3 class="category fs-5 text-secondary">{{ content.category.first }}</h3>
<h2 class="title fs-4 mb-2 text-dark">{{ content.title }}</h2>
{% if content_type == "book" %}
<a class="book-author fs-5 fw-bold" href="https://www.google.com/search?q={{content.book_author|default:''}}">By {{ content.book_author }}</a>
<h3 class="author fs-5 text-dark">Summarized by {{ content.author }}</h3>
{% else %}
<h3 class="author fs-5 text-dark">Created by {{ content.author }}</h3>
{% endif %}
</div>
<div class="flex-shrink-1 pt-3 d-flex justify-content-evenly border border-1">
<p class="date-created d-inline">{{ content.date_created }}</p>
<i class="fa-solid fa-star mt-1"></i>
<i class="fa-solid fa-ellipsis-vertical mt-1"></i>
</div>
</div>
</a>
card.html is included in this template (the div is inside a body).
<div id="list-container" class="d-flex flex-wrap justify-content-center gap-4 pb-5 px-5">
{% for content in content_list %}
{% include "app/card.html" with visibility="visible" %}
{% empty %}
<h2>No {{ content_type }} for now..</h2>
{% endfor %}
</div>
When rendered, it looks like this.
The anchor tag somehow close by itself and got inside the div.
<a class="url" href=" /books/1 "></a>
<div class="card d-flex flex-column border border-1 rounded">
<a class="url" href=" /books/1 ">
<div class="p-5 bg-light">
<img src="img.jpg" class="thumbnail img-fluid rounded">
</div>
</a>
<div class="flex-grow-1 p-4 border-top border-1">
<a class="url" href=" /books/1 ">
<h3 class="category fs-5 text-secondary">Example Category</h3>
<h2 class="title fs-4 mb-2 text-dark">Title</h2>
</a>
<a class="book-author fs-5 fw-bold" href="https://www.google.com/search?q=Name">By Name</a>
<h3 class="author fs-5 text-dark">Summarized by Archer</h3>
</div>
<div class="flex-shrink-1 pt-3 d-flex justify-content-evenly border border-1">
<p class="date-created d-inline">May 3, 2022, 9 a.m.</p>
<i class="fa-solid fa-star mt-1"></i>
<i class="fa-solid fa-ellipsis-vertical mt-1"></i>
</div>
</div>
You cannot use <a> tag inside <a> tag. HTML don't allow nested tag.
You can use onclick event but you have to check with javascript which element clicked because parent element is a wrapper.

Children div overlapping parent div

I have a parent div where children div are added. I use pagination set to five.
On large screen everything is fine but on smaller device (14.00-inch display that has a resolution of 1920x1080 pixels) the children divs are overlaying the parent div at the bottom.
The whole height of the children div can differ depending on how many children div are displayed (1,2,3,4 or 5)
This is the CSS of my parent div:
header.nav_masthead {
padding-top: 6.5rem;
background-color: #345a61;
background-size: cover;
background-position: center;
background-image:;...;
}
The div where the children div are added:
<div id='fav_list' class="w-75 mx-auto" style='background-color: transparent; height: auto;'>
This is my page HTML:
{% block content %}
<header class="masthead" >
<div class="col-lg-12">
<h2 class="intro-text text-center" style="color: beige;">Bienvenue sur ton compte {{ user }}</h2>
<hr class="divider1 my-4" />
<div class='w-75 mx-auto row d-flex justify-content-around mb-3'>
<h3 class="intro-text text-center account_items" style="color: beige;">Produit recherché</h3>
<h3 class="intro-text text-center account_items" style="color: beige;">Produit de substitut</h3>
</div>
</div>
<div id='fav_list' class="w-75 mx-auto" style='background-color: transparent; height: auto;'>
{% for saved in saved_list %}
<div class='row d-flex justify-content-between'>
<div class="card mb-3" style="width: 49%;">
<div class="row no-gutters">
<div class="col-md-2 my-auto">
<img class="mx-auto d-block" style="width:auto; height:auto; max-width:100px; max-height:100px; "
src="{{ saved.original_product.picture }}">
</div>
<div class="col-md-10">
<div class="card-body">
<h5 class="card-title"><a href="{% url 'finder:detail' saved.original_product.id %}"
class="aaccount">{{ saved.original_product.real_name }}/ {{ saved.original_product.real_brand }}</a>
</h5>
<img src="/static/finder/img/nutriscore-{{ saved.original_product.nutrition_grade}}.svg"
style="width:70px;"><br>
</div>
</div>
</div>
</div>
<div class="card mb-3" style="width: 49%;">
<div class="row no-gutters">
<div class="col-md-2 my-auto">
<img class="mx-auto d-block " style="width:auto; height:auto; max-width:100px; max-height:100px; "
src="{{ saved.sub_product.picture }}">
</div>
<div class="col-md-9">
<div class="card-body">
<h5 class="card-title"><a href="{% url 'finder:detail' saved.sub_product.id %}"
class="aaccount">{{ saved.sub_product.real_name}}/ {{ saved.sub_product.real_brand }}</a>
</h5>
<img src="/static/finder/img/nutriscore-{{ saved.sub_product.nutrition_grade}}.svg"
style="width:70px;"><br>
</div>
</div>
<div class="col-md-1 my-auto mx-auto">
<button type ='button' class=' btn substitut' value='{{ saved.id }}'>{% csrf_token %}<i class='fas fa-trash-alt'></i></button>
</div>
</div>
</div>
</div>
{% endfor %}
</div>
</header>
<div id='navigation'>
{% if paginate %}
<div style="background-color: #E8A75D; overflow: auto; ">
<div class="clearfix"></div>
{% for i in page_range %}
{% if i == 1%}
<span><button class='btn nav_button first ' value='{{ i }}'>{{i}}</button></span>
{% else %}
<span><button class='btn nav_button ' value='{{ i }}'>{{i}}</button></span>
{% endif %}
{% endfor %}
{% endif %}
</div>
{% endblock %}
What should I do to make my div 'fav_list' not overlapping my div '.nav_masthead'?

Django bootstrap modal not showing

I am trying to show a modal on a button click, however, after I click on the modal it does not show the modal, I do not know what seems to be the issue since I followed the exact tutorial on bootstrap and W3Schools. Here, is my template:
{% for comment in comments %}
<div class="border-bottom">
<div class="row pt-1 pl-4">
<div class="col-xs">
<img class="img-create-post rounded-circle mr-1" style="width: 2.1rem;height: 2.1rem;" src="https://mdbootstrap.com/img/Photos/Avatars/avatar-5.jpg" alt="Profile image">
</div>
<div class="col-xs" style="margin-bottom: 0;">
<span class="text-dark font-size-smaller" href="#" style="font-weight: 500;">{{ comment.name.first_name }}</span>
<span class="text-muted small">•</span>
<a class="text-muted small" href="#">#{{ comment.name.username }}</a>
<span class="text-muted small">•</span>
<span class="text-muted small">{{ comment.get_created_on }}</span>
<p class="font-weight-light pl-1">{{ comment.body }}</p>
</div>
</div>
<div class="d-flex justify-content-between">
<div>
<span class="text-muted small view-replies">view {{ comment.replies.count }} replies <i class="fas fa-caret-down"></i></span>
</div>
<div>
<!-- button to show modal -->
<button class="btn btn-sm small float-right text-muted button-outline-light reply-btn" type="button" data-toggle="modal" data-target="modal-comment-reply">Reply</button>
</div>
</div>
<div class="comment-replies">
{% for reply in comment.replies.all %}
<div class="row pt-1 pl-4">
<div class="col-xs">
<img class="img-create-post rounded-circle mr-1" style="width: 2.1rem;height: 2.1rem;" src="https://mdbootstrap.com/img/Photos/Avatars/avatar-5.jpg" alt="Profile image">
</div>
<div class="col-xs" style="margin-bottom: 0;">
<span class="text-dark font-size-smaller" href="#" style="font-weight: 500;">{{ comment.name.first_name }}</span>
<span class="text-muted small">•</span>
<a class="text-muted small" href="#">#{{ comment.name.username }}</a>
<span class="text-muted small">•</span>
<span class="text-muted small">{{ comment.get_created_on }}</span>
<p class="font-weight-light pl-1">{{ comment.body }}</p>
</div>
</div>
{% endfor %}
</div>
</div>
<div class="modal fade" id="modal-comment-reply">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<p class="font-size-smaller">{{ request.user.first_name }} replying to {{ comment.name.username }}</p>
</div>
<div class="modal-body">
<form method="POST" action="{% url 'home:post-detail' post.guid_url %}" class="post-comment-form" style="height: 1rem;">
{% csrf_token %}
<input type="hidden" name="comment_id" value="{{ comment.id }}"/>
{{ form }}
<button class="btn btn-sm small btn-outline-primary ml-1" style="border-radius: 20px;" type="submit">Reply</button>
<button type="button btn-sm small btn-outline-secondary" class="btn btn-secondary" data-dismiss="modal">Close</button>
</form>
</div>
</div>
</div>
</div>
{% empty %}
<div class="d-flex justify-content-center">
<p class="font-weight-lighter text-muted">No comments to show</p>
</div>
{% endfor %}
<style>
.view-replies:hover {
cursor: pointer;
text-decoration: underline;
}
</style>
<script>
$(document).ready(function () {
$('.reply-btn').on("click", function () {
$('#modal-comment-reply').modal("show");
});
})
</script>
I have even tried jQuery to open it but it does not seem to open, my other modals work fine I do not know why this does not open.
Thanks for all the help in advance!
EDIT: SOLVED - Typo in jquesry function!

how to add margin without ruining responsiveness

so I have three cards in one row but they are all stuck together without margin it looks ugly. I want there to be some margin between each card so I added margin but it ruins the responsiveness bootstrap provides. Thus I added padding only. Any help would be appreciated
<div class="row">
{% for all_episode in episode %}
<div class="col-6 col-md-4 card" style="padding:20px">
<a href="{% url 'episode_detail' slug=all_episode.slug %}">
<img class="card-img-top" src='{{all_episode.image.url}}'>
</a>
<div class="card-body">
<h5 class="card-title">
{{ all_episode.title }}
</h5>
<p class="card-text">{{ all_episode.story |slice:":100" }}...</p>
</div>
<div class="card-footer">
<small class="text-muted">
<span class="h5">
{{ all_episode.series }}
</span> /
<span class="h6">
<a href="{% url 'season_detail' slug=all_episode.season.slug %}">{{ all_episode.season }}
</a>
</span>
</small>
</div>
</div>
{% endfor %}
</div>
You can just tweak the card
<div class="row">
{% for all_episode in episode %}
<div class="col-6 col-md-4">
<div class="card" style="padding:20px">
<a href="{% url 'episode_detail' slug=all_episode.slug %}">
<img class="card-img-top" src='{{all_episode.image.url}}'>
</a>
<div class="card-body">
<h5 class="card-title">
{{ all_episode.title }}
</h5>
<p class="card-text">{{ all_episode.story |slice:":100" }}...</p>
</div>
<div class="card-footer">
<small class="text-muted">
<span class="h5">
{{ all_episode.series }}
</span> /
<span class="h6">
<a href="{% url 'season_detail' slug=all_episode.season.slug %}">{{ all_episode.season }}
</a>
</span>
</small>
</div>
</div>
</div>
{% endfor %}
</div>
Use Bootstrap Card Deck all cards will be in a row and responsive.
https://getbootstrap.com/docs/4.0/components/card/#card-decks