I have created a URL preview box for the entered URL.
Preview is shown in the div box. I want to add a close option on the right top. How could be done so that when users click on its box should be disabled?
Here is my fiddle.
<a class="fragment" href="google.com"> <div> <img src ="http://placehold.it/116x116" alt="some description"/> <h3>the title will go here</h3> <h4> www.myurlwill.com </h4> <p class="text"> this is a short description yada yada peanuts etc this is a short description yada yada peanuts etc this is a short description yada yada peanuts etc this is a short description yada yada peanuts etcthis is a short description yada yada peanuts etc </p> </div> </a>
code is inside php
In the function, we select the close button with document. getElementById('close') . And we set the onclick property to a function that removes the the parent of the close button, which is the div. We get the parent of the close button with this.
A close button is a <button> element with the class . close-button . We use the multiplication symbol ( × ) as the X icon. This icon is wrapped in a <span> with the attribute aria-hidden="true" , so screen readers don't read the X icon.
The task is to make the close button using Pure CSS. There are two approaches that are discussed below. Approach 1: Create a <div> inside another <div> which has alphabet 'X' in it which helps in displaying the close button. When the “click” event occurs on 'X', then perform the operation.
Use the following steps to center align a button in a div container: Create a div container. Insert the button tag. In the CSS for the div set the text-align to center.
Most simple way (assumed you want to remove the element)
<span id='close' onclick='this.parentNode.parentNode.parentNode.removeChild(this.parentNode.parentNode); return false;'>x</span>
Add this inside your div
, an example here.
You may also use something like this
window.onload = function(){ document.getElementById('close').onclick = function(){ this.parentNode.parentNode.parentNode .removeChild(this.parentNode.parentNode); return false; }; };
An Example Here.
Css for close button
#close { float:right; display:inline-block; padding:2px 5px; background:#ccc; }
You may add a hover effect like
#close:hover { float:right; display:inline-block; padding:2px 5px; background:#ccc; color:#fff; }
Something like this one.
it's easy with the id of the div container : (I didn't put the close button inside the <a>
because that's does work properly on all browser.
<div id="myDiv"> <button class="close" onclick="document.getElementById('myDiv').style.display='none'" >Close</button> <a class="fragment" href="http://google.com"> <div> <img src ="http://placehold.it/116x116" alt="some description"/> <h3>the title will go here</h3> <h4> www.myurlwill.com </h4> <p class="text"> this is a short description yada yada peanuts etc this is a short description yada yada peanuts etc this is a short description yada yada peanuts etc this is a short description yada yada peanuts etcthis is a short description yada yada peanuts etc </p> </div> </a> </div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With