Make text “more” selectable

前端 未结 6 1957
心在旅途
心在旅途 2021-02-01 17:48

I have text in a

tag:

Hello world... and goodbye mind A B!

How do I increase the area in which the te

6条回答
  •  天涯浪人
    2021-02-01 18:20

    I'm assuming the scenario where you have a body of text, and inside that body of text is a fairly important or relevant piece of information to an end user and you would like them to be able to easily highlight and copy the information.

    This would be considered as a last option if no other solution was found,

    BLAH BLAH BLAH This is the information you would like users to be able to highlight BLAH BLAH BLAH BLAH ETC ETC ETC

    If you wrap the text around it in separate paragraph tags and give them a class then set the following in CSS:

    .surroundingText {
    
      -webkit-user-select: none;  /* Chrome all / Safari all */
      -moz-user-select: none;     /* Firefox all */
      -ms-user-select: none;      /* IE 10+ */
      user-select: none;         
    }
    
    .importantText {
    
            -webkit-user-select: all;  /* Chrome all / Safari all */
          -moz-user-select: all;     /* Firefox all */
          -ms-user-select: all;      /* IE 10+ */
          user-select: all;
        }
    

    So the end result is only the text between the span tag is able to be selected.

提交回复
热议问题