The tag label does not let break line easily within it

Asked

Viewed 70 times

-2

I need to help figure out how to "break line" dentro tag.
For example: I have a 200px label and every name that is inside the label tag larger than 200px, should break line and move to the line below, thus pushing the other Abels down.
See how I’m trying to do, but it’s not working:

Veja no trecho de código

The text should appear until more or less the word free and move to the line below, but is not "breaking".
I’m not using any other code besides the style I’m demonstrating on the tag label itself.


<fieldset style='position:relative;width:100%;max-width:600px;min-width:305px;text-align:left;border:1px solid rgba(121,138,151,0.5);border-radius:3px;padding:0 5px 10px 5px;'>
<legend>Programa social</legend>

<legend style='position:absolute;top:-1px;right:5px;background:#fff;'>
<div onclick='modalSocial();'>Incluir Programa</div>
</legend>

<div style='position:relative;margin:0 0 20px 5px;'>Clique com o botão direito do mouse sobre um Programa Social para ler a descrição</div>

<div style='position:relative;margin:5px 0;'>

<input type='checkbox' id='chpsa' name='psoc[]' value='xxxxx'>
<label for='chpsa' style='position:absolute;left:0;'></label>
<label for='chpsa' style='position:relative;width:200px;word-break:break-word;overflow:hidden;'>
Lorem ipsum ante mi vel sagittis libero aliquam quisque praesent aliquet suspendisse etiam praesent, senectus aenean sapien mi dapibus sit aptent eu consequat pellentesque est.
</label>
<br>
<input type='checkbox' id='chpsb' name='psoc[]' value='xxxxx'>
<label for='chpsb' style='position:absolute;left:0;'></label>
<label for='chpsb' style='position:relative;width:200px;word-break:break-word;overflow:hidden;'>
Lorem ipsum ante mi vel sagittis libero aliquam quisque praesent aliquet suspendisse etiam praesent, senectus aenean sapien mi dapibus sit aptent eu consequat pellentesque est.
</label>
<br>
<input type='checkbox' id='chpsc' name='psoc[]' value='xxxxx'>
<label for='chpsc' style='position:absolute;left:0;'></label>
<label for='chpsc' style='position:relative;width:200px;word-break:break-word;overflow:hidden;'>
Lorem ipsum ante mi vel sagittis libero aliquam quisque praesent aliquet suspendisse etiam praesent, senectus aenean sapien mi dapibus sit aptent eu consequat pellentesque est.
</label>

</div>
</fieldset>

inserir a descrição da imagem aqui

Sam
inserir a descrição da imagem aqui

Felipe inserir a descrição da imagem aqui

  • As I said in my question (in bold): I’m not using! and the snippet really changes even!

  • OK thanks @Sam... I put it the way it is and removed the print.... "suck on this sleeve" rs

  • I tried it like this (display:inline-block), but I didn’t give @Sam... and if I don’t put the overflow:Hidden, the label breaks the fieldset line.

  • 'Cause it’s @Sam... I’ll post the image of the project for you to see what happens... Note that the Programa de Fomento is cut and does not break line..... and if I remove the overflow, it completes everything in one line only

  • Yes @Sam! Two columns because the DIV that holds the checkboxes will repeat itself according to the query of mysql and is with style display:inline-block... are many social programs, many even, so the need for the column... see the second image with the same code that I used here in the snippet. The label (with display:inline-block) does not break line at all.

  • My little boss, unable to reproduce the code and not knowing what you want to do (so far I do not understand), it is difficult to help.

  • I’ll keep searching... thanks @Sam, you’re very kind!

  • Blz... just don’t use overflow that has nothing to do with line breaking. Good luck!

Show 3 more comments

2 answers

0


Friends @Sam and @Felipe Maia, thank you so much for the tips you gave me to resolve my problem... everything you said makes sense and is correct. May God bless you for this!

I decided by adding a style directly on the Abels that are within my fieldset:
.pro-social-label label { white-space:normal;word-break:break-word; }
No other project label was defaced and only the social programs Abels were changed... Look at the image (I’m still reworking. rsrs) inserir a descrição da imagem aqui

0

In your code, you try to use a behavior on a label label which won’t work as you expect because you haven’t set what your block view should look like. Swap label for div may work, but will lose the functionality of the attribute for. But using two labels runs a little short of the goal, since one label shall be associated with another element through for. According to the documentation:

The <label> element represents a caption in a user interface. The caption can be Associated with a specific form control, known as the <label> element’s labeled control, either using the for attribute, or by putting the form control Inside the <label> element itself. [HTML 5.3]



But what you hope can be done so:

 * {
            margin: 0;
            padding: 0;
        }
        body {
            padding: 2rem;
        }
        fieldset {
            position:relative;
            width:100%;max-width:600px;
            min-width:305px;
            text-align:left;
            border:1px solid rgba(121,138,151,0.5);
            border-radius:3px;
            padding:0 5px 10px 5px;
        }
        .custom-content {
            position:relative;
            margin:5px 0;
        }
        legend {
            background:#ffffff;
            padding: 0.25rem;
        }
        .legend-right {
            position:absolute;
            top:-1px;
            right:5px;
            background:#ffffff;
            padding: 0.25rem;
        }
        .custom-label {
            display: inline-block;
            position:relative;
            width:200px;
            word-break:break-word;
            overflow:hidden;
        }
        .custom-label-inline-block {
            display: inline-block;
            position:relative;
            width:200px;
            word-break:break-word;
            overflow:hidden;
            background-color: aqua;
        }
        .program-action {
            position:relative;
            margin:20px 5px;
        }
        .label-chps {
            display: inline-block;
            vertical-align: top;
        }
<fieldset>
        <legend>Programa social</legend>
                
        <div class="legend-right">
            <div onclick='modalSocial();'>Incluir Programa</div>        
        </div>

        <div class="program-action">Clique com o botão direito do mouse sobre um Programa Social para ler a descrição</div>
        
        <div class="custom-content">
            <label for='chpsa' class="label-chps">
                <input type='checkbox' id='chpsa' name='psoc[]' value='xxxxx'>
            </label>
            <div data-for="chpsa" class="custom-label">
                Lorem ipsum ante mi vel sagittis libero aliquam quisque praesent aliquet suspendisse etiam praesent, senectus aenean sapien mi dapibus sit aptent eu consequat pellentesque est.
            </div>
            <br>
            <label for="chpsb" class="label-chps">
                <input type='checkbox' id='chpsb' name='psoc[]' value='xxxxx'>
            </label>
            <label for="chpsb"  class="custom-label-inline-block">
                Lorem ipsum ante mi vel sagittis libero aliquam quisque praesent aliquet suspendisse etiam praesent, senectus aenean sapien mi dapibus sit aptent eu consequat pellentesque est.
            </label>
            <br>
            <label for='chpsc' class="label-chps">
                <input type='checkbox' id='chpsc' name='psoc[]' value='xxxxx'>
            </label>
            <div  class="custom-label">
                Lorem ipsum ante mi vel sagittis libero aliquam quisque praesent aliquet suspendisse etiam praesent, senectus aenean sapien mi dapibus sit aptent eu consequat pellentesque est.
            </div>        
        </div>
    </fieldset>


In the color aqua blue, the label and the rest are elements div.

As you can see, I added a display: inline-block to make the block fit according to the container size. If the width is sufficient it stays in line, if not, the last block element goes to the line below (if there is more than one set as inline-block.



Note: Maybe the goal of using CSS1 is to simplify the code for use here, but otherwise I recommend using CSS2+. In addition to making it more readable, it will save time and effort.



References:

  • It can’t be div @Felipe Maia, otherwise the click no funfa... did not work, but thank you

  • I don’t think you even tested or read the code.

  • of course yes... I will post the image procê... It is exactly what you did... I did not change a comma... in the snippet is different even..

  • The highlighted part in blue is a label, if you click on the text you will see that the check box is marked. Text break occurs normally as well as is defined by the 200px width, which does not occur if you do not assign a display.

  • It’s @Felipe Maia!... My problem is with the line break on the label... See the part highlighted in blue in the image I posted with your code... does not break at all

  • The code I made is free of interference from other css styling. Isolated test, just this snippet.

  • Amigo @Felipe Maia, one style can interfere in another even before the current stylization?

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.