12

I found a strange behavior, I cannot select a text in a <button> element. As an example, please try to select a text in these buttons of Bootstrap: http://getbootstrap.com/components/#list-group-buttons

enter image description here

Is it some standard behavior or is it editable? I need to select text in buttons.

Green
  • 28,742
  • 61
  • 158
  • 247

3 Answers3

14

You could do the reverse of this question: create the following CSS3:

.list-group-item{
-webkit-touch-callout: text;
-webkit-user-select: text;
-khtml-user-select: text;
-moz-user-select: text;
-ms-user-select: text;
user-select: text;
}

and link the stylesheet. It works on my firefox.

Edit: changed "all" to "text" as Nenad Vracar said. It works in Chrome and Firefox for me now

Community
  • 1
  • 1
Appelemac
  • 192
  • 6
  • 1
    No, doesn't work in Chrome, `47.0.2526.106 m`. Yes, it looks like it is a browser behavior. – Green Dec 28 '15 at 14:02
  • Old comment, but just to confirm, tested and it do work in Mac Chrome 69 and Mac Firefox 6 at least. But it does not work in Safari 12. It do work with `user-select: all` though. But then the user can't choose to only select a single word, everything in that container is selected. – Jonas Sandstedt Oct 17 '18 at 14:01
7

You can set user-select: text

button {
  -webkit-user-select: text;  /* Chrome all / Safari all */
  -moz-user-select: text;     /* Firefox all */
  -ms-user-select: text;      /* IE 10+ */
  user-select: text;
}
<div class="col-sm-4">
  <div class="list-group">
  <button type="button" class="list-group-item">Cras justo odio</button>
  <button type="button" class="list-group-item">Dapibus ac facilisis in</button>
  <button type="button" class="list-group-item">Morbi leo risus</button>
  <button type="button" class="list-group-item">Porta ac consectetur ac</button>
  <button type="button" class="list-group-item">Vestibulum at eros</button>
</div>
</div>

Fiddle

Nenad Vracar
  • 118,580
  • 15
  • 151
  • 176
  • I would suggest this prefix-stack: `-webkit-user-select: all; -moz-user-select: text; -ms-user-select: text; user-select: text;` This because Safari doesn't support `user-select: text` on Buttons for some reason. – Jonas Sandstedt Oct 17 '18 at 14:09
-2

You can define css property for button like this For button class add cursor:pointer property. You can specify either to button directly or to your custom CSS class

cursor : pointer

Krishna S
  • 27
  • 3