If i hover the .header_kosar_link, the .cart_hover div will be displayed. Now, it will be displayed by jquery, with the code below.
How can i make the div showned, when i move the cursor into it?
.cart_hover{ max-width:300px; display:none; background:#fff; position:absolute; right:0; top:60px; z-index:999; padding:15px; border:1px solid #ccc; border-radius:5px; -webkit-box-shadow: 0 5px 16px rgba(50, 56, 77, 0.35);
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/all.min.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="col-md-2 d-flex justify-content-center justify-content-md-end align-items-center header_div">
<a href="https://projektar.hu/kosar" title="Kosár" class="header_kosar_link d-flex align-items-center">
<i class="fa fa-shopping-basket fejlec_kosar_ikon" aria-hidden="true"></i>
<span id="header_kosar_text" class="header_kosar_text">Cart</span>
</a>
</div>
<div class="clearfix"></div>
<div class="cart_hover">Cart Hover</div>
<script>
$('.header_kosar_link').on('mouseover', function() {
$('.cart_hover').css('display', 'block');
});
$('.header_kosar_link').on('mouseout', function() {
$('.cart_hover').css('display', 'none');
});
</script>
The .cart_hover div has this css:
.cart_hover{ max-width:300px; display:none; background:#fff; position:absolute; right:0; top:60px; z-index:999; padding:15px; border:1px solid #ccc; border-radius:5px; -webkit-box-shadow: 0 5px 16px rgba(50, 56, 77, 0.35);
2
Answers
You can solve this easily by CSS. No need for javascript/JQuery. Just add a
:hover
selector on the parent element. I would also advice to usevisibility
instead ofdisplay
.You can achieve this by using combination of ~ and nth-of-type, note that I added class
cart-container
, notice that my selector is on the parent of the<a>
tag: