5

I'm creating a layout using column-count and -webkit-column-count but I found an issue that appears multiple times.

enter image description here

As you can see from this image, Chrome 45 (not happening in FF) breaks elements' border, which is very strange and quite annoying. This is a bit the code where the break happens (but I don't know why it is not happening here, only difference are fonts, and absence of Mayers css reset):

body {
  line-height: 1.5;
}
form {
  -webkit-column-count: 2;
  column-count: 2;
}
label {
  display: block;
  -webkit-column-break-inside: avoid;
  page-break-inside: avoid;
  break-inside: avoid;
  margin-top: 0.625em;
}
input {
  border: 1px solid green;
  border-radius: 4px;
  padding: 0.25em 0.5em;
}
label>span:first-child {
  width: 5em;
  display: inline-block;
}
<h2>CONFIG:</h2>
<form id="pop_values" action="" class="ng-pristine ng-valid">
  <label>
    <input type="checkbox">
    <span>Mobile</span>
  </label>
  <label>
    <input type="checkbox">
    <span>Animate</span>
  </label>
  <label>
    <span>Frecuency:</span>
    <input type="number">
  </label>
  <label>
    <span>Exclusions:</span>
    <input type="text">
  </label>
</form>

But it didn't work. Could you give any enlightenment?

TylerH
  • 20,799
  • 66
  • 75
  • 101
Vandervals
  • 5,774
  • 6
  • 48
  • 94

1 Answers1

2

Although it is not very clear (without markup) in your question, it seems your form elements (labels and inputs) are not wrapped in their respective containers and are on their own.

You are preventing break on labels only, and hence the inputs are not bound by that rule. This is the reason you are facing that problem.

Best solution would be to wrap your label-input sets in their own containing divs and apply break-inside: avoid on those divs.

Example:

* { box-sizing: border-box; }
form { -webkit-column-count: 2; -moz-column-count: 2; column-count: 2; }

form > div { -webkit-column-break-inside: avoid; page-break-inside: avoid; break-inside: avoid-column; }

form label, form input { display: inline-block; margin: 4px 0px; }
form input[type=text] { width: 50%; }
<form>
    <div>
        <input id="chk1" type="checkbox" /><label for="chk1">Mobile</label>
    </div>
    <div>
        <input id="chk2" type="checkbox" /><label for="chk2">Animated</label>
    </div>
    <div>
        <label for="txt1">Input 1:</label><input id="txt1" type="text" />
    </div>
    <div>
        <label for="txt2">Input 2:</label><input id="txt2" type="text" />
    </div>
    <div>
        <label for="txt3">Input 3:</label><input id="txt3" type="text" />
    </div>
    <div>
        <label for="txt4">Input 4:</label><input id="txt4" type="text" />
    </div>
    <div>
        <label for="txt5">Input 5:</label><input id="txt5" type="text" />
    </div>
    <div>
        <label for="txt6">Input 6:</label><input id="txt6" type="text" />
    </div>
</form>

Fiddle to see the effect of resizing: http://jsfiddle.net/abhitalks/jd7v0n8e/

Note: Last style rule in the above example is to prevent overflow of the inputs when the the available space is less than their default width.

Edit:

(after Op's comment)

Now that you have provided your markup, this arrangement should also work. As long as you are sure that all inputs are properly wrapped inside those labels.

See this snippet:

* { box-sizing: border-box; } 
form{
    -webkit-column-count: 2;
    column-count: 2;
}
label {
    display: block; margin: 2px;
    -webkit-column-break-inside: avoid;
    page-break-inside: avoid;
    break-inside: avoid-column;
}
input {
    border: 1px solid green;
    width: 50%;
}
<form>
    <label>This: <input type="text" /></label>
    <label>This is long: <input type="text" /></label>
    <label>This: <input type="text" /></label>
    <label>This: <input type="text" /></label>
    <label>This is much longer than before: <input type="text" /></label>
    <label>This: <input type="text" /></label>
    <label>This: <input type="text" /></label>
    <label>This: <input type="text" /></label>
</form>

And also this fiddle: http://jsfiddle.net/abhitalks/38wjpu28/3/

It seems that there must be something else going on in your markup besides what you have shown in your question.

Note 2: I would recommend going with a wrapping div and keeping the label and input separate. This would allow you greater control in case you need to change the layouts later on. (e.g. when you need to put label on top of input instead of side by side)

Abhitalks
  • 27,721
  • 5
  • 58
  • 81
  • I added a sample of the structure of my code. You are right, labels are on their own, but they are styled as block elements. – Vandervals Sep 11 '15 at 11:14
  • @Vandervals: Per your markup that should cause problems unless you have something else going on with your markup or styles. I have updated the answer with a demo snippet and fiddle. – Abhitalks Sep 11 '15 at 11:29
  • I don't understand the second example. What is the difference between my own and yours, other than deleting the tags? I've also attempted to exchange the – Vandervals Sep 11 '15 at 11:43
  • @Vandervals: (1) I did not remove `span`s. It was as you posted in your question. See -- http://stackoverflow.com/revisions/32477400/2 . You again updated the question to include spans. Anyway, that will not make any difference. (2) I added the example in my answer not to show differences, but to show that it works without problems. – Abhitalks Sep 11 '15 at 11:46
  • In my snippet works as well, so i couldn't detect the problem. I've tryed canceling every css rule each at a time, to see if it was `line-height`'s fault or something, or some em's not giving exact px values... but nothing, I don't know how to get those showing here... As long as I'm concerned the markup is the mostly the same... – Vandervals Sep 11 '15 at 11:51
  • @Vandervals: Please wait. Let me have a look at the updated markup of yours. Give me some time here. I wish you are not going to make any more changes to the markup in the question ;) – Abhitalks Sep 11 '15 at 11:57
  • No, I won't. Btw, the same page in FF looks good even without the `page-break` rule. It is very strange that it breaks in the border, so I'm starting to think this may be a bug. – Vandervals Sep 11 '15 at 12:11
  • @Vandervals: (1) As per your above comment, yes there are differences in Chrome / FF. (2) Regarding your problem, I suspect it could be because of `margin-top: 0.675em;` on your `label`. Try making it `0.5em` or `0.7em` and it should fix the problem. Alternatively, a margin in `px` will also fix this. (3) As to why this is happening, I am stumped. I am investigating it further. Meanwhile, could you confirm that the problem is fixed by changing the margin on the label? – Abhitalks Sep 11 '15 at 12:22
  • No, it doesn't get fixed. I tryed that and also completly removed it and it still happens. – Vandervals Sep 11 '15 at 12:50
  • @Vandervals: Nopes. Not yet. – Abhitalks Sep 14 '15 at 09:00
  • Maybe there is an element outside of the form that is pushing the elements down? Or a rule that isn't present in the snippet? Because "config" also doesn't look like the screenshot. – xpy Sep 18 '15 at 07:40