CSS 3柱液体布局,带固定中心柱

编程入门 行业动态 更新时间:2024-10-27 00:35:11
本文介绍了CSS 3柱液体布局,带固定中心柱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想为我的营销网站制作一个在顶部横幅中包含图片的3列布局。

I want to make for my marketing site a 3 column layout that has images in the top banner.

我想有一个固定中心的液体左/右侧。 html最好看起来像这样:

I want to have a liquid left/right side with a fixed center. The html would ideally look like this:

<div id="pixelLeft">&nbsp;</div> <div id="bannerCenter"> <img src="images/mybanner.png" /> </div> <div id="pixelRight">&nbsp;</div> <style> #pixelLeft { background: url(../../images/pixel_left_fixed.png) 0 0 repeat-x; } #pixelRight { background: url(../../images/pixel_right_fixed.png) 0 0 repeat-x; } #bannerCenter { /* something here to make fixed width of 1550px */ } </style>

左/右像素边的图像为1px x 460px。 图片mybanner.png是1550像素×460像素。

The images in the left/right pixel sides are 1px x 460px. The image mybanner.png is 1550px x 460px.

提前感谢!

推荐答案

这对您有帮助吗?

仅CSS演示

jQuery演示(兼容跨浏览器)

<div class="wrap"> <div id="pixelLeft">&nbsp;</div> <div id="bannerCenter"> <img src="images/mybanner.png" /> </div> <div id="pixelRight">&nbsp;</div> </div> <div style="clear:both;"></div> *{ margin:0; padding:0; } #bannerCenter{ background:#ddd; width: 500px; float:left; } #pixelLeft{ background:#999; width: calc(50% - 250px); float:left; } #pixelRight{ background:#999; width: calc(50% - 250px); float:right; } #bannerCenter,#pixelLeft,#pixelRight{ height: 400px; }

您可以使用jQuery而不是使用 calc

You can use jQuery instead of using calc(50% - 250px); to make it compatible for older browsers.

$(document).ready(function() { $(window).on('resize', function() { $('#pixelLeft, #pixelRight').css('width',($('body').width()-$('#bannerCenter').width())/2); }).trigger('resize'); });

更多推荐

CSS 3柱液体布局,带固定中心柱

本文发布于:2023-11-06 16:05:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1564159.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:液体   布局   中心   CSS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!