Search Unity

How can I pad an image button?

Discussion in 'UI Toolkit' started by ChristianTellefsen, Oct 7, 2021.

  1. ChristianTellefsen

    ChristianTellefsen

    Joined:
    Aug 24, 2021
    Posts:
    2
    Hi!

    I wish to have a refresh button with padding around the image.

    Code (csharp):
    1. <ui:Button name="RefreshButton"/>
    I added the following css

    Code (csharp):
    1. #RefreshButton {
    2.     height: 16px;
    3.     width: 16px;
    4.     background-image: resource('d_Refresh');
    5.     align-self: flex-end;
    6. }
    7.  
    Which looks fine, except that there is no padding around the image.

    upload_2021-10-7_10-4-58.png

    But no matter what I try, I have not managed to add padding around the image without stretching it. This is what it ends up looking like if I add padding, or increase the height, width:

    upload_2021-10-7_10-5-46.png

    Anyone know how to make it look like this (from the Package Manager)?

    upload_2021-10-7_10-8-30.png
     
  2. Nexer8

    Nexer8

    Joined:
    Dec 10, 2017
    Posts:
    271
    Use the Image element. It has an image inside another VisualElement, which allows for padding.
     
    jonathanma_unity likes this.
  3. ChristianTellefsen

    ChristianTellefsen

    Joined:
    Aug 24, 2021
    Posts:
    2
    Thanks!
     
    Nexer8 likes this.