【问题标题】:css layout not working in different screens?css布局不能在不同的屏幕上工作?
【发布时间】:2014-11-26 17:23:53
【问题描述】:

我想让一个网站调整高度和宽度以适应任何屏幕,我的意思是它必须根据屏幕大小来改变大小。我编写了这段代码,它在我的电脑上看起来很完美,但是当我在屏幕较小的工作电脑上打开我的网站时,我看到网站上的所有东西都没有放在正确的位置,我的意思是它搞砸了。

代码:

  <html>
    <head><title>overview</title>
    <link rel="stylesheet" type="text/css" href="style/style.css">
    </head>
            <body>
               <?php
                  @session_start();
                 if(isset($_SESSION ['id'])) {
                    print ("
                     <div id='nav'><a href='logout.php'>logout</a></div>
                     <iframe src='mainpage.php' name='sidemenu' id='mp'></iframe>
                     <iframe src='sidemenu.php' name='mainpage' id='sm'></iframe>
                     <footer style='background: #4276A4;height: 38px;border: none;'</footer>
                    ");
                  } else { echo "<meta http-equiv='refresh' content='0,login.php'>";}
               ?>
            </body>
  </html>

css代码:

    @font-face {
        font-family: "JF Flat Regular";
        src: url('fonts/JF/JF-Flat-regular.eot');
        src: url('fonts/JF/JF-Flat-regular.eot?#iefix') format('embedded-opentype'),
        url('fonts/JF/JF-Flat-regular.svg#JF Flat Regular') format('svg'),
        url('fonts/JF/JF-Flat-regular.woff') format('woff'),
        url('fonts/JF/JF-Flat-regular.ttf') format('truetype');
        font-weight: normal;
        font-style: normal;
    }

    #cmessage {
    display:none;
    }
    #sr,#nw {
    text-decoration:none;
    }

    .si {
    background: #4276A4;
    color: #D9D9D9;
    font-size: 14px;
    float: right;
    font-weight: 900;
    padding: 12px;
    width: 239px;
    text-align: right;
    text-decoration: none;
    border-bottom:1px solid rgba(255, 255, 255, 0.1);
    font-family: "JF Flat Regular";
    }

    #b {

    background: #4276A4;

    }

    .st {

    background: #4276A4;
    color: #D9D9D9;
    font-size: 12px;
    float: right;
    font-weight: 900;
    padding: 8px;
    width: 239px;
    text-align: right;
    text-decoration: none;
    font-family: "JF Flat Regular";
    display:none;

    }

    .si:hover {
    background: rgba(255, 255, 255, 0.06);


    }
    .st:hover {
    background: rgba(255, 255, 255, 0.06);


    }

    #om {

    display:none;
    float: right;
    padding: 8px;
    width: 239px;
    text-align: right;

    }

    #home {

    background: #4276A4;
    color: #D9D9D9;
    font-size: 16px;
    float: right;
    font-weight: 900;
    padding: 8px;
    width: 239px;
    text-align: right;
    text-decoration: none;
    font-family: "JF Flat Regular";
    }





    #nav { 

    width: 100%;
    height: 38px;
    background: #2D5F8B;
    box-shadow: -10px 0px 20px -15px black;

    }
    html, body {
        margin: 0;
        padding: 0;
    }
    #mp {

    height:92.3%;
    width:86.5%;
    border:2px dashed black;
    border-right:none;
    border-bottom:none;
    margin:0;
    padding: 0;
    border-top:none;

    }
    #sm {

    float:right;
    height:95.5%;
    width:13.4%;

    border:none;
    z-index:100;position:absolute;

    }
    .img {

    height: 15px;
    padding-left: 2px;
    }
    #login {
      position: absolute;
      top: 30%;
      left: 50%;
              width: 360px;
      height: 340px;
      margin: -100px 0 0 -100px;
    background:rgba(66, 118, 164, 0.69);
    box-shadow: 0px 0px 14px rgba(0, 0, 0, 0.13);
    }
    .linput {

    width: 300px;
    height: 31;
    text-align: right;
    font-family: "JF Flat Regular";
    padding-right: 30px;
    border:none;
    margin-left: 30px;
    }
    .sinput {

    width: 300px;
    height: 31;
    text-align: right;
    font-family: "JF Flat Regular";
    padding-right: 30px;
    border:none;
    margin-left: 30px;
    }

    #form {

    margin-top: 65px;


    }
    .lbutton {

    width:132px;
    height:35px;
    background-color:rgba(75, 141, 248, 0.85);
    border:none;
    color:white;
    font-family: "JF Flat Regular";
    margin-left: 121px;
            margin-top: 25px;
    position: absolute;
    }
    .lbutton:hover {
    background-color:rgba(75, 141, 248, 0.31);


    }
    .limg {

    height: 15px;
    padding-left: 2px;
    margin-left: -25px;

    }
    #loginp {

    font-family: "JF Flat Regular";
    color: rgba(255, 255, 255, 0.93);
    margin-top: 29px;
    position: absolute;
    margin-left: 135px;

    }
    #hrlogin {
    margin-top: 61px;
    color:rgba(255, 255, 255, 0.1);
    }
            #new {
    font-family: "JF Flat Regular";
    color: #FFF;
    margin-top: -8px;
    margin-left: 225px;
    }
    #nhref {
    font-family: "JF Flat Regular";
    color: #FFF;
    margin-top: -41px;
    margin-left: 125px;
    position: absolute;
    font-size: 12px;

    }
    #lger {
    font-family: "JF Flat Regular";
    color: #FFF;
    margin-left: 907px;
    margin-top: 100px;


    }
    #signup {
    display:none;
      position: absolute;
      top: 30%;
      left: 50%;
      width: 360px;
      height: 340px;
      margin: -100px 0 0 -100px;
    background:rgba(66, 118, 164, 0.69);
    box-shadow: 0px 0px 14px rgba(0, 0, 0, 0.13);
    border:none;
    }
    #back {

    display:none;

    }
    #bb { 


    }
    #ibar {


    background-color: #E1D3D3;
    color: #FFF;
    font-family: "JF Flat Regular";
    text-align: right;
    padding-right: 25px;
    font-size: 20px;
    }
    .orderform {
        display: block;
        width: 100%;
        height: 34px;
        padding: 3px 12px;
        font-size: 14px;
        line-height: 1.42857;
        color: #555;
        background-color: #FFF;
        background-image: none;
        border: 1px solid #CCC;
        border-radius: 4px;
        box-shadow: 0px 1px 1px rgba(0, 0, 0, 0.075) inset;
        transition: border-color 0.15s ease-in-out 0s, box-shadow 0.15s ease-in-out 0s;
    font-family: "JF Flat Regular";
    }

    .orderform:focus {

    border-color: #999;
    outline: 0px none;
    box-shadow: none;

    }

【问题讨论】:

  • 考虑将 Bootstrap 用于响应式网站,另外,我认为您在这里犯了一个错误:src='mainpage.php' name='sidemenu' id='mp'。我猜这个名字应该是 mainpage 而不是 sidemenu,在 sidemenu 中也是如此。
  • @User8889 我将尝试引导程序,src='mainpage.php' name='sidemenu' id='mp' 它的 tfor 在同一页面中打开另一个框架内的内容:)跨度>
  • 适应宽度OK。适应身高?如果您不是在设计游戏或某些精美的背景完全覆盖屏幕(à la one-page-layout),那么只需忽略高度,让用户滚动、缩放等内容和内容流。网页不是 PDF(分页媒体)

标签: php css


【解决方案1】:

我无法添加评论。所以回答它。

您还没有使您的风格具有响应性。为不同的屏幕尺寸定义样式。

例如:

@media (max-width: 1024px) and (max-height:768px) { //for screen with max-width 1024px apply this style

    .banner {
       width:100px;
       height:150px;
    }
}

@media (max-width: 880px) {//for screen with max-width 880px apply this style   
    .banner {
       width: 60px;
       height: 90px;
     }
}

在上面的代码中,不同的样式被应用到'banner'类,具体取决于屏幕大小。

或按照@User8889 的建议使用 Bootstrap 进行响应。

【讨论】:

  • 你的牙套不匹配
  • 这不是一个答案,只是因为你不能评论不是你应该把它作为答案的理由。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-10-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多