2

Objective: I have a long text stored in a variable that I need to display as a text in a button. Since it is a long text, I wish to wrap it.
Example:
say the variable is $scope.buttonText, containg a long text(say 100 characters).
The button code (angular material is used) in the view is:

<md-button ng-click="someFunc()" style="width:300px;">
{{buttonText}}
</md-button>

The Expected Output is that the text in the button should wrap after 300px.
But the actual output of the above code is that the text is not wrapping after 300px. It just goes on and breaks the button. The spilled out text gets hidden.
Now, I have tried using the some CSS properties on it like white-space: normal; but it does not seem t work on the text at all.
I assume this is because the text is actually as a $scope variable.
Can someone help me in wrapping up the text in the button, which has a fixed width of 300px? Height is no issue.
A PLUNKR to regenerate the problem. please someone suggest changes.

1 Answer 1

1

.appText {
    width: 280px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
      display: inline-block;
}
<button style="width:300px;">
<span class="appText">sssssssssssssssssssxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxsssssssssssssssss</span>
</button>

Sign up to request clarification or add additional context in comments.

7 Comments

This CSS is not working... The text is still not wrapping :(
please add display: inline-block; to appText class
still not working... i have made a plunkr... plz edit it : plunkr
@jAYANT YADAV you need to add the 'appText' css class to html. replace button tag with this <button> <span class="appText">{{buttonText}} </span> </button>
sorry. I thought i had included it... But the text is still not wrapping... I have removed the overflow: hidden; and text-overflow: ellipsis; since i want to see the whole text in button
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.