How to make a button fit into an upvote icon - html

I was trying to make a button that has the shape of an icon but the button overflows the icon
.upvote, .downvote {
font-size: 55px;
}
.up {
color: green;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<button class="upvote up"><i class="fa fa-caret-up"></i></button>
<a class="upvote up"><i class="fa fa-caret-up"></i></a>
It works fine for a tag but I want to use it in a submit form so I can't use a tag.

Why don't use directly the icon as button like:
.upvote,
.downvote {
font-size: 55px;
}
.up {
color: green;
cursor: pointer;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<i class="fa fa-caret-up fa-5x upvote up"></i>
i add fa-5x for the size and cursor: pointer; for cursor in hover state.
Into a form:
const myform = document.getElementById('myform');
document.querySelector('.up').addEventListener('click', () => {
myform.submit();
});
.upvote,
.downvote {
font-size: 55px;
}
.up {
color: green;
cursor: pointer;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<form id='myform'>
<i class="fa fa-caret-up fa-5x upvote up"></i>
</form>
Else you can use SVG sprites Link official, i can't post an example for Same origin policy

Instead of using an icon inside the button, you can follow this method. Here I have modified the button matching the styles of the icon. This way you can keep the properties of a button, while having a different design.
Otherwise, you can add a clickEventListener to the icon itself as Simone's answer
.arrow-up {
display: inline-block;
width: 0;
height: 0;
background-color: #fff;
padding: 0;
border: 0;
outline: none;
border-left: 20px solid transparent;
border-right: 20px solid transparent;
border-bottom: 20px solid green;
}
<button class='arrow-up'></button>
Please find the same for arrow-down
.arrow-down {
display: inline-block;
width: 0;
height: 0;
background-color: #fff;
padding: 0;
border: 0;
outline: none;
border-left: 20px solid transparent;
border-right: 20px solid transparent;
border-top: 20px solid green;
}
<button class='arrow-down'></button>
This way you can completely avoid the usage of fa icons if this is your only requirement.

Check the margin and padding of the icon as well as the button and also define height and width by yourself.
.upvote, .downvote {
margin: 0px;
padding:0px;
font-size: 55px;
}
.up {
margin: 0px;
padding:0px;
height:..;
color: green;
}

Related

HTML / CSS: how to style a Div such that it matches the styling/behavior of Bootstrap buttons

I have a webpage that uses Bootstrap's button class="btn btn-sm btn-outline-primary".
On the same page, I render a Div with JavaScript that's clickable. I assign it an orders-data class:
...
element.classList.add('orders-data');
I would like to get the Div to match the styling of the buttons using some CSS. This is what I have so far:
CSS
.orders-data {
border: 1px solid #007bff;
border-radius: 5px;
margin-top: 5px;
padding-left: 10px;
}
.orders-data:hover {
background-color: #007bff;
border: 1px solid #007bff;
color: white;
border-radius: 5px;
margin-top: 5px;
padding-left: 20px;
This seems to work. But, is there a more elegant way to do this?
Thanks!
You can use this style to make Div element similar to Bootstrap Button.
.orders-data {
cursor:pointer;
color: #fff;
background-color: #007bff;
border-color: #007bff;
border: 1px solid transparent;
padding: .375rem .75rem;
font-size: 1rem;
line-height: 1.5;
border-radius: .25rem;
transition: color .15s ease-in-out,background-color .15s ease-in-out,border-color .15s ease-in-out,box-shadow .15s ease-in-out;
user-select: none;
display: inline-block;
font-weight: 400;
}
.orders-data:hover {
color: #fff;
background-color: #0069d9;
border-color: #0062cc;}
You can add this styling to the div:
.orders-data {
display: block;
width: 115px;
height: 25px;
padding: 10px;
text-align: center;
border-radius: 5px;
color: white;
font-weight: bold;
line-height: 25px;
background-color: #0d6efd;
border-color: #0d6efd;
}
.orders-data:hover {
background-color: #007bff;
border: 1px solid #007bff;
color: white;
border-radius: 5px;
margin-top: 5px;
padding-left: 20px;
}
<div class="orders-data"></div>
This looks more like the button you want:
.orders-data {
display: inline-block;
border: 1px solid transparent;
background-color: rgb(239, 239, 239);
border-radius: 3px;
line-height: 1.5;
font-size: 12px;
padding: 5px 10px;
text-align: center;
cursor: pointer;
}
.orders-data:active{
outline:5px auto rgb(14,98,201) ;
}
<div class='orders-data'>
Bootstrap Button
</div>
welcome here bro,
this is work without any problems but you can take more fast way than this
you can just add the button classes for div this classes global in bootstrap you can use it in any element you want like
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/5.0.2/css/bootstrap.min.css" rel="stylesheet" />
<button class="btn btn-sm btn-outline-primary"> button</button>
<div class="btn btn-sm btn-outline-primary">
button
</div>
because of : element.classList.add('orders-data'); you use,
You can add the bootstrap classes to your element going through a loop, so need to write them again.
exemple to demonstrate the idea :
let el = document.querySelector('a');
const classS = ['btn', 'btn-sm', 'btn-outline-primary'];
for (i = 0; i < classS.length; i++) {
el.classList.add(classS[i])
}
.shadow {
box-shadow: 2px 2px 2px black
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/5.0.2/css/bootstrap.min.css" rel="stylesheet" />
<button class="btn btn-sm btn-outline-primary">hello</button>
<a class="shadow" href="#">the world</a>
(if your element has no other class, then setAttribute at once will do):
let el = document.querySelector('a');
el.setAttribute('class','btn btn-sm btn-outline-primary' ) ;
.shadow {
box-shadow: 2px 2px 2px black
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/5.0.2/css/bootstrap.min.css" rel="stylesheet" />
<button class="btn btn-sm btn-outline-primary">hello</button>
<a class="shadow" href="#">the world</a>
<p><code>setAttribute()</code> removes any value already there , shadow class is not there anymore!</p>

How to create link in content element

I have been tasked with creating this.
I can create the box, font-awesome icon and the non-linking text using a pseudo element content, but I am unable to create the Learn More link (with a span class to include the >).
If I add text directly into the html, it will not fill the box (and spills out below it). I would also be forced to use inline styles to keep it top-aligned with the !.
We want to keep this in the CSS if at all possible. I realize that the real answer is that you can't do it, but I'm looking for a workaround to make it work.
This is the CSS I can use to place the non-linking message:
&:after {
color: #7b7b7b;
margin-top: -43px;
padding-left: 19%;
line-height: 18px;
display: flex;
font-weight: normal;
content: "You are no longer on FPC, you will now be back to your regular contract.";
#media #{$small} {
padding-left: 15%;
margin-top:-37px;
}
}
&:before {
color: #7b7b7b;
margin-left: 10px;
}
And this is the line of HTML:
<i class="fa fa-exclamation-circle"></i>; Learn more <span class="arrow-right"></span>
Does anyone have a solution to help me make this work?
Thanks
Here is a different structure & CSS if you end up going in that direction.
.message {
border: 2px solid #7b7b7b;
border-radius: 2px;
position: relative;
width: 220px;
font-size: 13px;
font-family: Arial;
background: #f7fcff;
padding: 7px 8px 5px 42px;
}
.message>.message-icon {
position: absolute;
color: #7b7b7b;
font-size: 26px;
left: 10px;
}
p {
color: #7b7b7b;
margin: 0 0 3px 0;
}
a {
color: #1464ae;
font-size: 12px;
text-decoration: none;
}
a .action-icon {
margin-left: 3px;
font-size: 10px;
}
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<div class="message">
<span class="message-icon"><i class="fa fa-exclamation-circle"></i></span>
<p>You are no longer on FPC, you will now be back to your regular contract.</p>
<a href="">Learn More
<span class="action-icon"><i class="fa fa-chevron-right"></i></span>
</a>
</div>

Two font awesome arrows with one on top of the other with a circle around them

I have this image:
and I tried to do the same in HTML and CSS, with two font awesome icons. I put the position:absolute for one of the icon to be close to the other. I tried to make the circle around but without any success. Someone please give me a hand.
.formular {
position: relative;
}
.formular a {
text-decoration: none;
}
.circle .fa-caret-right {
font-size: 17px;
color: #000;
}
.circle {
position: relative;
border: 1px solid #CCCCCC;
border-radius: 50%;
background-color: #dce0e1;
padding: 5px;
}
.circle .fa-caret-right:first-child {
position: absolute;
left: 4px;
}
.circle .fa-caret-right:last-child {
position: relative;
}
.formular .text {
font: normal 15px 'CenturyGothic-Bold';
color: #028A92;
}
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css">
</head>
<body>
<div class="formular">
<a href="#" title="Click here">
<span class="circle">
<i class="fa fa-caret-right" aria-hidden="true"></i>
<i class="fa fa-caret-right" aria-hidden="true"></i>
</span>
<span class="text">Ask for our forms</span>
</a>
</div>
</body>
</html>
i have change this
.formular .circle {
background: #efeded none repeat scroll 0 0;
border: 1px solid #cbcbcb;
border-radius: 50%;
color: #000;
display: inline-block;
padding: 3px 3px 3px 7px;
position: relative;
text-align: center;
}
<span class="circle">
<i class="fa fa-forward" aria-hidden="true"></i>
<!--<i class="fa fa-caret-right" aria-hidden="true"></i>-->
</span>
.formular {
position: relative;
}
.formular a {
text-decoration: none;
}
.circle .fa-caret-right {
font-size: 17px;
color: #000;
}
.formular .circle {
background: #efeded none repeat scroll 0 0;
border: 1px solid #cbcbcb;
border-radius: 50%;
color: #000;
display: inline-block;
padding: 3px 3px 3px 7px;
position: relative;
text-align: center;
}
}
.circle .fa-caret-right:first-child {
position: absolute;
left: 4px;
}
.circle .fa-caret-right:last-child {
position: relative;
}
.formular .text {
font: normal 15px 'CenturyGothic-Bold';
color: #028A92;
}
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css">
</head>
<body>
<div class="formular">
<a href="#" title="Click here">
<span class="circle">
<i class="fa fa-forward" aria-hidden="true"></i>
<!--<i class="fa fa-caret-right" aria-hidden="true"></i>-->
</span>
<span class="text">Ask for our forms</span>
</a>
</div>
</body>
</html>
You probably need a bit more padding on .circle class,
eg:
.circle { padding: 10px }
This is not the best way to create this button, but as you just wanted a hand, hope that helps. :)
You will have to play around adjusting the shape of the circle a bit more to make it perfect.
Small Change In Css.
check the link below may Help You
.circle .fa-caret-right:first-child {
position: absolute;
left: 6px;
}
.circle .fa-caret-right:last-child {
position: relative;
left: 5px;
}
visit the link: https://jsfiddle.net/crxsL3qt/

Making a bootstrap input clickable with a font-awesome icon in it

I have a date input field, and a font awesome icon on top of it. The look is correct, but I can't click on the input when the mouse in on top of the icon. I've tried to fix this using z-index, but it's not working.
Here's what it looks like:
HTML
<div class="form-group inline-block Criteria__datePickerDiv">
<input type="text" name="dob" id="datepicker" placeholder="Birth Date" class="Criteria__datePicker" value=" {{ old($user->seekerProfile->dob->format('Y-m-d')) }}">
</div>
<span class="Criteria__calendar">
<i class="fa fa-calendar"></i>
</span>
CSS
.Criteria__datePicker {
border: none;
border-bottom: 3px solid $gray-light;
font-size: 20px;
text-shadow: 0 0 0 $gray-light;
color: transparent;
font-weight: 600;
width: 150px;
padding-right: 5px;
margin-left: 15px;
&:focus {
outline: none
}
}
.Criteria__datePicker:hover {
cursor: pointer;
}
.Criteria__datePicker:focus {
outline: none;
}
.Criteria__datePickerDiv {
z-index: 1;
}
.Criteria__calendar {
position: relative;
left: -15px;
font-size: 22px;
color: $brand_green;
z-index: 0;
}
Using the default Bootstrap styles, you can get close to what you're doing with an input group (example):
HTML:
<div class="buffer">
<div class="input-group">
<input class="form-control" aria-describedby="basic-addon2" type="text">
<span class="input-group-addon" id="basic-addon2">
<i class="glyphicon glyphicon-calendar"></i>
</span>
</div>
</div>
CSS:
.buffer
{
margin: 1em;
width: 200px;
}
.buffer .input-group input
{
border-right: none;
}
.buffer .input-group .input-group-addon
{
background: #fff;
border-left: none;
}
If you're going for a borderless style, you can get even closer:
.buffer
{
margin: 1em;
width: 200px;
}
.buffer .input-group
{
border: none;
}
.buffer .input-group input
{
border-right: none;
border: none;
border-bottom: solid 1px #d5d5d5;
box-shadow: none;
border-radius: 0;
}
.buffer .input-group .input-group-addon
{
background: #fff;
border: none;
border-bottom: solid 1px #d5d5d5;
border-radius: 0;
}
.buffer is simply a container/class I added to contain the input group - you can safely remove that.

Mouse hover triggers hover on itself and another div

I am trying to set something up where when someone hovers over .twitter-underline-1 it triggers the :hover for that class AND the :hover for the #twitter-1 id
vice verse
When someone hovers over #twitter-1 it triggers the :hover for that id AND the :hover for the .twitter-underline-1 class
I tried some recommended solutions from other who asked a similar question but nothing fully worked. Can anyone point me in the right direction?
.twitter-underline-1 {
border-bottom: 1px dotted #E0E0E0;
}
.twitter-underline-1:hover {
border-bottom: 1px solid #4099FF;
}
#twitter-1 {
padding-top: 402px;
font-size: 40px;
color: #E0E0E0;
margin-left: 45px;
}
#twitter-1:hover {
color: #4099FF;
}
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
<span class="twitter-underline-1">Blah blah text</span>
<div class="twitter">
<span title="Click to Tweet"><i id="twitter-1" class="fa fa-twitter"></i></span>
</div>
demo - http://jsfiddle.net/3855n719/
$('#twitter-1').hover(
function() {
$('.twitter-underline-1').addClass('hover');
},
function() {
$('.twitter-underline-1').removeClass('hover');
}
);
It can't be done without changing your html structure as it is impossible to select a previous element in css.
I think you have two options:
Surround it with a .twitter-container and add the :hover class there. This might only be an option if you don't have any other content between the .twitter-underline and #twitter-1 as hovering over them would also add the styling.
Move the .twitter-underline element in the html below the #twitter-1, select it with a
sibling selector like + or ~ and use position: absolute to put it back in its proper place.
Example for method 1
.twitter-underline-1 {
border-bottom: 1px dotted #E0E0E0;
}
#twitter-1 {
padding-top: 402px;
font-size: 40px;
color: #E0E0E0;
margin-left: 45px;
}
.twitter-container:hover .twitter-underline-1 {
border-bottom: 1px solid #4099FF;
}
.twitter-container:hover #twitter-1 {
color: #4099FF;
}
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
<div class="twitter-container">
<span class="twitter-underline-1">Blah blah text</span>
<div class="twitter">
<span title="Click to Tweet"><i id="twitter-1" class="fa fa-twitter"></i></span>
</div>
</div>
Example for method 2
.twitter-container {
position: relative;
padding-top: 1em;
}
.twitter-underline-1 {
position: absolute;
top: 0;
left: 0;
border-bottom: 1px dotted #E0E0E0;
}
#twitter-1 {
padding-top: 402px;
font-size: 40px;
color: #E0E0E0;
margin-left: 45px;
}
#twitter-1:hover {
color: #4099FF;
}
#twitter-1:hover + .twitter-underline-1 {
border-bottom: 1px solid #4099FF;
}
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
<div class="twitter-container">
<div class="twitter">
<span title="Click to Tweet">
<i id="twitter-1" class="fa fa-twitter"></i>
<span class="twitter-underline-1">Blah blah text</span>
</span>
</div>
</div>