html - CSS BODY 在移动设备上出乎意料地比预期更宽

标签 html css

该页面在桌面浏览器上看起来与预期一致,例如Firefox等。问题是在移动设备上的显示。

正确显示时,页面“BODY”的深色背景应仅显示为细框架,“mainFrame”div 的白色背景显示为中心,其中包含所有内容。

我已经将“mainFrame”类的宽度更改为 100%,但没有帮助。

应该对 CSS 进行哪些更改才能在非桌面和移动设备浏览器上正确显示?

请参阅下面的 CSS 和 HTML。

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html dir='ltr'>
<head>
<style>
html, body{height:100%;text-align: center;background:#646464;}
body{padding:0px;margin:0px; text-align: center;}

.mainFrame{
    width: auto;
    min-height:100%;
    height: 100%;
    background: white;
    border: 5px solid #CCCCCC;
    margin:auto;
}
html>body .mainFrame {width:auto; height: auto;}

th{
    text-align: center;
    padding: 9px 0px 9px 0px;
    background: #E8E8FF;
    font: bold  12px TAHOMA;
    color: #404040;
}
td {
    font: 11px  Tahoma;
    background: #DFEFFF;
    padding: 8px 5px 8px 3px;
}
td.blank{
    padding: 12px 0px;
    background: WHITE;
}
.logosmallContainer {
    position: relative;
    width: 960px;
    top: 22px;
}
.logosmallContainer1 {
    position: relative;
    width: 720px;
    top: 22px;
}
.logosmall {
float:right;
}
.jobtabs{
    position: relative;
    top:40px;
    width: 720px;
}
.upperTabs{
    position: relative;
    font-size:  12px;
    width: 720px;
    clear:both;
}
.uprTabs {
width:120px;
text-align:center;
padding:0px;
font:  12px tahoma;
float:right;
}
.uprTabs a {
width:120px;
height: 30px;
line-height:30px;
background-color: #EEEEEE;
text-decoration: none;
border-top: 1px #F5F5F5 solid;
border-left: 1px #F5F5F5 solid;
border-bottom: 1px #F5F5F5 solid;
border-right: 1px #F5F5F5 solid;
}
html>body .uprTabs a {width:118px; display:table; }

.uprTabs a:hover{
background-color: #C3E2DB;
text-decoration: none;
border-top: 1px solid #31557f;
border-left: 1px solid #31557f;
border-bottom: 1px solid #E6E6E6;
border-right: 1px solid #E6E6E6;
}
.lowerTabs{
    position: relative;
    font-size:  12px;
    width: 720px;
    border-top: solid #007FC0 5px;
    clear:both;
    }
html>body .lowrTabs a {width:118px; display:table;}
.lowrTabs {
width:120px;
background-color: #EEEEEE;
text-decoration: none;
text-align:center;
font:  12px tahoma;
float:right;
height: 27px;
line-height:27px;
}
.lowrTabs a {
width:120px;
height: 25px;
line-height:25px;
background-color: #EEEEEE;
text-decoration: none;
border-top: 1px #F5F5F5 solid;
border-left: 1px #F5F5F5 solid;
border-bottom: 1px #F5F5F5 solid;
border-right: 1px #F5F5F5 solid;
float:right;
}
.lowrTabs a:hover{
background-color: #C3E2DB;
text-decoration: none;
border-top: 1px #31557f solid;
border-left: 1px #31557f solid;
border-bottom: 1px #E6E6E6 solid;
border-right: 1px #E6E6E6 solid;
}
.vMsg2 {
    font: bold 22px arial;
    position: relative;
    top: 78px;
    width: 720px;
    text-align: center;
    direction:rtl;
    clear:both;
}
.vMain {
    position: relative;
    top: 113px;
    width:620px;
    direction:rtl;
    clear:both;
}
.vMainJobs {
    position: relative;
    top: 30px;
    width:620px;
    direction:rtl;
    clear:both;
}
.pgn1 {
    width: 330px;
    top:30px;
    position: relative;
}
html>body .pgn1  {display:table;}
.pgnbx {
    width: 30px;
    height: 20px;
    line-height:20px;
    float:right;
    text-decoration: none;
    text-align:center;
}
html>body .pgnbx a {display:table;}
.pgnbx a{
    width: 30px;
    border-width: 1px;
    border-color: #ffe #aaab9c #ccc #fff;
    border-style: solid;
    background: #FFF;
    background: #CDF6ED;
}
.pgnbx a:hover{
    width: 30px;
     background: #B3E1D7;
    border-color: #fff #ccc;
    text-decoration: none;
}
.mainXJobs {
    height:55px;
    clear:both;
}
.ad728Y{
    position: relative;
    width:728px;
    border-top:  double  thick #D3D3D3;
    border-bottom:  double  thick #D3D3D3;
}
</style>
</head>
<body topmargin='0' leftmargin='0' >
 
<div class="mainFrame" align="center">
 
<div class="logosmallContainer1">
    <div class="logosmall"><img border="0" src="media/small.jpg" alt="logo"></div>
<DIV class=adtop2>
        </div>
</div>
 
<div class="jobtabs">
 
            <div class="upperTabs">
                <DIV class=uprTabs><A href="?Category6">Category 6</DIV>
                <DIV class=uprTabs><A href="?Category5">Category 5</A></DIV>
                <DIV class=uprTabs><A href="?Category4">Category 4</A></DIV>
                <DIV class=uprTabs><A href="?Category3">Category 3</A></DIV>
                <DIV class=uprTabs><a href="?Category2"> Category 2</a></DIV>
                <DIV class=uprTabs><A href="?Category1">Category 1</A></DIV>
            </div>
            <div class ="lowerTabs">
                <DIV class=lowrTabs><A href="?Category7">Category 7</A></DIV>
                <DIV class=lowrTabs><A href="?Category8">Category 8</A></DIV>
                <DIV class=lowrTabs><A href="?Category9">Category 9</A></DIV>
                <DIV class=lowrTabs><A href="?Category10">Category 10</A></DIV>
                <DIV class=lowrTabs><a href="?Category11"> Category 11</a></DIV>
                <DIV class=lowrTabs><A href="?Category12">Category 12</a></DIV>
            </div>
 
</div>
            <div class='vMsg2'><H1>
            GENERAL LIST
            </H1></div>
            <br><br><br><br><br><div class="ad300" id="ad"></div><div class='vMainJobs' dir='ltr'> <table border='0'  width='100%' dir='ltr' cellspacing='1'>
<tr>
    <th width='100%' colspan='2'>DETAILS</th>
</tr>
 
<tr>
    <td width='18%'height='18' valign='top'>LOCATION </td>
    <td height='18'>LONDON</td>
</tr>
<tr>
    <td width='18%'height='18' valign='top'>LINK</td>
    <td height='18'><a href='https://www.example.com'>https://www.example.com</a></td>
</tr>
</table>
    <table border='0'>
        <tr>
          <td class='blank'>
            <a href='#top'>top of page</a>
            </td>
        </tr>
    </table>
        </div>
    <div class="pgn1">
             <div class='pgnbx'>
            <a href='?jpage=2'>2</a>
            </div>
            <div class='pgnbx'>
            <a href='?page=3'>3</a>
            </div>
            <div class='pgnbx'>
            <a href='?jpage=4'>4</a>
            </div>
            <div class='pgnbx'>
            <a href='?page=5'>5</a>
            </div>
             <div class='pgnbx'>
            <a href='?jpage=6'>6</a>
            </div>
            <div class='pgnbx'>
            <a href='?page=7'>7</a>
            </div>
            <div class='pgnbx'>
            <a href='?jpage=8'>8</a>
            </div>
            <div class='pgnbx'>
            <a href='?page=9'>9</a>
            </div>
            <div class='pgnbx'>
            <a href='?page=10'>10</a>
            </div>
           
            <div class='pgnbx'>
            <a href='?jpage=11'>11</a>
            </div>
            <div class='pgnbx'>
            <a href='?page=12'>12</a>
            </div>

        </div>
    <div class="mainXJobs">&nbsp;</div>
    <DIV class="ad728Y"> PUT item "Classicus" here HERE</DIV>
    <br><br><br>
    </div>
    </body>
    </font>
    </html>

最佳答案

你的 body 不调整的原因是因为你使用 px 分配宽度。尝试将其更改为“%”或“vw”。您始终可以分配 max-widthmin-width如果您想限制宽度。

如果需要让子容器适应父容器,请指定宽度:100%。

关于html - CSS BODY 在移动设备上出乎意料地比预期更宽,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72595041/

相关文章:

html - 如何在 Chrome 或 Firefox 中打印特定的 HTML 元素而不是整个页面?

javascript - 使用 javascript 函数打印出动态 html 表(jquery 数据表插件)

javascript - 具有两个一致单词的多行打字机效果

javascript - 在哪里存储临时实时 &lt;style&gt; 样式

html使图像按钮尺寸等于图像尺寸

javascript - Bootstrap 3 不允许我在带有过渡的悬停时使用 CSS/JQuery 图像替换

javascript - 使用两个下拉菜单的输入更改按钮上的链接?

html - ruby /沃提尔 : go to next button of the same class

html - 触摸设备的 CSS 过渡悬停效果

html - 通过在调整浏览器大小时在图像下添加文本来使页面响应