html - 为什么一个简单的 HTML 站点中的横幅图像在不同页面中大小不同?

标签 html ios css image-size

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

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

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

我已经尝试了宽度、最大宽度、自动、百分比大小、像素大小和 View 屏幕大小的所有变体。没有一个创造了统一性。前两页的图像总是与以下 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;
}

最佳答案

如果能够比较两个在 bin 或 fiddle 中显示不同的页面,将会有所帮助。

我在代码和 CSS 示例中注意到的一些可能会影响宽度的地方。

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

为了帮助您获得更一致的结果,请尝试使用可变宽度并使用最大宽度样式属性。在固定宽度元素中包含填充时,使用 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%;
}

关于html - 为什么一个简单的 HTML 站点中的横幅图像在不同页面中大小不同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36584008/

相关文章:

css - 如何居中三个span3

javascript - 根据季节(当前日历月)更改 <body> 的背景图片(在 CSS 中)

javascript - Leaflet.js 快速入门基本示例演示

HTML 表格列右对齐

javascript - JSON.stringify 与示例不同

iphone - Oauth 和 Twitter API 的起点(用于 iOS 开发)

android - flutter 错误无法确定任务 ':app:compileDebugJavaWithJavac'的依赖关系

ios - 如何避免因小数据模型更改而产生巨大的 .xcmappingmodel 文件?

android - 如何在 Android 上的 Phonegap 中设置古吉拉特语字体

html - 响应式 Div 中的垂直对齐文本