【问题标题】:Why is banner image in a simple HTML site different sizes of different pages?为什么一个简单的 HTML 站点中的横幅图像在不同页面的大小不同?
【发布时间】:2016-08-03 16:47:29
【问题描述】:

这个简单的 9 页 HTML 网站多年来一直被用作多个网站的模板。它不是为此目的而建造的,但这就是我正在处理的问题。整个网站需要大修,没有响应,等等等等。如果您仔细查看代码,页面和横幅图像的宽度属性存在多个矛盾。有一个长期的计划来建造一个新的。在短期内,它给我带来了一个我无法解决的恼人的怪癖。

横幅图像会根据需要在桌面网站和机器人上显示。在 iPhone 和 iPad 上,横幅显示在 9 个页面中的 7 个上。在其中两个页面上,图像超出了屏幕边缘。相同的规则适用于不同页面上的每个图像,并且 HTML 看起来是相同的。这些照片都是相同的尺寸和分辨率。

为什么两个页面会不同?我知道代码中存在错误,但相同的错误不会适用于每个图像吗?我在代码中看不到任何会影响一个页面与其他页面不同的内容。

我尝试了所有宽度、最大宽度、自动、百分比大小、像素大小和视图屏幕大小的变化。没有人创造了统一性。前两页的图像总是与后面的 7 页不同。我还通过验证器运行了代码,每个页面都有完全相同的错误,这些错误都与图像大小无关。

<!DOCTYPE html>
<html class="no-js"><!-- InstanceBegin template="/Templates/oneclub_17.dwt"       codeOutsideHTMLIsLocked="false" -->
<script src="https://use.typekit.net/doa5ucf.js"></script>
<script>try[{Typekit.load({ async: true });}catch(e){}</script>
<head>
<meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <script     src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
    <!-- InstanceBeginEditable name="doctitle" -->
    <title>BOKF ONE Club 2017-Welcome</title>
    <!-- InstanceEndEditable -->
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width">
    <link rel="stylesheet" href="css/main.css">
    <!-- InstanceBeginEditable name="head" -->
    <!-- InstanceEndEditable -->
    <!-- InstanceParam name="Banner Image" type="URL" value="Images/banner_bokf_hmb17_welcome.jpg" -->
</head>
<body>
    <div id="header">

        <div id="header-top">
            <div class="container">
                <div class="header-content">
                    <div id="nav">
                        <ul>
                            <li><a href="index.html">WELCOME</a></li>
                            <li><a href="destination.html">DESTINATION</a></li>
                            <li><a href="hotel.html">HOTEL</a></li>
                             <li><a href="agenda.html">AGENDA</a></li>
                           <li><a href="activities.html">ACTIVITIES</a></li>
                           <li><a href="climate.html">CLIMATE</a></li>
                           <li><a href="questions.html">Q&amp;A</a></li>
                            <li><a href="contact.html">CONTACT US</a></li>
                            <li><a href="register.html">REGISTER</a></li>
                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="banner-container">
        <img src="Images/banner_bokf_hmb17_welcome.jpg" width="1460">       </div>

    <div class="container">
      <div id="photo-caption"><!-- InstanceBeginEditable name="Caption" -->Ritz-Carlton Half Moon Bay<!-- InstanceEndEditable --></div>
      <div id="main-container">
        <div id="content"><!-- InstanceBeginEditable name="Body" -->
          <h1>Welcome</h1>
            <p>Only 30 minutes south of San Francisco is a dramatic stretch of California coastline. Here, craggy and windswept bluffs tumble onto shores pounded by endless surf to postcard-worthy perfection. This is Half Moon Bay where we will celebrate our elite’s 2016 achievements as ONE Club, March 30–April 2, 2017.</p>
        <!-- InstanceEndEditable --></div>
      </div>
    <div id="footer">
        <p>Copyright &copy; Wyndham Jade, LLC. All rights reserved.</p>
    </div>

    </div>
<script defer src="js/main.js"></script>
</body>  

.container{
width: 1280px;
position: relative;
margin-top: 0px;
margin-right: auto;
margin-bottom: 0;
margin-left: auto;
padding-top: 0px;
padding-right: 25px;
padding-bottom: 0;
padding-left: 25px;
}
#header{
background-color: white;
height: auto;
}
#header-top{
position: fixed;
top: 0;
width: 100%;
background-color: #FFFFFF;
height: 50px;
line-height: 50px;
z-index: 2;
}
    #header-top .container{
        padding: 0;
    }
    .header-content{
        text-transform:uppercase;
        color: #ffffff;
        font-size:12px;
    }


#nav {
position: relative;
height: 50px;
background-image: url(../Images/oneclub_weblogo_2017.jpg);
background-repeat: no-repeat;
background-position: left center;
padding-top: 0px;
}
#nav ul {
position: absolute;
right: 0;
margin:0;
padding:0;
list-style:none;
line-height: 12px;
margin-top: 27px;
}
#nav li {
margin:0;
padding:0;
display: inline-block;
padding-left: 5px;
padding-right: 5px;
}


#home-banner {
text-align: center;
}

.banner-container{
height: 480px;
margin-top: 50px;
position: relative;
background-color: #FFF;
}
.banner-container img {
display: block;
width: 1460px;
margin-top: 0px;
margin-right: auto;
margin-bottom: 0;
margin-left: auto;
height: 480px;
}
.banner-container img land {
display: block;
width: 1460px;
margin-top: 0;
margin-right: auto;
margin-bottom: 0;
margin-left: auto;
height: 480px;
}

#main-container {
width: 1280px;
}

【问题讨论】:

    标签: html ios css image-size


    【解决方案1】:

    这将有助于查看在 bin 或 fiddle 中显示不同的两个页面的比较。

    我在代码和 CSS 示例中注意到的几件事可能会破坏宽度。

    1. 固定宽度的嵌套元素
    2. 使用 display:block 时在嵌套的固定宽度元素上设置填充
    3. 标题中的链接向右溢出,导致水平滚动

    为了帮助您获得更一致的结果,请尝试使用可变宽度并使用 max-width 样式属性。在固定宽度元素中包含填充时,请使用 box sizing 以避免不必要的水平滚动问题。盒子大小可能会直接解决您的问题。

    Here is a jsbin with close to your original markup and CSS

    Same page with variable width (width: 100%) and max-width set. 还移除了几个嵌套元素的左/右填充,并减小了标题容器的宽度以防止溢出。

    #header-top {
     position: fixed;
     top: 0;
     width: 98%;
    }

    【讨论】:

      【解决方案2】:

      我注意到几件事。首先,您应该删除&lt;img src="Images/banner_bokf_hmb17_welcome.jpg" width="1460"&gt; 上的宽度约束,因为它是在 CSS 中处理的。此外,在 CSS 中,.banner-container img land 没有在任何地方定义,可能会导致您看不到的错误。

      您是否也尝试过在任何浏览器中使用可供您使用的开发人员选项(使用 F12 激活)。此外,对于不工作的页面,可能有一个旧的缓存 CSS 文件破坏了结果。您还需要在 iOS 上clear the cached data for the pages giving you trouble。这应该会重新获取最新的 CSS 值,并希望以正确的方式显示。

      不过,我确实很欣赏 9 页中的 7 页有效#startrek

      就未来的工作而言...我建议使用Bootstrap CSSsomething similar...

      【讨论】:

      • 是的,我使用了开发者工具。 F12是女孩最好的朋友。我已经尝试删除内联宽度约束并删除“land”规则以及创建所有其他可能的宽度规则排列。没有人在图像中产生一致性。我知道如何建立一个响应式网站。我的经验是,使用 bootstrap 等并没有添加任何我无法使用 HTML 和 CSS 做的事情。
      • 当然,我同意这些工具有时可以消除控制,甚至易于使用。只是根据我的经验提供。唯一能想到的其他事情(因为 HTML 和 CSS 很简单)是浏览器以某种方式弄乱了图像大小本身。 Mozilla 提供了“测量”您的图像的能力,您甚至可以查看原始图像资源并查看它被解释为什么大小。除非包装器 div 以某种方式迫使图像尺寸减小,否则不确定它可能是什么。从几乎完全一致的角度来看,它们不应该是这样
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-30
      相关资源
      最近更新 更多