Say I have an element with the following structure:
<Link to={`/games/${game.id}`}>
<GameInfo/>
<CustomButton/>
</Link>
Is it possible for the button inside the link to behave independently from the link beneath without using the z-index css property? I'd like to do this while keeping the current behaviour in which hovering the button triggers both the hover effect for the button and for the link below.
Right now, if I click on the Add to Library button, the game gets added to the library but the Link below also gets triggered and the game profile page is open, which is not intended.
The only solution I can think of so far is something like this:
<div> // <= move link hover effects here
<Link to={`/games/${game.id}`}>
<GameInfo/>
</Link>
<CustomButton/>
</div>
But it's not ideal, because I would still like the area around the button to be part of the Link (so hover and the link itself work in the areas shown below).
Is z-index the only solution?
You can make use of preventDefault and stopPropagation to achieve this inside button click use like this below
<Link to="/game">
<div>
<button
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
//function to do your stuff
}}
>
Click Me
</button>
</div>
</Link>
You can check the demo here
https://codesandbox.io/s/adoring-sun-dwnde?fontsize=14&hidenavigation=1&theme=dark
Related
I have buttons that are close to each other that when the tooltip pops out it would block the other buttons out, here's a picture of the said problem:
If I hover the request button below the other one and then tries to hover the button above it, I will end up hovering on the tooltip instead of the button below it.
I can hide the tooltip on hover (see code below) using CSS but it produces a flickering effect when I hover to the next button then ends up not showing the tooltip on that specific next button.
.tooltip:hover {
display: none;
}
So my questions would be:
Is there a property on bootstrap-vue that would only show the tooltip when hovered on the button itself;
or hide the tooltip when hovering the tooltip itself;
If none, any alternative that would replicate the behavior I wanted without needing to change or edit each existing button on my app (preferred).
You can use the noninteractive modifier on the directive. (or prop if you're using the component)
This will make it so the tooltip can't be interacted with, so hovering the tooltip wont keep it visible.
new Vue({
el: "#app"
});
<link type="text/css" rel="stylesheet" href="//unpkg.com/bootstrap#4.5.3/dist/css/bootstrap.min.css" />
<link type="text/css" rel="stylesheet" href="//unpkg.com/bootstrap-vue#2.21.2/dist/bootstrap-vue.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.12/vue.min.js"></script>
<script src="https://unpkg.com/bootstrap-vue#2.21.2/dist/bootstrap-vue.js"></script>
<div id="app" class="p-5">
<b-button v-b-tooltip.noninteractive.hover title="Try and hover me!">
Hover me
</b-button>
</div>
Alternative solution:
Add an event listener as to when the mouse leaves/(un)hover the button and hide all tooltips:
<button
v-b-tooltip.hover="'Edit This Bish'"
#mouseleave="$root.emit('bv::hide::tooltip')"
>
The Button
</button>
The con with this is that you'll have to edit this to all existing buttons on other tables. That's why I'm still open to other more easier and general solution than this.
Boostrap-vue Documentation: How to hide all open tooltips
I have a button in React which when clicked scrolls the page to the desired location, which is working.
<div className={styles.classB}>
<Button onClick={ScreenMover.MoveToElem} > Extras </Button>
</div>
But I wanted the same onClick feature without a button, say a link and when clicking it should do the same operation. So I have used the below Link button, but it is not taking the onClick instead it goes to the page top based on the to="" attribute.
<div className={styles.classL}>
<Link className={styles.linkButton} onClick={ScreenMover.MoveToElem} to=""> Extras </Link>
</div>
Another thought, if we can not achieve the above one, then can we have a button look like a link by applying some css style to the button? I should be able to override the inherited button styles and instead it should take the link look and feel. Is it possible and can we have a sample css class for it?
Thanks in advance.
The Link object is important for you?
If not you can use a simple <p> tag and the onClick event will working perfectly.
<p className={styles.linkButton} onClick={ScreenMover.MoveToElem}> Extras </p>
I'm trying to make a link on a webpage to link to another website.
It works in Google chrome but in IE and FF it's not working.
When i hover the link in chrome, it shows in the left bottom cornor the correct link. When i hover it in FF and IE it shows the link of the page that i am currently on.
this is the code i have on my .apsx page
<div id="return">
<button>
<p><a id="ReturnBack" runat="server" href="http://www.stuff.be">Terug naar de site</a></p>
</button>
</div>
i even added some javascript to force it to redirect
$('#return button').click(function () {
alert("oke?");
window.location = 'http://www.stuff.be/Pages/Home.aspx';
});
The alert triggers when u click the link, just to check if it works
And when in IE in the f12 screen i can use window.location = 'http://www.stuff.be/Pages/Home.aspx'; to redirect it. So they both work seperatly but not in combo :s
Is there anybody who can help me?? i just spend 2 days on a silly link :(
This is probably confusing to the browser:
<button>
<p><a id="ReturnBack" runat="server" href="http://www.stuff.be">Terug naar de site</a></p>
</button>
A button which contains a paragraph and a link? I don't think buttons can contain links. (After all, when you click on the link, are you clicking on it or on the button?) This is probably invalid HTML, which means browser behavior is going to be undefined and browser-specific.
Don't use a button, just use a link:
<p><a id="ReturnBack" runat="server" href="http://www.stuff.be">Terug naar de site</a></p>
You can style the link to look like a button if you want. But structurally it can't be inside a button.
Then just change your jQuery selector:
$('#return a')
(Or, conversely, remove the link and keep the button? It's up to you. But it can't be both.)
Side note: This has nothing to do with ASP.NET. What you're using here is HTML and JavaScript.
You can't put a link inside a button.
Remove the button tags and script and it will work like a normal hyperlink in all browsers. You can style it to look like a button if you need that.
Alternatively, remove the <p> and <a> tag from within the button, and keep the click script...
I have a responsive site with bootstrap 3.1.1. I want to show the desktop view when the user click a button "Desktop view".
I have used this question right here as the support but this does not help.
It does not help for 2 reasons:-
The CSS I have added in my Layout file is as shown:
<link rel='stylesheet' media='screen and (max-device-width: 480px)' href='styles/mobile.css' type='text/css' />
I have used hidden-xs, hidden-sm, hidden-md and hidden-lg classes throught out my application.
How can I make the site desktop view and mobile view with the button click?
EDIT
I am simultaneously using both the style sheets at the same time. The style sheet for "mobile.css" and "desktop.css" (for the items which doesnot need to be styled specially for mobiles).
SO swapping both the style sheet would not work.
A way: is to use Jquery to change the meta tag for the viewport when the button is clicked:
$('#buttonId').click(function (){
$('meta[name=viewport]').attr('content', "width=1024");
});
I just thought of something simple. To all you divs that have hidden-xs classes: add a special class (had-hidden-xs), for hidden-lg add had-hidden-lg and so on for every single one of them.
//when the button is clicked, every class is removed
$('#buttonId').click(function (){
//removes all the classes
$('.hidden-xs, .hidden-sm, .hidden-md, .hidden-mg').removeClass('hidden-xs hidden-sm hidden-md hidden-mg');
});
//when the button to go to mobile view is clicked:
$('#backToMobile').click(function (){
//add back your classes using the classes you created in the previous 2 steps
$('.had-hidden-xs').addClass('hidden-xs');
$('.had-hidden-sm').addClass('hidden-sm');
$('.had-hidden-md').addClass('hidden-md');
$('.had-hidden-lg').addClass('hidden-lg');
});
Before Question Edit: Looking at your style sheet, you probably have a style for desktop too since you have a mobile.css. You can easily swap the stylesheets using jquery
$('#buttonId').click(function (){
$('link[href="styles/mobile.css"]').attr('href','desktop.css');
});
$('#buttonId').click(function (){
$('link[href="style/desktop.css"]').attr('href','mobile.css');
});
I have an alert is it´s showed in the navbar. What I would like is achieve an effect where the alert arrive form the left of the navbar, and when I close, instead of fade out just disappear from the right.
I dont know if that´s an effect that bootstrap can provide by the css framework.
Here is my current code
the html:
<div id="msgbox_success" class="alert alert-success alert-position hidden">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<spring:message code='msg.saved'/>
</div>
and here my js
function showMessageBoxSuccess() {
console.log("Displaying msgbox_success");
if ($("#msgbox_success").is(":visible")) {
$("#msgbox_success").hide();
}
$("#msgbox_success").removeClass("hidden");
$("#msgbox_success").show();
$("#msgbox_success").delay(callbackAction.SUCCESS_TIMEOUT).fadeOut();
}
Like I said I would like to have an animation instead use show, to show the alert from the left. And when I click in close another animation instead hide, to hide the alert moving it to the right.
Regards.
I wanted to give this another shot. I setup a JSFiddle example that I think is similar to what you want. It has JS and CSS that will get the job done. In the example, I have a button that triggers the alert to come in from the left. Then, clicking the close button in the alert will send the alert offscreen to the right.
$("#theButton").click(function(){
$("#msgbox_success").removeClass("hidden").attr("aria-hidden", false);
$("#msgbox_success").animate({left: '75%'}, "slow");
});
$(".close").click(function(){
$("#msgbox_success").animate({left: '150%'}, "slow");
var adjustMsgBox = function(){
$("#msgbox_success").addClass("hidden").attr("aria-hidden", true);
};
setTimeout(adjustMsgBox, 2000);
});
There might be a better way to do this, but I think this will point you in the right direction. The messageContainer will be your navbar, so adjust CSS accordingly. Hope this is more of what you are after.
There is a Bootstrap plugin that you could maybe take advantage of called Bootstrap Notify (formerly Bootstrap Growl). Another idea is Bootbox.js, but that is more modal driven. Hope this helps.