屏幕大小调整后的布局更改 CSS

Layout change after screen resize CSS

我的设计有很多错误。

首先,here是link我一直在做的示例站点学习HTML和CSS.

http://ramroweb.com/mnml/style.css

  • 调整屏幕大小时,容器中的所有项目都会向右移动。尽管我使用了 margin: 0 auto;
  • 整个内容都在 div id="container" 之内,但它仍然选择 section tag,不包括 footer tag
  • 背景图片不适合整个尺寸,在 top 上创建了一些 padding。 如果我能在这些问题上得到帮助,那就太好了。

    谢谢...

  • 您的 body 包装器宽度固定。

    body {
        width: 1020px;
    }
    

    您可以在调整大小时将其切换为 100%

    @media all and (max-width: 1020px) {
        body {
            width: 100%;
        }
    }
    

    这应该是回答 问题所在 的一个很好的线索...根据您的需要调整 CSS 的其余部分。请将相关代码编辑到问题本身。

    要获得响应式设计,请尝试使用百分比或 vw/vh 测量值。这样所有元素都会获得与用户屏幕尺寸相对的尺寸。使您的网站可移动访问也是一种很好的做法,这样当您在较窄的屏幕上打开它时,所有内容都会很好地适合页面。更多信息 -> https://snook.ca/archives/html_and_css/vm-vh-units。例如,查看此代码(显然您可能希望调整缩放比例以满足您的需要):

    body {
        width: 100%;
        background: url(img/beach.png) center no-repeat;
        background-color: #f3f2de;
        font-family: Courier, monospace;
        font-size: 15%;
        margin: 0 auto;
    }
    
    #container {
        color: #cc0000;
        margin: 0 auto;
        width: 92%;
    }
    
    header {
        margin: 0 auto;
        text-align: center;
        border-bottom: solid 5% black;
    }
    
    nav {
    
    }
    
    nav ul {
        list-style: none;
    }
    
    nav ul li {
        display: inline-block;
        padding: 0 10%;
        margin: 0 20%;
        font-weight: bold;
    }
    
    header {
        text-align: center;
        padding: 10% 0;
    }
    
    a:link {
    
    }
    
    a:visited {
        color: #cc0000;
    }
    
    a:hover {
        color: #fff200;
    }
    
    section {
        margin: 30% 0 40%;
    }
    
    section h1 {
        text-align: center;
        font-size: 1em;
    }
    
    section a {
        display: block;
        align-content: center;
        height: 100%;
        width: 50%;
        margin: 0 auto;
        margin-bottom: 30%;
    }
    
    footer {
        display: block;
        float: left;
    }
    

    尝试在正文中添加最小宽度

    width: 100% !important;
    min-width: 1000px;
    height: 100%;
    margin: 0px;
    padding: 0px;