Making clickable div - html

I want to make clickable div. Currently, it is only working when I click the red rectangle. How can I make the entire div clickable?
HTML
<div class="button">
<a href="#">
<p class="instagram-button">
<i class="fab fa-instagram"></i>
<span>Instagram Page</span>
</p>
</a>
</div>
CSS
.button {
background-color: transparent;
cursor: pointer;
border: 2px solid #737373;
margin: 20px auto 0;
display: flex;
align-items: center;
justify-content: center;
width: 200px;
height: 40px;
}
.button span {
font-size: 14px;
color: #737373;
text-transform: uppercase;
}
.fab {
color: #737373;
padding-right: 5px;
}

Make your <a> tag display:block and 100% height & width so the <a> tag has the same size your <div> tag

function redirect(){
window.location = "yourWebsite";
}
.button {
background-color: transparent;
cursor: pointer;
border: 2px solid #737373;
margin: 20px auto 0;
display: flex;
align-items: center;
justify-content: center;
width: 200px;
height: 40px;
}
.button span {
font-size: 14px;
color: #737373;
text-transform: uppercase;
}
.fab {
color: #737373;
padding-right: 5px;
}
<div onclick='redirect()' class="button">
<a href="#">
<p class="instagram-button">
<i class="fab fa-instagram"></i>
<span>Instagram Page</span>
</p>
</a>
</div>
Simple. Just redirect with the whole 'division' instead of just the 'anchor'.
(yes. it is supposed to throw a 404 error, I set window.location to 'yourWebsite' which is invalid.)
Suggestion: To make your anchor look more like a button, remove that underline from it with text-descoration: none.

If you can use JQuery, do
$(".button").click(function (){window.location.href="/wherever/you/wish/to/go"})
also, what's wrong with an onclick attribute?

Simply add an event listener to the button .div and assign a function to the event that redirects the window to a new location.

Related

Insert a div inside an anchor removing the anchor styling in the div elements

I'm trying to make the whole div clickable, but removing any styling that the anchor adds to the div. I cannot use JS for this.
HTML code
<a href="https://stackoverflow.com" target="_blank">
<div class="style1">
<div class="style2">
<div class="style3_">
<div>
<div class="text1">
Here is the Text 1
</div>
<span class="text2">
Here is the text 2
</span>
</div>
<a href="https://stackoverflow.com" target="_blank">
Link
</a>
</div>
</div>
</div>
</a>
CSS code:
.style1 {
padding: 16px;
}
.style2 {
border-radius: 8px;
background-color: #fff;
border: 1px solid #dadce0;
box-shadow: none
}
.style3 {
display: flex;
padding: 16px;
justify-content: space-between;
align-items: center;
}
.text1 {
line-height: 1.5rem;
font-size: 1rem;
letter-spacing: .00625rem;
font-weight: 500;
}
.text2 {
line-height: 1rem;
font-size: .75rem;
letter-spacing: .025rem;
font-weight: 400;
}
a tags usually adds an underline to indicate that it is a link, that's actually just a text decoration, to remove that you can add text-decoration: none; to whatever class you want the style to be removed, or you can add that to the anchor tag directly. See the snippet below for your reference:
.style3 {
display: flex;
align-items: center;
justify-content: space-between;
border-radius: 8px;
background-color: #fff;
border: 1px solid #dadce0;
box-shadow: none;
padding: 16px;
width: max-content;
gap: 2rem;
}
.text1 {
line-height: 1.5rem;
font-size: 1rem;
letter-spacing: .00625rem;
font-weight: 500;
}
.text2 {
line-height: 1rem;
font-size: .75rem;
letter-spacing: .025rem;
font-weight: 400;
}
a{
text-decoration: none;
color: black;
flex: 1;
height: 100%;
}
<a href="https://stackoverflow.com" target="_blank">
<div class="style3">
<div>
<div class="text1">
Here is the Text 1
</div>
<span class="text2">
Here is the text 2
</span>
</div>
<div>
Link
</div>
</div>
</a>

How to remove space between icon and surrounding div

I have a code as follows:
<div className="wrapper">
<i class="fa fa-quote-left" style="font-size: 10rem;"></i>
<div class="text">Title</div>
</div>
With next css:
.wrapper{
display: flex;
flex-direction: column;
border: 2px solid #f8f8f8;
}
.text{
font-size: 16px;
font-weight: 300;
margin-top: 0.25rem;
}
Why my icon takes more space than it should take.
How can I remove it?
Here is the fiddle.
not the best way but you can use line-height
for example :
i{
font-size: 10rem;
line-height: 7rem;
margin-top: 1rem;
}

Targeting span within button tag on hover: How to change border color and pointer?

I have some cards and want to change the properties border-color and pointer-events when a user hovers a span tag which is inside a button tag.
This is no problem if i use a tag, see First Card on the left:
https://codepen.io/anon/pen/JzzEvj
However, when using a PRG pattern with form and button changing the pointer event and the border-bottom color when hovering does not work with Firefox. (See Second Card on the right side)
Any ideas how to fix this in Firefox?
Desired outcome see Card on the left:
The cursor should have pointer state when hovering the image
The cursor should have pointer state when hovering the card heading
The card heading's border-bottom color should change color when hovering the card heading
I spend a lot of time on this issue but only found this solution https://codepen.io/anon/pen/PLLWxJ which is not exactly the same, because
the card heading's border-bottom color changes when hovering any part of the card.
all parts of the card look clickable when hovering. The cursor state should only change to pointer when hovering the image or the card heading.
a {
text-decoration: none;
}
.product-cards-wrapper {
background: #fff;
padding: 64px 0;
}
.product-cards {
display: flex;
justify-content: center;
flex-wrap: wrap;
}
.product-card {
border: 1px dotted #ccc;
cursor: default;
margin: 0 16px 32px;
width: 250px;
text-align: center;
}
.product-card-img-wrapper {
align-items: center;
cursor: pointer;
display: flex;
justify-content: center;
height: 150px;
line-height: 0;
margin-bottom: 16px;
}
.product-card-heading {
border-bottom: 1px solid #e5e5e5;
color: #2bb3f0;
display: inline;
font-family: sans-serif;
font-size: 18px;
font-weight: 700;
line-height: 1.6;
text-align: center;
transition: border-color .2s;
}
.product-card-heading:hover {
border-color: #2bb3f0;
cursor: pointer;
}
.product-card-label {
background: #fee5ad;
border-radius: 99px;
color: rgba(0, 0, 0, .54);
cursor: text;
font-family: sans-serif;
font-size: 14px;
font-weight: 600;
margin-top: 4px;
padding: 2px 10px;
}
.product-card>button {
background: 0;
border: 0;
padding: 0;
width: 100%;
}
.product-card-heading {
border-bottom: 1px solid #e5e5e5;
color: #2bb3f0;
cursor: pointer;
transition: border-color .2s;
}
.product-card button .product-card-img-wrapper,
.product-card button .product-card-heading {
cursor: pointer;
}
.product-card button .product-card-heading:hover {
border-color: #2bb3f0;
}
.product-card-labels {
display: block;
font-family: sans-serif;
}
<section class=product-cards-wrapper>
<div class=product-cards>
<a class=product-card href=#>
<div class=product-card-img-wrapper>
<img src=https://via.placeholder.com/160x150 alt="">
</div>
<div class=product-card-heading>First Card</div>
<div class=product-card-labels><span class=product-card-label>Label</span></div>
</a>
<form class=product-card action=# method=post target=_blank>
<button name=l value=123>
<span class=product-card-img-wrapper>
<img src=https://via.placeholder.com/120x150 alt="">
</span>
<span class=product-card-heading>Second Card</span>
<span class=product-card-labels><span class=product-card-label>Label</span></span>
</button>
</form>
</div>
</section>
This was a six years old Firefox bug which was fixed in Firefox 66.
Children of the button tag now do respond to :hover. :)

Can I achieve a scrollable flex container without a scrollbar on mobile devices using css only?

I uploaded a video here : https://streamable.com/uyddy
I am asking if I can somehow hide the horizontal scrollbar in that specific div, while still being able to scroll? I want to achieve this on mobile devices.
I attached the code here :
https://codepen.io/UrsuGrizzly/full/aVRZyg/
https://jsfiddle.net/o2ucuorL/
<div id="bottom">
All
Images
Videos
News
Maps
<a id="books" href="#">Books</a>
<a id="flights" href="#">Flights</a>
<a id="personal" href="#">Personal</a>
<a id="stools" href="#">Search tools</a>
<a id="moar" href="#">More</a>
Settings
<a href="#" id="tools">Tools</a
</div>
body{
font-family: arial,sans-serif;
font-size: 13px;
}
#bottom{
grid-area: 2/1/3/3;
display: flex;
overflow-x:scroll;
}
#bottom a{
font-size: 12px;
text-transform: uppercase;
text-decoration: none;
color: rgba(0,0,0,0.54);
padding: 14px 16px 12px 16px;
}
#bottom #stools{
border-left: 1px solid rgba(0,0,0,.12);
padding: 14px 16px 12px 24px;
white-space:nowrap;
}
#bottom #all{
color: #4285f4;
border-bottom: 2px solid #4285f4;
}
what I'd do is just to wrap the #bottom div inside a parent div with a fixed height and the overflow property set to hidden. Then you just have to give the #bottom div a padding-bottom with the same height as the scrollbar has (like 10px more or less). And thats all :), works great. Leave here the code:
// HTML Part
<div class="container">
<div id="bottom">
All
Images
Videos
News
Maps
<a id="books" href="#">Books</a>
<a id="flights" href="#">Flights</a>
<a id="personal" href="#">Personal</a>
<a id="stools" href="#">Search tools</a>
<a id="moar" href="#">More</a>
Settings
Tools
</div>
</div>
// CSS Part
body {
padding: 0;
margin: 0;
font-family: arial,sans-serif;
font-size: 13px;
}
.container {
height: 43px;
width: 100%;
overflow: hidden;
}
#bottom {
grid-area: 2/1/3/3;
display: flex;
overflow-x: scroll;
padding-bottom: 10px;
}
#bottom a {
font-size: 12px;
text-transform: uppercase;
text-decoration: none;
color: #0000008a;
padding: 14px 16px 12px 16px;
white-space: nowrap;
}
#bottom a#all {
color: #4285f4;
border-bottom: 2px solid #4285f4;
}

Change Font Awesome's icon color with hover

I just started programming and i need some help.
I'm using Font Awesome icons and i'm trying to change it's color when hovered but don't know why it isn't working. I looked up for other people having the same problem here, tried their solutions but it's still not working :(
here's part of my HTML code:
<footer>
<div class="row container">
<div class="logo-rodape col-md-2">
<img src="img/logo-principal-white-gota.png" alt="Logo Picada Zero">
</div>
<div class="r-content col-md-4">
<p class="slogan-title">CLEAN AND PROTECTION</p>
<p class="slogan-sub">Proteção e limpeza para sua família</p>
</div>
<div class="r-social col-md-5">
<i class="fa fa-facebook fa-2x" aria-hidden="true" style="color:#fff"></i>
<i class="fa fa-vimeo fa-2x" aria-hidden="true" style="color:#fff"></i>
</div>
</div>
</footer>
And here's all my footer's CSS:
footer{
background: url(../img/rodape-background.png);
clear: both;
padding: 50px 0;
}
footer .container{
position: relative;
margin-left: 80px;
box-sizing: border-box;
margin-top: 50px;
}
.logo-rodape {
padding: 0;
margin: 0 auto;
box-sizing: border-box;
display: inline-block;
}
.r-content {
padding: 0;
box-sizing: border-box;
display: inline-block;
text-align: left;
margin-left: 30px;
margin-top: 20px;
}
.slogan-title {
font-family: "avenir next condensed";
font-size: 0.3em;
font-size: calc(0.3em + 1vw);
#include screen-above(800px) {
font-size: 0.4em;
}
font-weight: 600;
letter-spacing: 1.5px;
margin-bottom: -2px;
color: #fff;
}
.slogan-sub {
font-family: 'Lato', sans-serif;
font-size: 0.2em;
font-size: calc(0.2em + 1vw);
#include screen-above(800px) {
font-size: 0.3em;
}
font-weight: 300;
letter-spacing: 1px;
color: #fff;
}
.r-social {
text-align: right;
box-sizing: border-box;
display: inline-block;
margin-top: 40px;
margin-left: 60px;
}
.fa-facebook {
padding-right: 20px;
}
.fa-facebook:hover {
color: #57cdf7;
}
I'll be really glad with any suggestions, I tried out everything I know so far and couldn't get it right.
Thanks!
Looks like it's because you use inline style. It always has a higher priority. Also you're trying to change style on hover of an <i> tag, but you should do this with an <a>
Take a look:
a {
display: block;
}
.test1 {
color: red;
}
.test1:hover {
color: #57cdf7;
}
.test2 .fa-facebook:hover {
color: #57cdf7;
}
.test3 .fa-facebook:hover {
color: #57cdf7;
}
<a href="#" class="test1">
<i class="fa fa-vimeo fa-2x">facebook</i>
</a>
<a href="#" class="test2">
<i class="fa fa-facebook fa-2x">facebook</i>
</a>
<a href="#" class="test3">
<i class="fa fa-facebook fa-2x" style="color:green">facebook</i>
</a>
I recommend to assign a single class for <a> tags of your font awesome buttons, remove inline styles and move it to your css file.
As it is in the anchor tag you should be writing the CSS on hover with anchor tag. a:hover .fa-facebook { color: #57cdf7}
You can use this and check on your browser
for example :
i.fa.fa-facebook.fa-2x:hover {
color: red;
background-color: red;
}
/* hover state */
a:hover .far, a:hover .fas {
color:white;
}
/* normal state */
li a .far , li a .fas {
color:red;
}
it work for me.... thanks guy.