Search code examples
htmlcss

align text and images inside the button image


to css . I have a button image inside the button image the txt should be in left side and another image should be in right side. the one i did is its all in the center. can some help me? thank you..

This is the code:

button {
  /* padding-top: 100px; */
  width: 100%;
  border: none;
  background-position: center;
  background-repeat: no-repeat;
  background-image: url("https://www.searchpng.com/wp-content/uploads/2019/01/Game-Button-PNG-copy.jpg");
  height: 100%;
}
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <meta http-equiv="X-UA-Compatible" content="ie=edge" />
  <title>Static Template</title>
</head>

<body>
  <button type="button">
          <span>test</span>
          <img
            src="https://cdn.iconscout.com/icon/free/png-256/metamask-2728406-2261817.png" width="60"
          />
        </button>
</body>

</html>


Solution

  • <!DOCTYPE html>
    <html lang="en">
      <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <meta http-equiv="X-UA-Compatible" content="ie=edge" />
        <title>Static Template</title>
        <style>
          button {
            /* padding-top: 100px; */
            width: 100%;
            border: none;
            background-position: center;
            background-repeat: no-repeat;
            background-image: url("https://www.searchpng.com/wp-content/uploads/2019/01/Game-Button-PNG-copy.jpg");
            height: 100%;
            max-width: 1400px;
        margin: 0 auto;
        position: relative;
          }
         button span {
        text-align: left;
        position: absolute;
        left: 20%;
        color: white;
        top: 29px;
    }
    button img{position: relative;
        right: -28%;}
        </style>
      </head>
      <body>
            <button type="button">
              <span>test</span>
              <img
                src="https://cdn.iconscout.com/icon/free/png-256/metamask-2728406-2261817.png"
                width="60"
              />
            </button>
        
      </body>
    </html>