在CSS中居中,当对象大于视口时

编程入门 行业动态 更新时间:2024-10-25 12:16:26
本文介绍了在CSS中居中,当对象大于视口时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想让一个jquery的旋转木马在屏幕上居中,即使剪辑区域比视口更宽。这将基本上总是给元素一个负左边距 - 我该如何指定?剪切区域是固定宽度,但是当然视口区域是可变的。

I'm trying to get a jquery carousel centered on the screen, even when the clipping area is wider than the viewport. This will basically always give the element a negative left margin -- how can I specify this? The clipping area is a fixed width but of course the viewport area is variable.

推荐答案

这是最好的解决方案找到在您的固定宽度内容周围使用一个包装元素,然后内容本身的-50%的margin。这是我的头顶,但它应该足以让你开始。这是代码片段:

Here's the best solution I've been able to find uses a wrapping element around your-fixed-width content, then a -50% margin on the content itself. This is off the top of my head, but it should be enough to get you started. Here's the code snippet:

div.wrapper { position: absolute; left: 50%; } .content { position: relative; margin-left: -50%; } <div class="wrapper"> <div class="content">JQUERY BIZ-NASS HERE</div> </div>

当然,这里假设你的div是 body 标记,并且您的浏览器指定 body 的宽度为100%,没有边距或填充。

Of course, this assumes that your div here is a direct descendant of the body tag, and that your browser specifies body to have a width of 100% and no margin or padding.

更多推荐

在CSS中居中,当对象大于视口时

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

发布评论

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

>www.elefans.com

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