gpt4 book ai didi

html - 如何在页面中包含和居中宽泛的 html 内容?

转载 作者:行者123 更新时间:2023-11-28 04:58:59 25 4
gpt4 key购买 nike

我在页面中动态包含一个 html 内容。
内容是html中的树状结构,通常高度和宽度都很大。
我希望在包含 AJAX 后树的根节点可见:包含的 HTML 内容居中。

UPDATE1:在 MWE 中,我只是使用 width:2000px 来模拟​​比屏幕页面更宽的内容。重点是将这个巨大的东西放在页面的中央而不是改变它的宽度(缩放是可以接受的,但是如何?)。

UPDATE2:包含的树的根应该水平居中,但它的其他部分也需要通过浏览器的滚动条或一些内部滚动条可用。

通过样式化实现它的简单和正确的方法是什么(没有框架,因为它们已被弃用)?

UPDATE3:下面是一个真实示例的屏幕截图。树生成并动态包含在页面底部后,客户端不可见。需要使用滚动条才能看到树的根。

UPDATE4:查看一个可能的选项,其中包含的内容放置在带有滚动条的窗口中,需要通过浏览器或其他功能进行缩放。

enter image description here

enter image description here

MWE: https://jsfiddle.net/kowalsky/tgkbn8wp/2/

HTML:

<body>
<h1>Test page</h1>
<div>
So here comes a long text that might fill the page and wrap outomatically like this.
Below is a WIDETHING which is supposed to content an HTML loaded dynamically via AJAX.
The loaded content is usually wider and is impossible to fit to the page.
<b>What are the ways to put WIDETHING centered on the page, i.e. CENTER is in the center of the page?</b>
</div>

<div class="frame">
<div class="wideThing">
CENTER
<div class="box">BOX1</div>
<span class="box">BOX2</span>
<span class="box">BOX3</span>
<span class="box">BOX4</span>
<div class="box">BOX5</div>
</div>
</div>
</body>

CSS:

.wideThing {
width: 2000px;
text-align: center;
}

.frame {
width: 100%;
border: solid 2px black;
}

.box {
padding: 40px 100px;
border: solid 1px black;
background-color: red;
}

最佳答案

我会用这个:

.wideThing {
position: relative;
width: 2000px;
left: 50%;
transform: translateX(-50%);
text-align: center;
}

首先将左边框移动到中间,然后将其向左移动其自身宽度的 50%,从而使其水平居中。

https://jsfiddle.net/p7d2j323/1/

关于html - 如何在页面中包含和居中宽泛的 html 内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40217268/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com