Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent Word Breaks for link - CSS

Tags:

html

css

I have some links that I would like to prevent from being broken up when a wrap is needed. I would rather the whole entire link be moved to another line rather than half of the link.

Here is an example

Is there any way to make a class only break 'full' if a word-break is needed? (meaning that if the content of that class will exceed the lines, instead of breaking it, just create a new line with it).

I hope this makes sense; thank you for your time.

HTML

<div class="box">
    Here is some text within this grey box; <a href="#">And here is the link</a>.
</div>

CSS

.box {
    background: grey;
    color: white;
    line-height: 24px;
    padding: 15px;
    width: 290px;
}
.box a {
    background: aqua;
    color: black;
    padding: 5px;
}
like image 267
justinw Avatar asked Feb 13 '23 01:02

justinw


1 Answers

You are looking for white-space: nowrap.

Updated Example

.box a {
    white-space: nowrap;
    background: aqua;
    color: black;
    padding: 5px;
}
like image 126
Josh Crozier Avatar answered Feb 15 '23 14:02

Josh Crozier