1

好的,我拼命尝试定位 2 个元素,一个边和一个部分(我认为这些 HTML5 元素的使用与它们所持有的内容相关)。

对于下一页单击此处,我​​试图使“位置”(旁边)元素保持静态并保持在容器 div 的左侧。至于“区域”(部分),我希望它保持在页面的右侧(与“位置”元素处于同一水平)但是当尺寸减小时,我需要它保持在右侧并缩小宽度,里面的内容显示我现在的样子。我似乎已经正确设置了它,其中包含的 div 在缩小时显示在哪里,但我无法将它定位在位置元素的下一个(在级别上)。

请参阅以下标记:

<div class="mainwrapper">
  <aside id="locations">
    <h4 style="border-bottom: 1px dotted #990000;">Locations</h4>
    <ul>
      <li>
        <a href="recentwork.htm">
          <span>Recent Work</span>
        </a>
      </li>
      <li>
        <a href="asia.htm">
          <span>Asia</span>
        </a>
      </li>
      <li>
        <a href="australia.htm">
          <span>Australia</span>
        </a>
      </li>
      <li>
        <a href="britisles.htm">
          <span>British Isles</span>
        </a>
      </li>
      <li>
        <a href="europe.htm">
          <span>Europe</span>
        </a>
      </li>
      <li>
        <a href="london.htm">
          <span>London</span>
        </a>
      </li>
      <li>
        <a href="morocco.htm">
          <span>Morocco</span>
        </a>
      </li>
    </ul>

  </aside>
  <section id="regions">
    <h4 style="text-align:left;">Asia</h4>
    <div class="thumbcontainer">
      <div class="thumb">
        <a href="india.htm">
          <img src="images/photo/tn/india.jpg" alt="India" width="310" height="207">
        </a>
        <h3>India</h3>
        <p>Country Description</p>
      </div>
      <div class="thumb">
        <a href="indonesia.htm">
          <img src="images/photo/tn/indonesia.jpg" alt="Indonesia" width="310" height="207">
        </a>
        <h3>Indonesia</h3>
        <p>Country Description</p>
      </div>
      <div class="thumb">
        <a href="malaysia.htm">
          <img src="images/photo/tn/malaysia.jpg" alt="Malaysia" width="310" height="207">
        </a>
        <h3>Malaysia</h3>
        <p>Country Description</p>
      </div>
      <div class="thumb">
        <a href="singapore.htm">
          <img src="images/photo/tn/singapore.jpg" alt="Singapore" width="310" height="207">
        </a>
        <h3>Singapore</h3>
        <p>Country Description</p>
      </div>
      <div class="thumb">
        <a href="thailand.htm">
          <img src="images/photo/tn/thailand.jpg" alt="Singapore" width="310" height="207">
        </a>
        <h3>Thailand</h3>
        <p>Country Description</p>
      </div>
    </div>
  </section>
</div>

和CSS:

.mainwrapper {
width: 90%;
margin: 130px auto 0;
text-align:center;
}

.mainwrapper h4 {
text-align:center;
padding-bottom: 5px;
color: #FFF;
border-bottom: 1px solid rgba(153,0,0,1);
font-size:16px;
font-weight:200;
letter-spacing: 2px;
text-transform:uppercase;
font-family:'Lucida Sans Unicode', 'Lucida Grande', sans-serif;
}

#locations {
background-color:rgba(26,26,26,0.8);
display:inline-block;
text-align:left;
width: 150px;
height:auto;
margin-top: 5px;
padding: 0 10px 0;
}

#locations ul {
list-style: none;
padding:0;
}

#locations li {
}

#locations li a {
text-align:left;
color:#FFF;
font-family:"Lucida Sans Unicode", "Lucida Grande", sans-serif;
font-size:12px;
font-weight:normal;
margin:0;
text-decoration:none;   
}



#regions {
background-color:rgba(26,26,26,0.8);
display:inline-block;
vertical-align:top;
width: 90%;
margin-left: 20px;
margin-top: 5px;
padding: 0 10px 0;
}

.thumbcontainer {
display:inline-block;
width:100%;
}

.thumb {
background-color:rgba(18,18,18,0.8);
border:1px solid rgba(0,0,0,1);
margin:10px 2px;
display:inline-block;
vertical-align:top;
width: 310px;
height:270px;
}

.thumb h3 {
color: #FFF;
border-bottom: 1px solid rgba(153,0,0,1);
font-size:14px;
font-weight:200;
letter-spacing: 2px;
text-transform:uppercase;
font-family:'Lucida Sans Unicode', 'Lucida Grande', sans-serif;
margin:0 8px 0;
}

.thumb p {
color:#FFF;
font-family:"Lucida Sans Unicode", "Lucida Grande", sans-serif;
font-size:11px;
text-align:left;
padding-left:8px;

}

.thumb img {
border:0;
}

请在这里重新找到链接

非常感谢您的帮助。

4

2 回答 2

1

尝试这个 ...

从 HEADER 中删除 position: fixed,从 #regions 中删除 width: 90% 并将 .mainwrapper CSS 声明替换为:

.mainwrapper {
    margin: 40px 2% 0;
    padding-left: 168px;
    position: relative;
    text-align: center;
}
于 2012-10-06T01:37:06.430 回答
0

正如您所说,您应该分别在您的 Locations 和 Regions 元素上使用float:leftfloat:right,以便它们处于同一级别。

我还会使用媒体查询来更改 Regions 元素的宽度,因为在 90% 的情况下,它并不总是能够将 Locations 元素放在左侧。我个人认为您应该摆脱 Regions 元素上的百分比宽度,并使用媒体查询有条件地设置它。

有关媒体查询的更多信息:这里

例如,您的 Regions 元素需要大约 636px 宽才能显示两张照片。所以你可以有一个媒体查询来允许这个宽度,加上你的边距宽度、填充和 Locations 元素宽度,你会有这样的东西:

@media (min-width: 956px) { 
#regions {
width: 636px;
}
}

它需要 956px 宽才能显示三个。所以你可以在它下面有另一个媒体查询,如下所示:

@media (min-width:1276px) { 
#regions {
width: 956px;
}
}

你可以包括max-width:955px来解释一切。您可以使用这样的媒体查询,以便在调整页面时,它将在一行中显示尽可能多的照片,并显示 Locations 元素。

看看我做的 JSFiddle,这里,作为一个例子。可能想在此处查看全屏版本,以了解更改浏览器窗口宽度时它是如何工作的。

于 2012-10-06T01:55:55.833 回答