164

I am using dreamweaver to create a website and I thought of just using Photoshop to create backgrounds. I decided to do so only because in case I'd choose to change the button name easily by just editing the codes, I could just refer to the code. If I would construct buttons using Photoshop, I wouldn't be able to edit the Texts in those buttons or in any element easily.

So my question is simple, How do I create a button that has a simple inline style making it transparent leaving the value of the button still visible.

.button {     
    background-color: Transparent;
    background-repeat:no-repeat;
    border: none;
    cursor:pointer;
    overflow: hidden;        
}

It still leaves a border shade after your click it.

1

6 Answers 6

315

To get rid of the outline when clicking, add outline:none

JSFiddle example

button {
    background-color: transparent;
    background-repeat: no-repeat;
    border: none;
    cursor: pointer;
    overflow: hidden;
    outline: none;
}

button {
    background-color: transparent;
    background-repeat: no-repeat;
    border: none;
    cursor: pointer;
    overflow: hidden;
    outline: none;
}
<button>button</button>

5
  • This is actually good enough. I've already tried the image way and it did as exactly needed. Thank you so much, Mr. Hayes!
    – Shinji
    Commented Mar 26, 2014 at 20:47
  • 1
    It works 100% after include -webkit-box-shadow: none; -moz-box-shadow: none; in the code
    – h3nr1ke
    Commented May 18, 2016 at 17:24
  • 6
    You can optimize it changing background-color: Transparent; background-repeat:no-repeat; to background: Transparent no-repeat; Commented Jul 24, 2017 at 4:47
  • 1
    missing outline: none; gets me every time
    – Adam
    Commented May 21, 2018 at 17:55
  • For me, I had to apply the property "cursor: pointer" to button:hover. With solely button it did not work.
    – Spixmaster
    Commented Aug 14, 2020 at 9:58
9

The solution is pretty easy actually:

<button style="border:1px solid black; background-color: transparent;">Test</button>

This is doing an inline style. You're defining the border to be 1px, solid line, and black in color. The background color is then set to transparent.


UPDATE

Seems like your ACTUAL question is how do you prevent the border after clicking on it. That can be resolved with a CSS pseudo selector: :active.

button {
    border: none;
    background-color: transparent;
    outline: none;
}
button:focus {
    border: none;
}

JSFiddle Demo

3
  • Still leaves a border shade after you have clicked it. Thank you for your input!
    – Shinji
    Commented Mar 26, 2014 at 20:35
  • So, your actual question is very different from the original one that I responded to. You already know how to use CSS to make the button transparent. After it has been clicked on, it's leaving a border you don't want. Is that accurate?
    – EnigmaRM
    Commented Mar 26, 2014 at 20:38
  • Yes, I am terribly sorry if my question was misleading.
    – Shinji
    Commented Mar 26, 2014 at 20:41
2

Make a div and use your image ( png with transparent background ) as the background of the div, then you can apply any text within that div to hover over the button. Something like this:

<div class="button" onclick="yourbuttonclickfunction();" >
Your Button Label Here
</div>

CSS:

.button {
height:20px;
width:40px;
background: url("yourimage.png");
}
1
  • If you want to keep your html semantic and accessible, it's best to use the button tag and remove background, etc.. using css. However, this is fine, especially in a situation where accessibility is not an issue like a native app that uses html5 and CSS for layout, here is an example: smashingmagazine.com/2013/10/17/… Commented Jul 4, 2015 at 4:02
0
<div class="button_style">
This is your button value
</div>

.button_style{   
background-color: Transparent;
border: none;             /* Your can add different style/properties of button Here*/
cursor:pointer;    
}
0
0

Setting its background image to none also works:

button {
    background-image: none;
}
0

**add the icon top button like this **

#copy_btn{
	align-items: center;
	position: absolute;
	width: 30px;
  height: 30px;
     background-color: Transparent;
    background-repeat:no-repeat;
    border: none;
    cursor:pointer;
    overflow: hidden;
    outline:none;
}
.icon_copy{
	position: absolute;
	padding: 0px;
	top:0;
	left: 0;
width: 25px;
  height: 35px;
  
}
<button id="copy_btn">

                        <img class="icon_copy" src="./assest/copy.svg" alt="Copy Text">
</button>

Not the answer you're looking for? Browse other questions tagged or ask your own question.