Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide button text in phone mode - Bootstrap

I am making an application in which I would like to hide the button text in order to save valuable space in the "phone mode". All the buttons have icons, so that should be enough.

I would like to have a pure css solution, but I can not come up with anything.

This is what a button looks like:

<button type="submit" name="btnSave" id="btnSave" class="btn btn-primary"><i class="icon-save"></i> Save</button>

I would like to add that it could also be an:

<a class="btn btn-warning"><i class="icon-trash"></i> Delete</a>

So basicly, if the responsive's mode is phone, all the text inside the .btn selector should be hidden. But the icon needs to remain.

I've tried text-ident, but that also hides the icon.

like image 702
JohnHeroHD Avatar asked Apr 04 '13 19:04

JohnHeroHD


People also ask

How do I hide a text button?

We can use media queries in CSS to hide button text according to the screen size of the device.

How do I make a button only visible on mobile view?

You need to specify display:none; for it to be trully hidden. In you example you can change the display property of the button to block inside the responsive file and display:none for the text. In the main css file you need to do exactly the opposite.

Can you hide a button with CSS?

You can hide an element in CSS using the CSS properties display: none or visibility: hidden . display: none removes the entire element from the page and mat affect the layout of the page. visibility: hidden hides the element while keeping the space the same.


2 Answers

For Bootstrap 4 you can use display property. As such, the classes are named using the format:

.d-{value} for xs
.d-{breakpoint}-{value} for sm, md, lg, and xl.

So your code should look like this:

<button type="submit" name="btnSave" id="btnSave" class="btn btn-primary">
    <i class="icon-save"></i> <span class="d-none d-sm-inline">Save</span>
</button>

The text will disappear for extra small(xs) screens:

enter image description here

like image 60
Krzysztof Raciniewski Avatar answered Sep 28 '22 10:09

Krzysztof Raciniewski


In bootstrap 3 the hidden-phone class was changed to hidden-xs. Matter of fact, hidden- can now be used with other device size prefixes such as lg, sm etc...

like image 41
adrien Avatar answered Sep 28 '22 10:09

adrien