如何使我的网站放大和缩小而不影响中心的网站布局?

时间:2018-03-18 19:02:28

标签: html css

当我的网站100%缩放时,它看起来还不错......

  • 当我放大时,一切顺利
  • 当我缩小时,它全部向左移动

我该如何制作,以便我的网站放大和缩小而不会影响中心的网站布局?

e.g。喜欢这个网站http://www.johnlewis.com

我是编码的初学者。

HTML和CSS如下所示。

HTML

    <html>

    <head>
    <meta charset="utf-8"/>
    <title> Josh Taylor</title>

     <link rel="stylesheet" type="text/css" href="main.css">
     <link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet" 
    type='text/css'>
    <link rel="shortcut icon" href="Icon.png"/>

    </head>

    <body>


    <div id="nav-div">
        <ul>
            <h1>JOSH TAYLOR</h1>
            <li><a href="">Contact</a></li>
            <li><a href="">CV</a></li>
            <li><a href="">Portfolio</a></li>
            <li><a href="">Home</a></li>
        </ul>
    </div>

    <div id="main-left">


     <h2> A BIT ABOUT ME </h2>
     <p> this crap is only here to show what it would look like mate I don't 
    want it sounding boring like my CV and needs some life so give it some josh 
    </p>

    <h3> INTERESTS</h3>


    </div>

    <div id="main-right">


        <img src="CopenhagenJosh.png">
    </div>
    <div id="main-social">
    </div>

    <div id="interests">
        <img src="CopenhagenJosh.png">
        <img src="CopenhagenJosh.png">
        <img src="CopenhagenJosh.png">
        <img src="CopenhagenJosh.png">
        <img src="CopenhagenJosh.png">
    </div>

    <div id="intereststitles">
     <p> Hello</p>
     <p> Hello</p>
     <p> Hello</p>
     <p> Hello</p>
     <p> Hello</p>
     </div>

    <div id="portfolio-left">
        <h2> PORTFOLIO</h2>
    </div>
    <div id="portfolio-right">
        <p> This is my creative work ayoooo below...</p>
    </div>

           <div id="portfolio-1">
            <img src="AppIcon.png">
           <img src="AppIcon.png">
           <img src="AppIcon.png">
            <img src="AppIcon.png">
           <img src="AppIcon.png">
           <img src="AppIcon.png">
        </div>

    <div id="CV">
    <div id="CV-left">
     <h2> CV </h2>
    </div>
    <div id="CV-right">
    </div>
    <div id="CV-img">
    <img src="CopenhagenJosh.png">
    </div>    
    <div id="contact">

    <div id="contact-left">
          <h2> CONTACT </h2>
    </div>
    <div id="contact-right">
    </div>

    </div>

    </body>

    </html>

CSS

    body {
     font-family: 'Lato', sans-serif;
     font-style:italic
     }

    html{
    padding: 0px;
    margin: 0px;
    background: url(sky.jpg);
    background-size:contain;
    background-repeat:no-repeat;
    display: inline-block;
    }

    /* FOOTER NAVIGATION */

    #nav-div {
    opacity: 1;
    font-size: 15px;
    }

    #nav-div h1{
    color: lightskyblue;
    cursor: pointer;
    width: px;
    float: left;
    margin-left: 600px;
    margin-top: 0px;
    margin-bottom: 0px;
    padding: 0px;
    font-size: 25px;
    }

    #nav-div h1:hover{
    color: white;
    transition:all 0.40s;
    }


    #nav-div ul{
    margin: 0px;
    padding: 0px;
    width: 100%;
    height: 80px;
    background: ;
    line-height: 80px;
    float:right;
    border-bottom: px solid black;
    margin-right: 300px;
    }

    #nav-div ul a{
    text-decoration: none;
    color: lightskyblue;
    padding: 25px;
    }

    #nav-div ul a:hover{
    color:white;
    transition:all 0.40s;
    font-style:italic;
    }

    #nav-div ul li {
    list-style-type: none;
    display: inline-block;
    float: right;
    font-style:normal; 
    font-size: 15px;
    }

    #main-left{
    float: left;
    display: inline-block;
    width: 40%;
    height: 250px;
    margin-top: 100px;
    }

    #main-right{
    float: left;
    padding: px;
    display: inline-block;
    width: 22%;
    height: 175px;
    margin-top: 100px;
    }

    #main-right img{
    float: left;
    margin-left ;
    width: 150px;
    height: 150px;
    padding: 10px;
    display: inline-block;
    }

    #main-social{
     float: left;
    display: inline-block;
    margin-left: 7%;
    width: 10%;
    height: 250px;
    margin-top: 100px;
    }

    #main-left h2{
    width: 300px;
    height: 50px;
    font-size: 35px;
    color: white;
    display: inline-block;
    margin-left: 300px;
    margin-right: %;
    margin-top: 0;
    margin-bottom:0;
    float: left;
    }

    #main-left p{
    width: 250px;
    height: 100px;
    margin-top: px;
    margin-left: 300px;
    margin-right: 5%;
    font-size: 17px;
    color: darkgrey;
    display: inline-block;
    position: relative;
    }

    #main-left h3{
    margin-top: px;
    width: 150px;
    height: 30px;
    margin-left: 300px;
    font-size: 20px;
    color: white;
    display: inline-block;
    float: left;
    }

    #interests {
    width: 100%;
    height:125px;
    margin-top:px;
    margin-left: 300px;
    display: inline-block;
    }

    #interests img{
    padding: 14px;
    Height: 100px;
    Width: 100px;
    margin-bottom: 0px;
    }

    #intereststitles{
    width: 100%;
    height:100px;
    margin-top:0px;
     margin-left: 300px;
    display: inline-block;
      color: white;
    }

    #intereststitles p{
    padding: 14px;
    margin-top:0px;
    Height: 10px;
    Width: 100px;
    font-style: normal;
    display: inline-block;
    text-align: center
    }

     #portfolio {
    width: 100%;
    height: 100%;
    background-color: gray;
    opacity: 1;
    }

    #portfolio-left{
    background-color: gray;
    float: left;
    width: 25%;
    height: 100px;
     }

    #portfolio-left h2{
    width: 200px;
    height: 50px;
    font-size: 35px;
    color: white;
    display: inline-block;
    margin-left: 200px;
    margin-right: ;
    margin-top: 25px;
    margin-bottom:0;
    float: left;
    }

    #portfolio-right{
    background-color: gray;
    float: right;
    width: 75%;
    height: 100px;
    margin-top: 0px;
    }

    #portfolio-right p{
    font-size: 20px;
    color: white;
    display: inline-block;
    margin-left: 0%;
    margin-right: %;
    margin-top: 36px;
    margin-bottom:0;
    padding: 0px;
    float: left;
    }

    #portfolio-1{
    margin-left: 0%;
    width: 100%;
    display: inline-block;
    text-align: center;
    padding:0%;
    margin:0;
    background-color: gray;
    }

    #portfolio-1 img{
    display: inline-block;
    padding: 0px;
    width:33%;

    }

    #CV {
    width: 100%;
    height: 900px;
    background-color: skyblue;
    opacity: 1;
    }

    #CV-left{
    float: left;
    width: 430px;
    height: 100px;
    }

    #CV-left h2{
   font-size: 35px;
    color: white;
    display: inline-block;
    margin-left: 200px;
    margin-right: ;
    margin-top: 25px;
    margin-bottom:0;
    float: left;
    }

    #CV-right{
    float: right;
    width: 75%;
    height: 100px;
    margin-top: 0px;
    }

    #CV-right p{
    font-size: 20px;
    color: white;
    display: inline-block;
    margin-left: 0%;
    margin-right: %;
    margin-top: 40px;
    margin-bottom:0;
    padding: 0px;
    float: left;
    }

    #contact {
    width: 100%;
    height: 500px;
    background-color: mediumpurple;
    opacity: 1;
    }

    #contact-left{
    float: left;
    width: 50%;
    height: 900px;
    }

     #contact-left h2{
    font-size: 35px;
    color: white;
    display: inline-block;
    margin-left: 200px;
    margin-right: ;
    margin-top: 25px;
    margin-bottom:0;
    float: left;
    }

    #contact-right{
    float: right;
    width: 50%;
    height: 900px;
    }

2 个答案:

答案 0 :(得分:2)

您需要div作为网页的包装,并设置固定的widthmax-width,如果您希望内容能够在较小的屏幕上变小{{{ 1}}设置为marginmargin-left的自动以保持页面居中。

这正是您提到的网页所做的 - Wrapper

答案 1 :(得分:0)

您可以将中心内容水平居中在CSS中,方法是将其放在块级元素(如div)中,左右边距设置为“自动”。看看Centering in CSS: A Complete Guide > Horizontally > Block level element。在您的情况下,您可能希望在div中的所有内容周围添加body,为其设置一个宽度,然后添加margin: 0 auto。请注意,您可能希望使用max-width而非width来支持较小的浏览器(请参阅CSS Layout - width and max-width)。

在您提到的示例网站中,有一个div,ID为“包装器”,其中包含所有居中的内容。