Responsive text and image

1

I'm a beginner working with responsive methods and I'm having problems with a detail, I need to change the text of a btn to an image when my application is accessed by mobile.

Could anyone help me with this?

<button class="btn btn-lg btn-info btn-block text-uppercase" id="prosseguir" type="submit">Prosseguir</button>

I would like that when resizing the screen, btn would replace "Proceed" with an icon.

Thank you.

    
asked by anonymous 13.11.2018 / 12:17

2 answers

3

As a complement to Hugo's response, Bootstrap already has tools to change the display property by varying it according to the width of the viewport (through media queries ). They are the d-* ( documentation classes).

OBS : When referring to xs , this is screen size (

Already in the image you would use:

<img class="d-inline-block d-sm-none" src="...">

xs causes d-inline-block to be img , and display: inline-block causes it to be d-sm-none for display: none or larger screens, ie it will only be visible on% / p>

In this way the visibility of sm and xs are mutually exclusive.

Example:

html, body {
  padding-top: 40px;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">

<main class="container">
  <div class="row">
  
    <button class="btn btn-lg btn-info btn-block text-uppercase">
      <span class="d-none d-sm-block">Prosseguir</span>
      
      <img class="d-inline-block d-sm-none" src="https://getbootstrap.com.br/docs/4.1/assets/brand/bootstrap-solid.svg"style="max-width: 50px;">
      
    </button>
    
  </div>
</main>

You can leave the snippet in full screen (full page link) and change the width of your browser window to see responsiveness working     

13.11.2018 / 13:01
3

There are several ways to do it and one of them is putting span inside button as I did in this example. then with the @media rule you hide and show this span , at the same time that you remove the text from bottun by putting font-size:0 for example.

Then if the screen has a maximum width of% width, the image appears, if it is more than 610px the text of 610px appears. You can adjust this in the rule button if you want

Atfirstyoumaythinkitisnotafullysemanticform,buttheupsideisthatevenwith@mediathetextmaystillbevisibletoscreenreaders,butitdoesnotappeartotheregularuser.

Seethecodefortheimageabove:

.icon {
    height: 16px;
    width: 16px;
    background-image: url(https://placecage.com/16/16);
    vertical-align: middle;
    display: none;
}
@media screen and (max-width:610px) {
    .icon {
        display: inline-block;
    }
    button {
        font-size: 0;
    }
}
<button class="btn btn-lg btn-info btn-block text-uppercase" id="prosseguir" type="submit">
    Prosseguir
    <span class="icon"></span>
</button>
    
13.11.2018 / 12:36