Navbar Section Highlighting - html

Recently I tried adding functionality to a website I am making by making the current section the user is on appear as "highlighted" in the navbar. In order to do this, I added this JQuery script to my code:
<script type="text/javascript">
$(document).on('click', '.navbar-end a', function() {
$(this).addClass('active').siblings().removeClass('active');
});
</script>
This function determines which section of the navbar was clicked and adds the class "active" to the specific anchor tag. The class "active" is styled with a different color so that it appears different from the other navbar elements.
My Navbar:
<div class="hero-head">
<nav class="navbar">
<div class="container">
<div id="navbar" class="navbar-menu">
<div class="navbar-end">
<a href="{{ url_for('welcome') }}" class="active">
Home
</a>
{% if not current_user.is_authenticated %}
<a href="{{ url_for('login') }}" class="navbar-item">
Login
</a>
<a href="{{ url_for('signup') }}" class="navbar-item">
Sign Up
</a>
{% endif %}
{% if current_user.is_authenticated %}
<a href="{{ url_for('index') }}" class="navbar-item">
My Tasks
</a>
<a href="{{ url_for('logout') }}" class="navbar-item">
Logout
</a>
{% endif %}
</div>
</div>
</div>
</nav>
CSS:
a {
color: #b2b1b1;
font-family: Lato;
display: inline-flex;
margin: 20px;
padding: 3px;
padding-left: 20px;
text-decoration: none;
}
.active {
color: #19dafa !important;
}
Now I will describe the issue I am facing. After making these changes, when I click on a tab on the Navbar on my site, it only momentarily changes to the color specified by the active class. For a split second the color is #19dafa, but then it changes back to #b2b1b1 immediately after (without me clicking on a different Navbar section). This led me to believe that the color was immediately getting overwritten by another style. After trying to debug around this claim, I was unable to find any fixes. Any ideas as to what could be causing this?

Related

How do i make my drop down menu visible beyond the navbar?

I'm trying to have a drop down menu within a navbar; however, it only displays until the limit of my navbar when, ideally, id like it to be "in front" of the navbar so to speak.
Dropdown is cut off
I am new to html and CSS so my exploration is somewhat limited. I have implemented one of bootstrap's navbar's and also used their dropdown button html. I expected this to work okay but, as stated, the dropdown seems to be bound within the navbar (assuming this is because it is within the navbar div?) I have also attempted to follow w3schools guide but I didn't succeed with that either.
Sidenote: because of the limited visibility, the "my account" button logs the user out, this is intentional for now lmao.
<body>
<nav class="navbar navbar-expand-lg bg-light">
<div class="container-fluid">
<a class="logo" href="/"><img src="static/Logo_2.png" alt="Logo"></a>
<div class="navbar-nav">
{% if not session["id"] %}
<a class="nav-link" href="login">Log In</a>
{% endif %}
{% if session["id"] %}
<a class="nav-link" href="languages">Languages</a>
<a class="nav-link" href="faq">FAQs</a>
<div class="dropdown">
<button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton1" data-bs-toggle="dropdown" aria-expanded="false">
Account
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenuButton1">
<li><a class="dropdown-item" href="logout">My Account</a></li>
<li><a class="dropdown-item" href="logout">Log Out</a></li>
</ul>
</div>
{% endif %}
</div>
</div>
</nav>
{% if get_flashed_messages() %}
<header>
<div class="alert alert-primary mb-0 text-center" role="alert">
{{ get_flashed_messages() | join(" ") }}
</div>
</header>
{% endif %}
<main class="container-fluid py-5 text-center">
{% block main %}{% endblock %}
</main>
</body>
.navbar {
height: 100;
overflow: hidden;
}
.navbar-nav {
align-items: baseline;
display: flex;
float: right;
gap: 3em;
}
.nav-link {
color: black;
display: flex;
float: right;
}
.nav-link:hover {
color: red;
}
.btn-secondary {
background: none;
border: none;
color: black
}
.btn-secondary:hover {
background: none;
border: none;
color: red;
}
.logo {
display: flex;
scale: 0.4;
transform-origin: left;
}
your example should be cut down to just the minimum that displays the issue. you have extra classes, some ASP-like code, etc - none of that is needed and just makes it harder to diagnose.
the issue appears to be that your submenu is contained inside the top-level .navbar element, but you are constraining that to have a height of 100 (and you should include the metric here - 100px? 100cm?) with overflow being hidden. this means that the submenu gets cut off.
you could just remove those constraints.
a better solution would involve a rewrite, so the submenu items are positioned absolutely, in a relatively-positioned placeholder. there are examples of this online. example: https://gist.github.com/SamWM/901853
{% if not session["id"] %}
Log In
{% endif %}
{% if session["id"] %}
Languages
FAQs
Account
My Account
Log Out
{% endif %}
...
Remove the "overflow: hidden;" style from .navbar css, so your code should be-
.navbar {
height: 100;
}

Bootstrap row doesn't put elements in a row

I wanted to put elements in my nav menu in a row, so I used bootstrap 5.0 row class, but they still land one below another.
I am doing a Flask project, so I am using Jinja to some extent.
base.html
<body>
<div class = "container">
{% block body %}
{% endblock %}
</div>
</body>
panel.html
{% block body %}
<nav class="navbar sticky-top">
<div class="fixed-top" style="width: 100%; max-width: 100%; height: 100px; background-color: #2E2E2E;">
<nav class="container-wide navbar navbar-expand-lg">
<div class = "row">
<a id="rbf-main" style="font-size:40px" href= "{{ url_for ('home') }}">RBF</a>
<a class ="rbf-link" href= "{{ url_for ('home') }}">Remove more Big Files</a>
</div>
</nav>
</div>
</nav>
{% endblock %}
Your elements in the row have to get "col-" classes.
Bootstrap is based on a 12 column layout, so if you want to have your rbf-main and rbf-link in one row, they should both have classes like that.
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"/>
<div class = "row">
<a class="col-12 col-sm-6" id="rbf-main" style="font-size:40px" href= "{{ url_for ('home') }}">RBF</a>
<a class="col-12 col-sm-6 rbf-link" href= "{{ url_for ('home') }}">Remove more Big Files</a>
</div>
The elements share one row at viewport size sm. You can use any other viewportsize.

Setting only categories to be view on homepage/set amount of images

<html>
<head>
<meta charset='utf-8'>
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<title>Gallery</title>
<!-- CSS only -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.2.1/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-iYQeCzEYFbKjA/T2uDLTpkwGzCiq6soy8tYaI1GyVh/UjpbCx/TYkiZhlZB6+fzT" crossorigin="anonymous">
<style>
.image-thumbnail {
height: 200px;
object-fit: cover;
}
.container {
margin-left: 1;
}
.h1 {
text-align: center;
}
.list-group-item a {
text-decoration: none;
color: black;
}
</style>
</head>
<h1 class="text-center m-5 p-3 mb-2 bg-light text-secondary">CHARLIES LIFE</h1>
<body class="m-5">
<div class="container">
<div class="row">
<div class="col-md-3 mt-2">
<div class="card">
<div class="card-header">
Categories
</div>
<ul class="list-group list-group-flush">
<li class="list-group-item">
All
</li>
{% for category in categories %}
<li class="list-group-item">
<a href="{% url 'gallery' %}?category={{category.name}}">{{category.name}}
</a>
</li>
{% endfor %}
Add Photo
</ul>
</div>
</div>
<div class=" col-md-9">
<div class="row">
{% for photo in photos %}
<div class="col-md-4">
<div class="card my-2">
<img class="image-thumbnail" src="{{photo.image.url}}" class="card-img-cap"
alt="...">
<div class="card-body">
<p class="card-text text-center">{{photo.category.name}}</p>
</div>
<div class="d-grid gap-2">
<a href="{% url 'photo' photo.id %}" class="btn btn-dark m-1"
type="button">View</a>
</div>
</div>
</div>
{% empty %}
<h3> No Photos...</h3>
{% endfor %}
</body>
</html>
Hi, I'm currently trying to make a photo blog to record the life of my son with photos as he grows. The above is my code for the "home" page (name as gallery).
So at the moment I have a for loop which adds a "card" class to my gallery page every time I upload an image.
Ideally I'd like to make it so it only showed each category I create with only one picture from that category rather than showing every picture I upload to the website. I just didn't think a head on how many photos I would upload and the home page will just turn into a HUGE photo dump.
If any one has any ideas how I could accomplish this or any other recommendations it would be greatly appreciated.
TYIA
Correct me if i'm wrong, but what i think you're trying to accomplish is to have different section i.e. 'young', 'teenager', 'adult' or something like that, and only show images in those sections with the section name as a tag in the image itself? If that is the case, you can do something like this:
{% for photo in photos %}
{% if photo.tag == young %}
<h1>Show young images here</h1>
{% elif photo.tag == teenager %}
<h1>Show teenage images here</h1>
{% elif photo.tag == adult %}
<h1>Show adult images here</h1>
{% else %}
<h1>No photo's yet</h1>
{% endif %}
{% endfor %}
alternatively, you can do this in your views and serve different images to different templates if you wish to do so.
It would look something like this:
def teenageImages(request):
teenageImage = Image.objects.raw("SELECT * FROM
photos WHERE tag = 'teenager' ")
template = loader.get_template('teenager_photos.html')
context = {
'photos': teenageImage
}
return HttpResponse(template.render(context, request))
You can also go a different route and use filter, more information on filter can be found here.
EDIT for bootstrap cards
Here is an example Github Repo on bootstrap cards with image (without a link) my webpage repo
You can clone this repo and look around in it, that way maybe you can get some inspiration / ideas on how to do certain things.
Alternatively, you can use something like Wagtail for this, I have also made a Github repo regarding that, which can be found here
I suggest that you look at the RoutablePageMixin of the Wagtail CMS (Django based), see documentation here. With it you could make your home page accept the category as a variable like the following URL is representing: davidsonsblog.com/category/foobar
Than you could define a queryset filtered by category and ordered randomly (e.g. by the queryset method .order_by('?')). If you only want to show one image of it, add the .first() method to the queryset.
The menu would generate the links accordingly.

Bootstrap carousel and column will not stay next to each other

Goal:
I would like to create a bootstrap row where there is a carousel on the left and text blocks on the right. I have labeled these "Left Column" and "Right Column" respectively within the HTML comments.
Problem:
I'm not able to get the carousel and text to stay in columns. Instead, they stack on top of each other, with the carousel on top and the next column going below it.
Context:
I've tried a few different things by moving around divs and creating new ones. I've already tried to remove the flex CSS styling and I've tried to remove all padding and margins. I've reviewed several stack overflow questions that seemed similar, but none of the problems seems similar to mine or the suggestions do not help.
It does not appear that there is anything within the main CSS that is causing this issue, because I am able to get other columns and rows to work correctly on the same page. However, I'm adding it here just in case with a screenshot.
HTML
<div class="container">
<div class="row">
<!-- Left Column Start -->
<div class="col-6" id="carousel-contain">
<div id="plantCarousel" class="carousel slide col-6" data-ride="carousel" data-interval="false">
<ol class="carousel-indicators">
{% for image in plant.plant_images.all %}
{% if forloop.first %}
<li data-target="#plantCarousel" data-slide-to="{{forloop.counter0}}" class="active"></li>
{% else %}
<li data-target="#plantCarousel" data-slide-to="{{forloop.counter0}}"></li>
{% endif %}
{% endfor %}
<li data-target="#plantCarousel"></li>
</ol>
<div class="carousel-inner">
{% for image in plant.plant_images.all %}
{% if forloop.first %}
<div class="carousel-item active">
{% else %}
<div class="carousel-item">
{% endif %}
<img src="{{ image.images.url }}" alt="{{ plant.name }}">
</div>
{% endfor %}
</div>
<a class="carousel-control-prev" href="#plantCarousel" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#plantCarousel" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
</div>
</div>
<!-- Left Column Ends -->
<!-- Right Column Start -->
<div class="col-6">
<p> <b>Latin Name: </b>{{ plant.latin_name }} </p>
<br>
<p><b>Description: </b></p>
<p> {{ plant.description }} </p>
<br>
<br>
</div>
<!-- Right Column Ends -->
</div>
</div>
CSS
/* Sticky footer styles
-------------------------------------------------- */
html {
position: relative;
min-height: 100%;
font-size: 14px;
}
#media (min-width: 768px) {
html {
font-size: 16px;
}
}
body {
margin-bottom: 60px; /* Margin bottom by footer height */
}
.container {
max-width: 960px;
}
.pricing-header {
max-width: 700px;
}
.footer {
position: absolute;
bottom: 0;
width: 100%;
height: 60px; /* Set the fixed height of the footer here */
line-height: 60px; /* Vertically center the text there */
background-color: #f5f5f5;
}
img {
max-width: 100%;
max-height: 100%;
}
How it appears on the page:
After digging around even further, I discovered that I accidentally added an extra </div> which caused my row to end before the right column could be added into the row.

text-wrap in navbar dropdown doesnt work through css, it works through html

I have a dropdown in BS4 navbar. The content goes out of the container on mobile device. I want to wrap the text through css.
Following code works:
HTML:
<div class="dropdown-menu" >
{% for department in object.departments.all %}
<a class="dropdown-item text-wrap" href="">
{{ department.name }}</a>
{% endfor %}
</div>
CSS:
.dropdown-menu {
width: 30vw;
}
But following code doesnt work:
HTML:
<div class="dropdown-menu" >
{% for department in object.departments.all %}
<a class="dropdown-item" href="">
{{ department.name }}</a>
{% endfor %}
</div>
CSS:
.dropdown-menu {
width: 30vw;
}
.dropdown-item{
text-wrap:normal;
}
I think you are looking to use the white-space property or possibly to use word-wrap or text-overflow.
I've not heard of the text-wrap property in css.