当 div 向左浮动时,如何才能使 div 不会根据浏览器窗口大小或屏幕分辨率相互堆叠?

发布于 2024-07-29 07:46:16 字数 729 浏览 3 评论 0原文

抱歉,如果我的措辞……不清楚。 我真的不知道如何正确解释我的困境。 但是让我们看看我是否可以在这里做得更好......

我正在制作一个博客,其中帖子将水平显示和滚动,而不是垂直。 每篇博文都显示在一个单独的 div 中,并且这些 div 通过向左浮动的方式并排显示。

但根据计算机的分辨率或查看页面的窗口的大小,div 会堆叠在一起,而不是像我预期的那样并排显示。 当然,如果屏幕分辨率足够大,可以显示每个 div,效果会很好,但事实并非如此。

我感谢我能得到的任何帮助、提示和指示。 非常感谢。

编辑 就代码而言,这是我正在使用的基本 HTML 结构和 CSS:

<div class="post">Post Content</div>
<div class="post">Post Content</div>
<div class="post">Post Content</div>
<div class="post">Post Content</div>
<div class="post">Post Content</div>

.post {
     float: left;
     margin-top: 74px;
     margin-left: 50px;
     margin-right: 50px;
}

Sorry if my wording is... unclear. I really had no idea how to properly explain my dilemma. But lets seen if I can do it better here...

I am making a blog in which posts will be displayed and scrolled through horizontally, rather than vertically. Each blog post is displayed in a separate div, and the divs are displayed side by side by floating them to the left.

But based on the resolution of one's computer, or the size of the window one is viewing the page in, the divs will stack on top of one another instead of displaying side by side as I intended. Of course, if the screen resolution was large enough to display every div it would work wonderfully, but it's not.

I appreciate any help, tips, and pointers I can get. Thank you very much.

Edit
And as far as code goes, this is the basic HTML structure and CSS I am using:

<div class="post">Post Content</div>
<div class="post">Post Content</div>
<div class="post">Post Content</div>
<div class="post">Post Content</div>
<div class="post">Post Content</div>

.post {
     float: left;
     margin-top: 74px;
     margin-left: 50px;
     margin-right: 50px;
}

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

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

发布评论

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

评论(1

残疾 2024-08-05 07:46:16

您是否尝试过将 div 放入具有溢出:滚动的容器 div 中?

例如:

<div id="container" style="overflow:scroll; height: 100px; width: 500px;">
<div class="post"></div>
<div class="post"></div>
<div class="post"></div>
</div>

如果这不能回答您的问题,那么也许您可以向我们展示您现有的标记/CSS,以便我们可以准确地看到您想要实现的目标。

Have you tried putting your divs inside a container div with overflow:scroll?

For example:

<div id="container" style="overflow:scroll; height: 100px; width: 500px;">
<div class="post"></div>
<div class="post"></div>
<div class="post"></div>
</div>

If this doesn't answer your question, then perhaps you could show us your existing markup/CSS so we can see exactly what you're trying to achieve.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文