无论用户的屏幕尺寸如何,如何使用固定菜单覆盖整个页面宽度?

发布于 2024-12-20 23:57:43 字数 714 浏览 0 评论 0原文

我对固定且位于页面中央的菜单有疑问。我希望整个菜单(3 个背景图像)覆盖整个页面宽度,无论用户的屏幕尺寸是什么。

原图:(

图1:宽1px,高76px;)
(图2:宽1135px,高76px;)
(图3:宽度1px,高度76px;)

CSS更改后我希望这些变成:(

图1:宽度392,5px,高度76px;)
(图2:宽1135px,高76px;)
(图3:宽度392,5px,高度76px;)

<div style="position:fixed; width:100%; height:76px;">
  <div> Picture 1 </div>  <!-- repeat-x on the left side -->
  <div> Picture 2 , center of the page , no-repeat</div>
  <div> Picture 3</div>  <!--  repeat-x on the right side -->
</div>

我想在图1和图3上设置repeat-x,但不知道宽度。我可以用 jQuery 修复它,但 CSS 中没有办法吗?

I have a problem with a menu that is fixed and centered on the page. I want the entire menu (3 background images) to cover the entire page width, regardless what the screen size user have.

Orginal pictures:

(Picture 1: width 1px, height 76px;)
(Picture 2: width 1135px, height 76px;)
(Picture 3: width 1px, height 76px;)

After CSS changes I want those to become:

(Picture 1: width 392,5px, height 76px;)
(Picture 2: width 1135px,  height 76px;)
(Picture 3: width 392,5px, height 76px;)

<div style="position:fixed; width:100%; height:76px;">
  <div> Picture 1 </div>  <!-- repeat-x on the left side -->
  <div> Picture 2 , center of the page , no-repeat</div>
  <div> Picture 3</div>  <!--  repeat-x on the right side -->
</div>

I want to set the repeat-x on picture 1 and 3, but don't know the width. I can fix it with jQuery but aren't there a way in CSS?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

超可爱的懒熊 2024-12-27 23:57:43

更新了透明中心图像请参阅,http://jsfiddle.net/QEPX4/ 5/show/

HTML

<div class="TriHeader">
  <div class="left"><div></div></div>
  <div class="center"></div>
  <div class="right"><div></div></div>
</div>

CSS(代表)

.TriHeader {
    position:fixed;
    width:100%;
    height:76px;
}

.TriHeader div {
    height: 76px;
    position: absolute;
}

.TriHeader .left {
    left: 0;
    right: 50%;
    z-index: 0;
}

.TriHeader .left div {
    background: url(repeatingLeftImage.png) top left repeat-x;
    right: 567.5px;
    left: 0;
    top: 0;
}

.TriHeader .center {
    background: url(nonrepeatingCenterImage.png) top left no-repeat;
    width: 1135px;
    left: 50%;
    margin-left: -567.5px; /*ideally, the image would be an even number */
    z-index: 1;
}

.TriHeader .right {
    left: 50%;
    right: 0;
    z-index: 0;
}

.TriHeader .right div {
    background: url(repeatingRightImage.png) top left repeat-x;
    left: 567.5px;
    right: 0;
    top: 0;
}

如果你不关心IE7,那么你可以去掉左右两侧嵌套的div元素,将css替换为伪元素选择器如:

.TriHeader .right:before {
    content: '';
    display: block;
    position: absolute;
    background: url(repeatingRightImage.png) top left repeat-x;
    left: 567.5px;
    right: 0;
    top: 0;
}

Updated for transparent center image See, http://jsfiddle.net/QEPX4/5/show/

HTML

<div class="TriHeader">
  <div class="left"><div></div></div>
  <div class="center"></div>
  <div class="right"><div></div></div>
</div>

CSS (representative)

.TriHeader {
    position:fixed;
    width:100%;
    height:76px;
}

.TriHeader div {
    height: 76px;
    position: absolute;
}

.TriHeader .left {
    left: 0;
    right: 50%;
    z-index: 0;
}

.TriHeader .left div {
    background: url(repeatingLeftImage.png) top left repeat-x;
    right: 567.5px;
    left: 0;
    top: 0;
}

.TriHeader .center {
    background: url(nonrepeatingCenterImage.png) top left no-repeat;
    width: 1135px;
    left: 50%;
    margin-left: -567.5px; /*ideally, the image would be an even number */
    z-index: 1;
}

.TriHeader .right {
    left: 50%;
    right: 0;
    z-index: 0;
}

.TriHeader .right div {
    background: url(repeatingRightImage.png) top left repeat-x;
    left: 567.5px;
    right: 0;
    top: 0;
}

If you don't care about IE7, then you can eliminate the nested div elements in the left and right sides and replace the css with pseudo element selectors like:

.TriHeader .right:before {
    content: '';
    display: block;
    position: absolute;
    background: url(repeatingRightImage.png) top left repeat-x;
    left: 567.5px;
    right: 0;
    top: 0;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文