I am building a BlogApp and I am trying to make upvote and downbutton , Like Stack Overflow shows BUT my buttons are not showing opposite one another.
They are showing like:
template.html
<!-- Upvote button -->
<span id="id_likes{{topic.id}}">
{% if user in topic.likes.all %}
<button name='submit' type='submit' value="like"><i class="btn fas fa-sort-up fa-6x fa-lg post-buttons " ></i></button>
{% endif %}
</span>
<!-- DownVote button -->
<span id="id_dislikes{{topic.id}}">
{% if user in topic.dislikes.all %}
<button name='submit' type='submit' value="dislike"><i class="fas fa-sort-down fa-6x"></i></button>
{% endif %}
</span>
When I use div instead of span then it shows like this:
It was showing border on buttons then I used:
<style>
button {
padding: 0;
border: none;
background: none;
}
</style>
Any help would be much appreciated.
If you check out the Fontawesome site for these icons (up and down), you'll see that they're designed as a pair, so that (when they're overlaid) the up arrow will be above the down arrow. If you use them separately, as you're doing, that means they're naturally high and low.
Basically, you've done nothing wrong - that's how these characters were designed to appear!
If you want to line them up, you'll need to manually alter the positions of one or both to get them as you want. You could use css top or padding, as you prefer.
I have removed your dynamic code and added one css class.
button {
padding: 0;
border: none;
background: none;
}
.btnOuter{
display: block;
overflow: hidden;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css" rel="stylesheet" />
<span>
<button class="btnOuter" name='submit' type='submit' value="like">
<i class="fas fa-sort-up fa-6x fa-lg post-buttons" ></i>
</button>
</span>
<span>
<button class="btnOuter" name='submit' type='submit' value="dislike">
<i class="fas fa-sort-down fa-6x"></i>
</button>
</span>
Related
I feel like this is relatively simple styling, but i cant for the life of me figure out how to do it.
My code:
<div class="container py-5">
<div class="pull-left" style="margin-right:5px">
<form method="post">
{% csrf_token %}
<p>
<h3>
Do you want to delete <em>"{{ entry.title }}"</em> posted on {{ entry.date_created|date:'Y-m-d' }}?
</h3>
</p>
<button class="btn btn-danger" type="submit" value="Confirm">Confirm</button>
</form>
</div>
<a href="{% url 'entry-detail' entry.id %}">
<button class="btn btn-secondary">Cancel</button>
</a>
</div>
I want both the Confirm and Cancel buttons to be aligned next to eachother, but if I put the Cancel besides the Confirm button or in a div inside of the form it too performs the delete action.
In Django using Bootstrap.
Your easiest solution is to put the cancel button in your form aswell, since your form is a block level element it wont let you put it next to it unless you change it to an inline level element. or make the parent a flexblox or grid container.
The solution:
.button--container {
display: flex;
justify-content: space-between
}
<div class="container py-5">
<div class="pull-left" style="margin-right:5px">
<form method="post">
{% csrf_token %}
<p>
<h3>
Do you want to delete <em>"{{ entry.title }}"</em> posted on {{ entry.date_created|date:'Y-m-d' }}?
</h3>
</p>
<div class="button--container">
<button class="btn btn-danger" type="submit" value="Confirm">Confirm</button>
<a class="btn btn-secondary" href="{% url 'entry-detail' entry.id %}">Cancel</a>
</div>
</form>
</div>
</div>
You will also notice I have changed your markup from <a><button /></a> to <a></a>. This is because you are not allowed to put an anchor tag inside a button or a button inside an anchor.
I have 3 elements that are displayed when hovering on the img element.
the problem is that when I hover over the icons, hovering over image disrupts and icons start flashing.(hovering happens back and forth between image and icon)
I know that I can add some class like this:
.dark-shield {
pointer-events: none;
}
to icons, and it fixes it but then I wont be able to apply the click event.
I appreciate if someone can help.
here is my code for display bellow:
.invisible {
visibility: hidden;
}
<div class="container transition-3d-hover ">
<a href="{% url "gallery-post" post.id %}">
<img id="{{ post.id }}" class="rounded "
src="{{ post.photo.url }}"
onmouseenter="f(this)"
onmouseleave="f(this)"
>
</a>
<i id="complain-icon-{{ post.id }}"
class=" fas fa-angry complain-box invisible icon-big dark-shield"></i>
<i id="fav-icon-{{ post.id }}"
class=" fa fa-hand-point-up like-box invisible icon-big "></i>
<i id="score-icon-{{ post.id }}"
class=" fas fa-heart fav-box invisible icon-big "></i>
</div>
<script>
function f(e) {
var complain = "#" + "complain-icon-" + e.id
var fav = "#" + "fav-icon-" + e.id
var score = "#" + "score-icon-" + e.id
$(complain).toggleClass('invisible')
$(fav).toggleClass('invisible')
$(score).toggleClass('invisible')
}
</script>
In your code, as you can see, the icons are not a part of the image. So, the icons become invisible when you hover them. After they are invisible, you hover over the image again, and the icon becomes visible. This keeps repeating. So, here is a code snippet that would solve this issue:
.img1 {
width: 100%;
height: 100%;
}
.icon {
color: white;
font-size: 30px;
position: absolute;
top: 40%;
left: 40%;
display: none;
}
#wrapper {
float: left;
width: 50%;
height: 30%;
cursor: pointer;
}
#wrapper:hover .icon {
display: block;
}
<!DOCTYPE html>
<html>
<head>
<script src="https://kit.fontawesome.com/a076d05399.js"></script>
</head>
<body>
<div id="wrapper">
<img src="https://cdn.mos.cms.futurecdn.net/wtqqnkYDYi2ifsWZVW2MT4-1200-80.jpg" class="img1">
<i class="fas fa-angry icon"></i>
<i class="fa fa-hand-point-up icon" style="top: 20%;"></i>
<i class="fas fa-heart icon" style="left: 10%; top: 20%;"></i>
</div>
</body>
</html>
Please note: This code might not work in the snippet, but it would work if you create a new file with this code.
Code explained
As I have already explained, the icons are not a part of the image. So, when you hover them, they become invisible. However, in my code, I have inserted the images, as well as the icons inside one div. Now, whenever you hover the div, the icons are visible. Since the icons are a part of the same div, they would remain visible.
I have an accordion in Html
<accordion [isAnimated]="true">
<accordion-group heading="Date Created">
{{ example text }}
</accordion-group>
</accordion>
I want to reduce the size of the box, text and the text when clicked. Basically reduce the size of entire box. How to do that?
I have tried these below which reduce the Header text and body text but not the box
<accordion-group panalClass="xyz">
<button
class="btn btn-link btn-block clearfix"
accordion-heading
type="button" panalClass="xyz"
>
<div class="pull-centre float-centre" style="background-color: blue;">
Date Created
</div>
</button>
{{ example text }}
</accordion-group>
I want to align the element with rest of the page.
Since I didnt find an option to resize it I found out that I have to use the angular generated classes (Shadow CSS concept) which can be seen in the elements section in console page. In this case it was ".panel-heading" and ".panel-body".
Use the angular class within your own class to make the effect IN styles.css to get the effect. Like this:
.accordion-small {
.panel-heading {
padding: 0px;
}
}
.accordion-small {
.panel-body {
padding: 5px;
font-size: small;
text-align: center;
}
}
In html:
<accordion [isAnimated]="true" class="accordion-small">
<accordion-group>
<button
class="btn btn-link btn-block clearfix"
accordion-heading
type="button"
>
<div class="pull-centre float-centre header-name">
Date Created
</div>
</button>
{{ example text }}
</accordion-group>
</accordion>
In component css
.header-name {
font-size: small;
}
Result:
Another way is you can use [panelClass]="customClass" to define the custom styling for your ngx-bootstrap accordion.
In css:
.custom-accordion-style {
/*any size you want*/
line-height: 30px;
font-size: small;
}
In ts:
customClass='custom-accordion-style';
In html:
<accordion [isAnimated]="true">
<accordion-group [panelClass]="customClass">
<button class="btn btn-link btn-block clearfix"
accordion-heading
type="button">
<div class="pull-centre float-centre">
Date Created
</div>
</button>
{{ example text }}
</accordion-group>
</accordion>
I have a button to go to a link, but when the visitor is the user that created the page, that button needs to also have an X so it can be deleted by the user-owner.
1) Tags: The solution that works has the problem that: I can make the 2 buttons, but it is difficult to spot visually which X corresponds with each button (when there is more than one).
2) Tags: On the other side, when I put them together you can not click on the X, because it always takes you to the buttons' link.
NEED: I need a button with two parts, one for the delete X and another for the link of the text, but I do not see how to do it. Please, see the image.
<div class="g-mb-30">
<h6 class="g-color-gray-dark-v1">
<button id="jh-create-entity"
*ngIf="owner === post.userId"
class="btn btn-primary float-right jh-create-entity create-tag"
[routerLink]="['/tag/new']" [queryParams]="{ 'postIdEquals': post.id }">
<fa-icon [icon]="'plus'"></fa-icon>
</button>
<strong class="g-mr-5">Tags:</strong>
<span *ngFor="let tag of post.tags">
<a (click)="removePostTag(tag.id, post.id)">
<fa-icon [icon]="'times'"></fa-icon>
</a>
<a [routerLink]="['/tag', tag.id, 'view' ]" class="u-tags-v1 g-font-size-12 g-brd-around g-brd-gray-light-v4 g-bg-primary--hover g-brd-primary--hover g-color-black-opacity-0_8 g-color-white--hover rounded g-py-6 g-px-15 g-mr-5">
{{tag.tagName}}
</a>
</span>
</h6>
<h6 class="g-color-gray-dark-v1">
<button id="jh-create-entity"
*ngIf="owner === post.userId"
class="btn btn-primary float-right jh-create-entity create-tag"
[routerLink]="['/tag/new']" [queryParams]="{ 'postIdEquals': post.id }">
<fa-icon [icon]="'plus'"></fa-icon>
</button>
<strong class="g-mr-5">Tags:</strong>
<span *ngFor="let tag of post.tags">
<a [routerLink]="['/tag', tag.id, 'view' ]" class="u-tags-v1 g-font-size-12 g-brd-around g-brd-gray-light-v4 g-bg-primary--hover g-brd-primary--hover g-color-black-opacity-0_8 g-color-white--hover rounded g-py-6 g-px-15 g-mr-5">
<span>
<a (click)="removePostTag(tag.id, post.id)">
<fa-icon [icon]="'times'"></fa-icon>
</a>
</span>
{{tag.tagName}}
</a>
</span>
</h6>
EDIT Wayne: This does not work since the X (delete) does not work
<h6 class="g-color-gray-dark-v1">
<button id="jh-create-entity"
*ngIf="owner === post.userId"
class="btn btn-primary float-right jh-create-entity create-tag"
[routerLink]="['/tag/new']" [queryParams]="{ 'postIdEquals': post.id }">
<fa-icon [icon]="'plus'"></fa-icon>
</button>
<strong class="g-mr-5">Tags:</strong>
<section style="display: flex; justify-content: space-around;">
<span *ngFor="let tag of post.tags">
<a [routerLink]="['/tag', tag.id, 'view' ]" class="u-tags-v1 g-font-size-12 g-brd-around g-brd-gray-light-v4 g-bg-primary--hover g-brd-primary--hover g-color-black-opacity-0_8 g-color-white--hover rounded g-py-6 g-px-15 g-mr-5">
<span>
<a (click)="removePostTag(tag.id, post.id)">
<fa-icon [icon]="'times'"></fa-icon>
</a>
</span>
{{tag.tagName}}
</a>
</span>
</section>
</h6>
Currently, in your second solution (which I recommend from a UX standpoint), you have the X icon within the element that links to /tag.
If you move that icon to the outside of your anchor, it should work properly.
Check my quick example below.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" integrity="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/" crossorigin="anonymous">
</head>
<body>
<section style="display: flex; justify-content: space-around;">
<span style="border: 1px solid gray; padding: 5px;">
<a onclick="remove()"><i class="fas fa-times"></i></a>
<a onclick="link()">Link</a>
</span>
<span style="border: 1px solid gray; padding: 5px;">
<a onclick="remove()"><i class="fas fa-times"></i></a>
<a onclick="link()">Link</a>
</span>
<span style="border: 1px solid gray; padding: 5px;">
<a onclick="remove()"><i class="fas fa-times"></i></a>
<a onclick="link()">Link</a>
</span>
<span style="border: 1px solid gray; padding: 5px;">
<a onclick="remove()"><i class="fas fa-times"></i></a>
<a onclick="link()">Link</a>
</span>
</section>
</body>
<script>
function remove() {
alert('Removed an element!');
}
function link() {
alert('Clicked a link!');
}
</script>
</html>
Edit: Changed to use FA so that it is hopefully more clear.
Edit: Here is an example of how you would apply what I am explaining in your own code. If this does not work, inspect your CSS.
<h6 class="g-color-gray-dark-v1">
<button id="jh-create-entity" *ngIf="owner === post.userId" class="btn btn-primary float-right jh-create-entity create-tag"
[routerLink]="['/tag/new']" [queryParams]="{ 'postIdEquals': post.id }">
<fa-icon [icon]="'plus'"></fa-icon>
</button>
<strong class="g-mr-5">Tags:</strong>
<section style="display: flex; justify-content: space-around;">
<span *ngFor="let tag of post.tags">
// Note that here I have moved the X link to be a child of the span
<a (click)="removePostTag(tag.id, post.id)">
<fa-icon [icon]="'times'"></fa-icon>
</a>
// The tag name link is on the same level as the X (child of the span)
<a [routerLink]="['/tag', tag.id, 'view' ]" class="removed-classes">
{{tag.tagName}}
</a>
</span>
</section>
</h6>
I have such a block of elements:
<div class="dropdown">
<button class="btn" >
<i class="fa fa-search"></i>
<i class="fa fa-caret-down"></i>
</button>
<input type="search" class="search-field" placeholder="Search...">
<div class="dropdown-content">
Link 1
Link 2
Link 3
</div>
</div>
Now I want to display the dropdown-content when I am hovering just over button. .btn:hover .dropdown-content{ dislpay: block; } has no effect, however hovering over the whole block (dropdown) does work. It is also possible to wrap the whole block in an another block and pull the <input> to the outer block. But than I'm getting a similar problem with hovering over <input>.
My questions are now.
Why isn't it possible to display the block hovering over the button
Why hovering over <input> has no effect when it is in outer block (this
is not presented in the code above)
How can I fix it ?
There is no element .btn .dropdown-content. .dropdown-content is a sibling of .btn. So you can use following code. Please check...
.btn:hover + input + .dropdown-content {
display: block;
background: #000;
}
<div class="dropdown">
<button class="btn" >
button
<i class="fa fa-search"></i>
<i class="fa fa-caret-down"></i>
</button>
<input type="search" class="search-field" placeholder="Search...">
<div class="dropdown-content">
Link 1
Link 2
Link 3
</div>
</div>
Or you can use .btn:hover ~ .dropdown-content { this CSS also.
Fiddle