简体   繁体   English

最小化后如何使页面布局保持不变?

[英]How to make the page layout stay the same after minimized?

How do I make my page layout stay the same and not become all clumped up when minimized? 如何使我的页面布局保持不变,并且在最小化时不会变得一团簇?

这是该页面通常应具有的外观

but when minimized the page layout becomes 但是当最小化时,页面布局变成

都挤了,布局弄乱了

. I was wondering how I could fix this? 我想知道如何解决这个问题? I'm still new to HTML and CSS so I was having trouble with figuring this out. 我对HTML和CSS还是很陌生,所以我很难弄清楚这一点。

Sorry if the coding is a bit messed up this is my first time doing html and css! 抱歉,如果编码有点混乱,这是我第一次做html和CSS! Appreciate all of the help I can get. 感谢所有我能得到的帮助。 I'm also doing this with google apps script. 我也在用Google Apps脚本执行此操作。

Rather than using hardcoded px values (such as margin-left: 310px ), set width: 100% on your body element and use percentage values. 不要在您的body元素上设置width: 100%并使用百分比值,而不是使用硬编码的px值(例如margin-left: 310px )。 So, instead of margin-left: 310px for a margin-left of a quarter of the screen, you can use margin-left: 25% . 所以,与其margin-left: 310pxmargin-left屏幕的四分之一,可以使用margin-left: 25%

Add width: 1000px; 新增width: 1000px; to your container. 到您的容器。 Then the layout should stay consistent. 然后,布局应保持一致。

Something like this? 像这样吗 https://jsfiddle.net/9nguoepu/7/ I just added some divs wrapping your labels and form inputs and a little css. https://jsfiddle.net/9nguoepu/7/我刚刚添加了一些div,用于包装标签,表单输入和一些CSS。

    <style type="text/css"> * {
    margin: 0
}
.container {
    margin-left: auto;
    margin-right: auto
}
.header {
    background-color: #8000FF;
    margin:auto;
    width: 50%;
    border:3px solid #41087B;
    padding: 10px;
}
.header img {
    float:left;
    padding: 5px;
}
.header h1 {
    color: white;
    line-height: 80px;
    text-align:center
}
.label {
   float: left;
    padding: 5px;
    color: red;
}
.label-container {
width: 50%;
    float:left;
}
.label p {
    padding: 2px
}
.inputBox {
    float:left;
}
.inputBox p {
    padding: 1px
}
.label2 {

    float:left;
    padding:5px;
    color: red
}
.label2 p {
    padding:2px
}
.inputBox2 {
    float:left;
}
.inputBox2 p {
    padding: 1px
}
.contentBackground {
    background-color:#D8D8D8;
    clear:left;
    width: 60%;
    margin: auto;
    height: 200px
         display: block;
}
.uploadFile p {
    text-align:center;
    padding: 20px;
    color:red
}
.content p {
    color:red;
    padding: 7px
}
.dropDown p {
    padding: 40px;
    margin-left: 8px;
    height:
}
.moreFiles {
    text-align:center
}
.textBox {
    text-align: center
}
.textBox p {
    text-align:center;
    padding: 5px
}
.button {
    text-align: center
}
</style>

Setting minimum widths prevents elements from getting squished. 设置最小宽度可以防止压扁元素。 https://jsfiddle.net/9nguoepu/9/ https://jsfiddle.net/9nguoepu/9/

HTML 的HTML

<div class="customer-info-container">
            <div class="label">

                <p><b>Customer Name</b>
                </p>
                <p><b>Due Date</b>
                </p>
                <p><b>Phone #</b>
                </p>
            </div>
            <div class="inputBox">

                <p>
                    <input type="text">
                </p>
                <p>
                    <input type="text">
                </p>
                <p>
                    <input type="text">
                </p>

            </div>
            <div class="label2">

                <p><b>Contact</b>
                </p>
                <p><b>E-mail</b>
                </p>
                <p><b>PO#</b>
                </p>
            </div>
            <div class="inputBox2">

                <p>
                    <input type="text">
                </p>
                <p>
                    <input type="text">
                </p>
                <p>
                    <input type="text">
                </p>

            </div>
        </div>

CSS 的CSS

 .customer-info-container{
        width: 800px;
        min-width: 800px;
    }

.customer-info-container{
        text-align: center;
        margin-left: auto;
        margin-right: auto;
    }
    .customer-info-container div  {
        display: inline-block;
    }
 .contentBackground {
    background-color:#D8D8D8;
    clear:left;
    min-width:800px;
    width: 60%;

    margin: auto;
    height: 200px
}

The issue is you're mixing percentage and pixel units. 问题是您要混合百分比和像素单位。 Here, I've updated the label/inputs to be all in percentages. 在这里,我将标签/输入全部更新为百分比。 https://jsfiddle.net/9nguoepu/8/ https://jsfiddle.net/9nguoepu/8/

However, note that they still "squish". 但是,请注意,它们仍然“压缩”。 If they should remain the same width no matter the users' viewport size, set a min-width on your body tag in CSS. 如果无论用户的视口大小如何,它们都应保持相同min-width ,请在CSS的body标签上设置min-width The user will have a horizontal scrollbar in this case, if their viewport is too narrow (like on a mobile device, for example). 如果用户的视口太窄(例如,在移动设备上),则在这种情况下,用户将具有水平滚动条。

I also would recommend making the forms more semantic, as I did in the js fiddle - using <label> and keeping them next to/near the input they're labelling. 我还建议像在js小提琴中所做的那样,使表单更具语义-使用<label>并将其保留在要标记的输入旁边/附近。 To be completely accessible, you should add a for attribute with the id of the input . 为了完全可访问,您应该添加带有input的id的for属性。 For example: 例如:

<label for="customer-phone-num">Phone Number</label>
<input type="text" id="customer-phone-num" />

Note that this is an id, so it has to be unique-per-page. 请注意,这是一个ID,因此每页必须唯一。

You should also be careful to separate styles from semantics. 您还应该注意将样式与语义分开。 For example, the <b> tag doesn't mean anything if you're reading the source, but visually, it means it should be bold. 例如,如果您正在阅读源代码, <b>标记就没有任何意义,但是在视觉上,它意味着它应该为粗体。 Those kinds of stylistic specifications should be handled in the CSS. 这些样式规范应在CSS中处理。 Read this Q&A for more details: https://softwareengineering.stackexchange.com/questions/255366/why-are-the-b-and-i-tags-deprecated 阅读此问答以获取更多详细信息: https : //softwareengineering.stackexchange.com/questions/255366/why-are-the-b-and-i-tags-deprecated

As mentioned by others, you can force everything to stay the same by giving the container a set width. 正如其他人提到的,您可以通过给容器指定宽度来强制所有内容保持不变。 For example, you could define a width to the body: 例如,您可以定义主体的宽度:

body {
    width: 1000px;
}

Most modern websites are created with Responsive Web Design in mind, meaning that elements on the page will shift around depending on the window size. 大多数现代网站都是在考虑响应式Web设计的情况下创建的,这意味着页面上的元素将根据窗口大小而变化。 This allows the same webpage to appear correctly on every device, including small mobile screens. 这样一来,同一网页就可以正确显示在所有设备上,包括小型移动屏幕。

Bootstrap is one of the most common frameworks used to create responsive web pages. Bootstrap是用于创建响应式网页的最常见框架之一。 You might be interested in reading this tutorial: http://www.revillweb.com/tutorials/bootstrap-tutorial/ . 您可能对阅读本教程感兴趣: http : //www.revillweb.com/tutorials/bootstrap-tutorial/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM