Search code examples
cssspaceline-breaks

How to force line-break only on a space in a title and prevent hypenation with CSS?


I would like in CSS force break-line on space and not break words like "Plan[break-line]individual"

enter image description here

I'm using Flexbox to make an easy responsive code.

HTML

<section class="card-container">
    <div class="card card-inline text-center">
        <div class="card-block">
            <h4 class="card-title">Plan individual</h4>
                <p class="card-text">€10.00 / year</p>
                <button click="#'">Sign in</button>
        </div>
    </div> 
    ...                   
</section>  

style.css

.card-container{
    display: flex;
    height: inherit;
    width: inherit;
}

.card{
    position: relative;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background-color: #fff;
    background-clip: border-box;
    border: 1px solid rgba(0,0,0,.125);
    border-radius: .25rem;
    width: 170px;
}

.card-inline{
    display: inline-flex;
    margin: .75rem;
}

.card-block {
    flex: 1 1 auto;
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

h4.card-title{
    margin: .5rem !important;
    font-size: 100% !important;
}

.text-center{
    text-align: center !important;
}

I tried white-space, word-wrap, flex-wrap... without success. Does anyone have an idea how to prevent the words from being hyphenated?


Solution

  • The code you included doesn't give the result you show in your image, so you must have a CSS rule somewhere else that's causing it.

    However, you should be able to override it with the following:

    h4 {
        hyphens: none;
    }