<Button> Background Image

How to add background image for input type=button?

You need to type it without the word image.

background: url('/image/btn.png') no-repeat;

Tested both ways and this one works.

Example:

<html>
<head>
<style type="text/css">
.button{
background: url(/image/btn.png) no-repeat;
cursor:pointer;
border: none;
}
</style>
</head>
<body>
<input type="button" name="button" value="Search" onclick="showUser()" class="button"/>
<input type="image" name="button" value="Search" onclick="showUser()" class="button"/>
<input type="submit" name="button" value="Search" onclick="showUser()" class="button"/>
</body>
</html>

button background image

Astonishing that no answer addresses or mentions the actual problem here.

The CSS selector button #rock says "give me an element with the id rock inside a <button> element", like this:

<button>
<span id="rock">This element is going to be affected.</span>
</button>

But what you wanted is a <button> element with the id rock. And the selector for that would be button#rock (note the missing space between button and #rock).

And as @Greg already mentioned: #rock is already specific enough to target the button and could be used on its own.

Can't get a buttons background image to display

Issue was that images, unless explicity imported as:

import D20 from './Images/D20.png';

and then used as:

  background: url(${D20});

...will be minified and have their URL changed thanks to webpack.

Found answer here:

https://stackoverflow.com/a/56404570/2796017

how to set a background image of a button to nothing

You want the whole image to be nil rather than passing nil to the UIImage initializer. Try this:

BTN.setImage(nil, for: .selected)

is there anyway to change background image (not color) of button from xml in android studio 4.2.2?

Try this code

 <androidx.appcompat.widget.AppCompatButton
android:id="@+id/btn_ok"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="@drawable/btn_background"
android:text="@string/ok"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/btn_cancel"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintWidth_percent="0.3"/>


Related Topics



Leave a reply



Submit