Pressing the border will not trigger any events

I'm facing an issue with using animation in CSS and event handlers in JS. Specifically, I have two styles for my button (normal and with the :active suffix) to simulate clicking the button. However, when I use the ng-click directive on the button in Angular HTML, the event only triggers when I click the body of the button, not the border where the pointer is set in the CSS.

I am seeking the best solution or practice to resolve this problem. Should I remove the CSS style with the active suffix or adjust something in my styles?

CSS

#addButton {
    padding: 5px;
    float: left;
    background: linear-gradient(#92AFDE, #668FED);
    border: solid 2px #14438F;
    margin-left: 10px;
    border-radius: 10px;
    font-size: 20px;
    cursor: pointer;
}
#addButton:ACTIVE {
    transform: translateY(4px);
}

HTML

<div class="card">
    <img ng-click="selectCard()" style="width: 150px; height: 200px;"   ng-src="cards/\{{cardId}}.png"></img>
    <button  ng-click="addCard()" id="addButton">Add<div class="count">0</div></button>
    <div id="delButton">X</div>
</div>

Answer №1

When a border is specified, it will be added to the actual width of the element.

Implement this code snippet:

#addButton{
  box-sizing:border-box
}

By using this CSS property, the border space will be included in the actual width.

Answer №2

Encountered a similar issue while working on a project. I attempted the solution provided in this Stack Overflow answer, but unfortunately, it did not resolve the problem. The click event was not triggered when clicking on the border. Adding box-sizing: border-box as suggested in the answer proved to be crucial for making the workaround mentioned below effective.

The explanation given in the comment appears to be accurate:

OK i know where is the problem. If i click on the button the "activate" suffix moves the button down and browser don't notice click on this button because pointer is outside my div (after moving)

To address this issue, I implemented a workaround by placing a div outside the button with CSS padding-top set to a value equal to or greater than the height of translateY. The onClick event was added to the div instead of the button. While this solution may not be the most elegant, it does get the job done.

Here is a snippet of the code for reference:

.sw-form-button-card {
    padding: 5px 10px;
    text-decoration: none;
    background: #668ad8;
    color: #FFF;
    border: none;
    box-sizing:border-box;
    border-bottom: solid 3px #627295;
    border-radius: 3px;
    cursor: pointer;
}
.sw-form-button-card:active {
    -ms-transform: translateY(2px);
    -webkit-transform: translateY(2px);
    transform: translateY(2px);
    border-bottom: none;
}

HTML section:

<div data-bind="click: () => openDDDialog()" style="padding-top: 5px;">
    <button class="sw-form-button-card">
        <span style="font-size: 15px;" data-bind="text: 'Button text'"></span></div>
    </button>
</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Troubleshooting issues with mail subscriptions using Ajax and PHP

My Idea for Implementation I successfully set up a subscription form using PHP initially. However, I wanted to enhance the user experience by implementing an Ajax feature that would display a nice image and a "thank you" message without reloading the pag ...

When it comes to E2E testing with an Angular, Python, and MongoDB web stack, which tool is more effective: Selenium or Protractor?

Just discovered the protractor framework, which offers end-to-end testing for Angular applications. I'm curious to know which test framework is more suitable for the webstack I am using - Angular, Python, and MongoDB. Should I go with Selenium or Pro ...

Half-height rows and columns in Bootstrap 4

Can someone help me create blocks similar to the one shown in the image? The left block should be col-5, while the right block should be col-7. The right block needs to have two rows with a height that is 50% of the left block. Is there a way to achieve ...

Understanding the order of execution in AngularJS when using `$q` for chaining promises

Here's a successful approach: $q.when() .then(checkCookieToken) // check if cookie already exists e.g. in cookie .then(setHeader) // set Header with REST-Token e.g from cookie .then(checkTokenOnline) ...

What mechanism does Angular use to determine the location of the ng-include file?

I recently came across this Angular App example. Within the main html document named [index.html][2], I noticed the following line: <div ng-include="'header.tpl.html'"></div> Curiously, there is no file named header.tpl.html in the ...

What is the best way to fetch information from an external json api using angularJS?

As an example, I am interested in accessing data from two different URLs: 1- http://jsonplaceholder.typicode.com/posts/ 2- http://jsonplaceholder.typicode.com/todos/ Is it possible to fetch data from these two URLs in a single application using two contro ...

The width of the Ion-slide is dynamically determined by the styling

After transitioning my Ionic 2 project to Ionic 3, I encountered issues with ion-slides which are affecting my app's functionality. Upon app loading, specific widths are being defined in the style tags on the slides, disrupting the intended styling. ...

The Angular scope fails to reflect changes on the view

In this angular ng-click event, I have the following code: eventApp.controller('DetailEventController', ['$scope', '$http', '$compile', '$timeout', function ($scope, $http, $compile, $timeout, uiCalendarCon ...

Tips for arranging information in ng-repeat using nested objects within JSON data on AngularJS

Looking to display an array of object properties in an Angular view. Here is the object: $scope._Json = { "foo": { "ItemDimension1": { "Item": "item1", "ItemIndex": 1, "SelectedItems": [{ "C ...

Sketch the borders of the element (animated)

Seeking a way to create a button with an animated border that looks like it is being drawn. Current progress involves some code, but it's not working smoothly with border-radius set. (keep an eye on the corners) https://codepen.io/anon/pen/MbWagQ & ...

What are some examples that illustrate the differences between ng-if, ng-show, and ng-hide

While exploring ng-if, ng-show, and ng-hide, I realized that they all seem to serve a similar purpose. Why are there three directives when one might suffice? ...

Learn the process of zipping a folder in a Node.js application and initiating the download of the zip file afterwards

After encountering issues with the latest version of the npm package adm-zip 0.4.7, I reverted to an older version, adm-zip 0.4.4. However, despite working on Windows, this version does not function correctly on Mac and Linux operating systems. Additionall ...

Horizontal navigation bar encroaching on slideshow graphics

I'm encountering difficulties aligning the horizontal menu below the image slider. When I have just an image without the slider, the menu aligns properly (vertically), but as soon as I introduce the code for the slider, the menu moves to the top and d ...

Is it possible to retain the placeholder text if the user selects the input field and the value is left empty?

Is there a way to make the placeholder text disappear only when the user starts typing at least one character in the input field? Currently, the placeholder disappears as soon as the user focuses on the input. Any suggestions would be appreciated. Thank ...

Bone structure template - optimizing list spacing with CSS

Currently, I am attempting to float my navigation bar further towards the left by at least 200px, closer to the end of the line visible below. However, every time I add a margin or padding, it causes the elements within the navigation bar to stack on top o ...

Utilizing HTML/CSS to display text and an image positioned above a sleek navigation bar

I am struggling to align a logo on the left side of my website, with text on the right next to it, all placed above the navigation bar. Despite my efforts, I just can't seem to get them positioned correctly! CSS .headerLogo{ float:left; marg ...

What could be causing my React button to stop functioning as a link to an external website when using anchor tags?

I recently created some buttons for my website using React. Initially, everything was working perfectly with the buttons, but suddenly they stopped functioning. Strangely, I didn't make any alterations to the code and I'm puzzled as to why they a ...

Toggle switch unable to reset upon reloading the page

Issue with Toggle Switch Not Resetting on Page Reload I am encountering a problem with a toggle switch I implemented from the W3schools example (link here). Unlike in the W3schools editor where it resets its state upon reload, my toggle switch remains in ...

When Node.js meets Angular, it results in the error message: "Uncaught ReferenceError: require is

Working on setting up an Express.js API hosted on a Node.js server. The purpose of the API is to retrieve data stored on the server and keep track of API access in a database. Currently, I'm looking to develop an admin section that will utilize Angul ...

Discrepancy discovered in Bootstrap 5 container dimensions compared to provided documentation

I am currently delving into Bootstrap 5 (I have some experience with coding but not much with web technologies). To better understand how Bootstrap works, I've been creating HTML documents to experiment with its behavior. While working on the "conta ...