调整屏幕大小后的布局变化



我的设计有各种错误。

首先,这里是我一直在学习HTML和CSS的示例站点的链接。

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

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

    谢谢…

  • 要获得响应式设计,请尝试使用百分比或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;
    }
    

    你的body wrapper的宽度是固定的。

    body {
        width: 1020px;
    }
    

    当你调整

    的大小时,你可以把它改为100%
    @media all and (max-width: 1020px) {
        body {
            width: 100%;
        }
    }
    

    这应该是回答what wrong…的一个很好的线索。调整CSS的其余部分,因为你认为合适。请将相关代码编辑到问题中。

    尝试在body中添加min-width

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

    最新更新