Элементы сетки переполняются из родительского контейнера с помощью сетки CSS - PullRequest
0 голосов
/ 04 июня 2018

В настоящее время я имею дело с проблемой с элементами сетки, переполняющими родительский контейнер.Я не уверен, как исправить эту проблему.Если я изменяю размер области просмотра, поля формы переполняют родительский контейнер, что не идеально.Если кто-то может оказать некоторую помощь, это было бы здорово.Большое спасибо!

Ссылка на codepen - https://codepen.io/philmein23/pen/oybrVX

Ниже приведена HTML-структура, приведенная ниже:

<div class="framed-layout-part modern container padded-container">
    <header>
        <h1>Create Contact Information</h1>
    </header>
    <section class="indent">
        <form class="person-edit-form-grid">
            <div>
                <div>
                    <label for="primary-email">Primary Email Address</label>
                    <input id="primary-email" type="text" value.bind="state.person.primaryEmail.address" readonly/>

                </div>
                <div>
                    <label for="secondary-email">Secondary Email Address</label>
                    <input id="secondary-email" type="text" value.bind="state.person.secondaryEmail.address"/>
                </div>
            </div>

            <div class="basic-info">
                <div class="basic-info-grid">
                    <label for="salutation">Salutation</label>
                    <select id="salutation" value.bind="state.person.prefix">
                        <option model.bind="null">Choose Salutation</option>
                        <option repeat.for="prefixValue of state.person.prefixValues" model.bind="prefixValue">
                            ${prefixValue.value}
                        </option>
                    </select>
                </div>

                <div class="basic-info-grid">
                    <label for="first-name">First Name</label>
                    <input id="" type="text" value.bind="state.person.firstName"/>
                </div>
                <div class="basic-info-grid">
                    <label for="middle-initial">Middle Name</label>
                    <input id="middle-initial" type="text" value.bind="state.person.middleName"/>
                </div>
                <div class="basic-info-grid">
                    <label for="last-name">Last Name</label>
                    <input id="last-name" type="text" value.bind="state.person.lastName"/>
                </div>
                <div class="basic-info-grid">
                    <label for="title">Title</label>
                    <input id="title" type="text" value.bind="state.person.title"/>
                </div>
            </div>

            <div class="phone-info">
                <h2>Phone</h2>
                <div class="phone-info-grid">
                    <label id="work-phone">Work</label>
                    <div>
                        <span>+</span>
                        <input class="country-code-width" type="text" value.bind="state.person.businessPhone.countryCode" /> 
                    </div>
                    <div>
                        <input aria-labelledby="work-phone" placeholder="Phone Number" type="text" value.bind="state.person.businessPhone.number"/>
                    </div>
                    <div>
                        <input style="width: 80px" placeholder="Extension" aria-labelledby="work-phone" type="text" value.bind="state.person.businessPhone.extension"/>
                    </div>
                </div>
                <div class="phone-info-grid">
                    <label id="mobile-phone">Mobile</label>
                    <div>
                        <span>+</span>
                        <input class="country-code-width" type="text" value.bind="state.person.mobilePhone.countryCode" /> 
                    </div>
                    <div>
                        <input id="" type="text" placeholder="Phone Number" value.bind="state.person.mobilePhone.number"/>
                    </div>
                </div>
                <div class="phone-info-grid">
                    <label id="fax-number">Fax</label>
                    <div>
                        <span>+</span>
                        <input class="country-code-width" type="text" value.bind="state.person.faxPhone.countryCode" />
                    </div>
                    <div>
                        <input aria-labelledby="fax-number" type="text" placeholder="Phone Number" value.bind="state.person.faxPhone.number"/>
                    </div>
                </div>
            </div>
        </form>
    </section>
</div>  

Ниже приведен код CSS, указанный ниже:

body {
  background: lightgrey;
 }        

 h1, h2 {
        margin-bottom: 5px;
    }

.framed-layout-part {
  border: none;
-webkit-box-shadow: 2px 2px 3px 0 #ccc;
-moz-box-shadow: 2px 2px 3px 0 #ccc;
box-shadow: 2px 2px 3px 0 #ccc;
position: relative;
border-radius: 3px;
border: none;
box-sizing: border-box;
background-color: #fff;
margin: 7px;
}

    .indent {
        margin-left: 15px;
    }

    .country-code-width {
        width: 20px !important;
    }

    .container {
        width: 30vw;
        margin: 30px auto;
    }

    .button-container {
        margin-top: 10px;
        display: flex;
        justify-content: flex-end;
    }

    #primary-email {
        border: none;
        background: lightgray;
    }

    @supports not (display: grid) {    
        .person-edit-form-grid {
            display: flex;
            flex-direction: column;
        }

        .basic-info {
            margin: 15px 0;
        }

        .phone-info {
            width: 30vw;
        }

        .phone-info-grid {
            display: flex;
        }

        label {
            flex-basis: 80px;
        }

        .phone-info-grid > div {
            margin: 0 5px 5px 0;
        }
    }

    @supports (display: grid) {
        .person-edit-form-grid {
            display: grid;
            grid-row-gap: 20px;
            padding: 10px 0;
        }

        .basic-info {
            display: grid;
            grid-row-gap: 10px;
        }

        .basic-info-grid {
            display: grid;
            grid-template-columns: 100px max-content;
        }

        .phone-info {
            display: grid;
            grid-gap: 10px;
        }

        .phone-info-grid {
            display: grid;
            grid-template-columns: 100px repeat(3, max-content);
            grid-column-gap: 10px;
        }
    }

Ответы [ 3 ]

0 голосов
/ 04 июня 2018

Основной причиной поведения является 'display: grid' в классах .person-edit-form-grid, .phone-info-grid

U можно увидеть изменение, просто удалив сетку отображения в этом классе.

Используйте правильную реализацию с помощью начальной загрузки, используя строку, cl

https://getbootstrap.com/docs/4.1/layout/overview/

0 голосов
/ 04 июня 2018

Вы можете установить минимальную ширину:

.container {
width: 30vw;
min-width: 360px;
margin: 30px auto;
}
0 голосов
/ 04 июня 2018

Вы можете использовать медиазапросы, чтобы уменьшить количество столбцов и ширину столбцов в маленьких окнах просмотра.Например:

@media screen and (max-width: 1350px){
  .phone-info-grid {
    grid-template-columns: 50px repeat(2, max-content);
  }
}

@media screen and (max-width: 900px){
  .phone-info-grid {
    grid-template-columns: 50px repeat(1, max-content);
  }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...