Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specify column size on a parent element (or on a template row) #19258

Closed
bjornte opened this issue Feb 17, 2016 · 2 comments
Closed

Specify column size on a parent element (or on a template row) #19258

bjornte opened this issue Feb 17, 2016 · 2 comments

Comments

@bjornte
Copy link

bjornte commented Feb 17, 2016

For context and a HTML example, see this post on Stack Overflow.

Normally you specify the column size of the <div> on the element itself.

But e.g. when building a form with multiple rows of similarly styled attribute-value pairs, it would be beneficial to specify this on a parent element, so that you don't have to repeat the exact same styling on multiple rows of elements. Another way to achieve the same effect would be to use the first row as a template, and to apply this style to subsequent rows.

On my current layout, I have 11 attribute-value pairs, so I would save 20 ((11-1)*2) classes if I could specify this on a parent or template element. This would improve brevity (and, in my opinion, legibility) and reduce room for errors.

Has this been proposed for Bootstrap 4 (or previous versions)? I assume this must have been raised by other people than myself, but I haven't found any threads. I guess I'm missing the correct keyword or term. Sorry if this is a duplicate.

@cvrebert
Copy link
Collaborator

so that you don't have to repeat the exact same styling on multiple rows of elements

Well, if you're using templates, you only have to write the column layout once and then merely invoke it when rendering each row. Of course, that doesn't affect the verbosity of the final output HTML at all.


As far as a CSS approach, the problem I see is that quite a lot of CSS would be required to cover all the possible combinations of # of columns and widths of columns. And it would seem to require a bunch of :nth-child selectors, which increases CSS specificity, which we're generally trying to avoid in Bootstrap 4.

FWIW, your scenario is fairly straightforward to accomplish by adding a little custom Sass (for the exact layouts your project needs) that utilizes Bootstrap's grid mixins.

Another way to achieve the same effect would be to use the first row as a template, and to apply this style to subsequent rows.

It's probably possible to implement something like that using display: table; and table-layout: fixed;, or Flexbox. Could be interesting! Your form use-case seems pretty common.

@mdo
Copy link
Member

mdo commented Feb 17, 2016

Thanks, but we won't be doing anything to tackle this in Bootstrap.

@mdo mdo closed this as completed Feb 17, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants