make a single row in CSS grid span all columns

假如想象 提交于 2019-12-13 05:09:27

问题


How I can make the <legend> span all rows, so it will mess up the <fieldset> which is styled as a 3 column CSS grid?

<fieldset>
  <legend>Personal Details</legend>
  <label class="field__label" for="first-names">
            First names
        </label>
  <input class="form__entry" id="first-names" type="text" name="firstName">
  <span class="form__feedback form__instructions">
            Must only use letters, spaces, hyphens and apostrophes
        </span>
</fieldset>

CSS:

form {
    display: grid;
    grid-template-columns: minmax(100px, max-content) minmax(200px, max-content) minmax(200px,1fr);
    grid-gap: 10px;
}

fieldset {
    display: contents;
}

回答1:


Maybe it is better to use:

fieldset legend {
       grid-column: 1/-1;
 }

Or if you only need 3 columns

fieldset legend {
       grid-column: 1/ span 3;
 }



回答2:


Apply

fieldset legend {
    grid-column: 1/4;
}

to the CSS. This makes it span three columns.



来源:https://stackoverflow.com/questions/50576999/make-a-single-row-in-css-grid-span-all-columns

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!