Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i want to create a button like a tab in chrome with cross top-right most to close it

What I have tried:

<button> Master Data </button>
Posted
Comments
Afzaal Ahmad Zeeshan 11-Feb-16 15:28pm    
That is not a button.

You can use, CSS properties to make the "x" float to the right side of the container.
Sergey Alexandrovich Kryukov 11-Feb-16 21:15pm    
Well... if "<button>" is not a button, what is it?.. :-)
Your idea is correct, but the beginner needs some explanation... this is "absolute" positioning (which is actually floating, overlapping some element, positioned relative to that element).
—SA
Sergey Alexandrovich Kryukov 11-Feb-16 22:25pm    
Anyway, I just created a proof-of-concept code sample; please see Solution 1.
Your advice in your comment is credited, of course.
—SA

1 solution

Afzaal gave you a good idea, but it may need explanation. Here is a proof of concept for you:
HTML
<html>>
  <head>
    <title>Styled button demo</title>
    <style>
      button {
        position: relative; height: 4em;
        padding-left: 2em; padding-right: 2em; }
      span.close { position: absolute; top:0; right: 0; }
    </style>
  </head>
<body>

<button>Normal button text<span class="close">x</span></button>

</body>
</html>

The element button is just for example; in your code, it will be whatever you use for the tab, probably a div with special CSS class. The element span and the letter "x" is also just for example. Of course, instead of it you need to devise some graphical element. Make sure you remove all unwanted margins and padding, to position this element precisely. On this element, you should also add the onclick handler.

That's all. Any questions?

—SA
 
Share this answer
 
v5
Comments
Afzaal Ahmad Zeeshan 12-Feb-16 13:20pm    
5ed; After all that was a very simple concept. :-) Thank you for bringing my idea to a full answer.
Sergey Alexandrovich Kryukov 12-Feb-16 17:29pm    
Sure. Teamwork! Thank you, Afzaal.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900