1

BEFORE AFTER! the light gray is the button. I have this css for my html button:

.link-container button {
    background-color: #444;
    color: white;
    border: none;
    padding: 10px;
    border-radius: 5px;
    cursor: pointer;
    width: 100%;
    background-image: url(imgs/openbutton.png);
}

this is the html code for the button: <button onclick="window.location.href='https://example.com/link2';"></button>

the main problem is, its too big.

I have searched online for solutions, havent found anything, and I was kind expecting for it to shrink and fit...

2
  • 1
    Set the size using background-size? Commented Jun 30 at 12:55
  • @Cyclonecode Yes, I tried using Utsav katharotiya answer. Didnt work. Commented Jun 30 at 13:06

1 Answer 1

1

Try, below CSS code ...

.link-container button {
    background-color: #444;
    color: white;
    border: none;
    padding: 10px;
    border-radius: 5px;
    cursor: pointer;
    width: 100%;
    background-image: url('imgs/openbutton.png');
    background-size: contain; /* Makes the image fit within the button */
    background-repeat: no-repeat; /* Prevents the image from repeating */
    background-position: center; /* Centers the image within the button */
}
4
  • I cant tell if its working or not... It looks the same. Commented Jun 30 at 13:01
  • please! add the pictures of outputs for better understanding Commented Jun 30 at 13:10
  • nvm its works! thanks! Commented Jun 30 at 13:10
  • here is the solution in play! sorry it took so long, my compuetrs VERy slow Commented Jun 30 at 13:38

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