多个 div 居中对齐,左对齐,彼此相邻

发布于 2024-12-23 22:20:44 字数 3864 浏览 2 评论 0原文

我试图让多个 div 坐在一起,居中。当窗口变得太小而无法容纳一行中的所有 div 时,我希望溢出的 div 向下移动到下一行。最好左对齐但仍居中。

如果这是不可能的,我也很乐意让它们居中对齐。

我希望它如何发挥作用的一个例子是本页底部的大拇指 http:// /www.klossal.com/portfolio/index2.html

我遇到问题的当前页面位于此处 http://www.klossal.com/portfolio/test.html

这是我当前的代码:

<div
    align="center"
    style="
        clear:both;
        margin-left:auto;
        margin-right:auto;
        width: 100%;
        visibility: show;"> 


    <div style="height:330px;width:330px;float:left;">
        <div style="left:0px;width:330px;">
            <a class="lib" href="#">
                <img         src="http://www.klossal.com/portfolio/library/space/space_lib.png" />
            </a>
        </div>
        <div style="width:300px;left:0px;">
            <p class="ex2" align="left">Made in Photoshop</p>
            <img src="/media/divider.png" width="100%" height="5px" border="0"  style="opacity:0.0;filter:alpha(opacity=0)" />
            <p class="ex3" align="left">Photoshop created space environments made as concept backgrounds for several character drawings</p>
        </div>
    </div>

    <div style="height:330px;width:330px;float:left;">
        <div style="left:0px;width:330px;">
            <a class="lib" href="#">
                <img src="http://www.klossal.com/portfolio/library/glow/glow_lib.png" />
            </a>
        </div>
        <div style="width:300px;left:0px;">
            <p class="ex2" align="left">Made in Photoshop</p>
            <img src="/media/divider.png" width="100%" height="5px" border="0"  style="opacity:0.0;filter:alpha(opacity=0)" />
            <p class="ex3" align="left">Photoshop created space environments made as concept backgrounds for several character drawings</p>
        </div>
    </div>

    <div style="height:330px;width:330px;float:left;">
        <div style="left:0px;width:330px;">
            <a class="lib" href="#">
                <img    src="http://www.klossal.com/portfolio/library/faces/faces_lib.png" />
            </a>
        </div>
        <div style="width:300px;left:0px;">
            <p class="ex2" align="left">Made in Photoshop</p>
            <img src="/media/divider.png" width="100%" height="5px" border="0" style="opacity:0.0;filter:alpha(opacity=0)" />
            <p class="ex3" align="left">Photoshop created space environments made as concept backgrounds for several character drawings</p>
        </div>
    </div>

    <div style="height:330px;width:330px;float:left;">
        <div style="left:0px;width:330px;">
            <a class="lib" href="#">
                <img src="http://www.klossal.com/portfolio/library/color/color_lib.png" />
            </a>
        </div>
        <div style="width:300px;left:0px;">
            <p class="ex2" align="left">Made in Photoshop</p>
            <img src="/media/divider.png" width="100%" height="5px" border="0" style="opacity:0.0;filter:alpha(opacity=0)" />
            <p class="ex3" align="left">Photoshop created space environments made as concept backgrounds for several character drawings</p>
            <img src="/media/divider.png" width="100%" height="5px" border="0" style="opacity:0.0;filter:alpha(opacity=0)" />
        </div>
    </div>

    <img src="/media/divider.png" width="100%" height="52px" border="0" style="opacity:0.0;filter:alpha(opacity=0)" />
</div>

I'm trying to get multiple divs sitting next to each other, centered. When the window gets too small to fit all the divs in one row I would like the overflowing divs to bump down to the next row. Preferably aligned left but still centered.

If this isn't possible I'd also be happy to have them just be centered aligned.

An example of how I would like this to function is the large thumbs at the bottom of this page http://www.klossal.com/portfolio/index2.html

The current page I'm having trouble with is here http://www.klossal.com/portfolio/test.html

Here is my current code:

<div
    align="center"
    style="
        clear:both;
        margin-left:auto;
        margin-right:auto;
        width: 100%;
        visibility: show;"> 


    <div style="height:330px;width:330px;float:left;">
        <div style="left:0px;width:330px;">
            <a class="lib" href="#">
                <img         src="http://www.klossal.com/portfolio/library/space/space_lib.png" />
            </a>
        </div>
        <div style="width:300px;left:0px;">
            <p class="ex2" align="left">Made in Photoshop</p>
            <img src="/media/divider.png" width="100%" height="5px" border="0"  style="opacity:0.0;filter:alpha(opacity=0)" />
            <p class="ex3" align="left">Photoshop created space environments made as concept backgrounds for several character drawings</p>
        </div>
    </div>

    <div style="height:330px;width:330px;float:left;">
        <div style="left:0px;width:330px;">
            <a class="lib" href="#">
                <img src="http://www.klossal.com/portfolio/library/glow/glow_lib.png" />
            </a>
        </div>
        <div style="width:300px;left:0px;">
            <p class="ex2" align="left">Made in Photoshop</p>
            <img src="/media/divider.png" width="100%" height="5px" border="0"  style="opacity:0.0;filter:alpha(opacity=0)" />
            <p class="ex3" align="left">Photoshop created space environments made as concept backgrounds for several character drawings</p>
        </div>
    </div>

    <div style="height:330px;width:330px;float:left;">
        <div style="left:0px;width:330px;">
            <a class="lib" href="#">
                <img    src="http://www.klossal.com/portfolio/library/faces/faces_lib.png" />
            </a>
        </div>
        <div style="width:300px;left:0px;">
            <p class="ex2" align="left">Made in Photoshop</p>
            <img src="/media/divider.png" width="100%" height="5px" border="0" style="opacity:0.0;filter:alpha(opacity=0)" />
            <p class="ex3" align="left">Photoshop created space environments made as concept backgrounds for several character drawings</p>
        </div>
    </div>

    <div style="height:330px;width:330px;float:left;">
        <div style="left:0px;width:330px;">
            <a class="lib" href="#">
                <img src="http://www.klossal.com/portfolio/library/color/color_lib.png" />
            </a>
        </div>
        <div style="width:300px;left:0px;">
            <p class="ex2" align="left">Made in Photoshop</p>
            <img src="/media/divider.png" width="100%" height="5px" border="0" style="opacity:0.0;filter:alpha(opacity=0)" />
            <p class="ex3" align="left">Photoshop created space environments made as concept backgrounds for several character drawings</p>
            <img src="/media/divider.png" width="100%" height="5px" border="0" style="opacity:0.0;filter:alpha(opacity=0)" />
        </div>
    </div>

    <img src="/media/divider.png" width="100%" height="52px" border="0" style="opacity:0.0;filter:alpha(opacity=0)" />
</div>

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

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

发布评论

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

评论(1

两个我 2024-12-30 22:20:44

如果我错了,请纠正我,但你的意思是:

<div class="container">
    <div class="img">
        <a href="#">
            <img src="http://www.klossal.com/portfolio/library/space/space_lib.png" />
            <p>Picture one..</p>
        </a>
    </div>
    <div class="img">
        <a href="#">
            <img src="http://www.klossal.com/portfolio/library/glow/glow_lib.png" />
            <p>Picture two..</p>
        </a>
    </div>
    <div class="img">
        <a href="#">
            <img src="http://www.klossal.com/portfolio/library/faces/faces_lib.png" />
            <p>Picture three..</p>
        </a>
    </div>
    <div class="img">
        <a href="#">
            <img src="http://www.klossal.com/portfolio/library/color/color_lib.png" />
            <p>Picture four..</p>
        </a>
    </div>
</div>

我认为?

检查 JSFiddle 此处...

Correct me if I'm wrong but you mean something like:

<div class="container">
    <div class="img">
        <a href="#">
            <img src="http://www.klossal.com/portfolio/library/space/space_lib.png" />
            <p>Picture one..</p>
        </a>
    </div>
    <div class="img">
        <a href="#">
            <img src="http://www.klossal.com/portfolio/library/glow/glow_lib.png" />
            <p>Picture two..</p>
        </a>
    </div>
    <div class="img">
        <a href="#">
            <img src="http://www.klossal.com/portfolio/library/faces/faces_lib.png" />
            <p>Picture three..</p>
        </a>
    </div>
    <div class="img">
        <a href="#">
            <img src="http://www.klossal.com/portfolio/library/color/color_lib.png" />
            <p>Picture four..</p>
        </a>
    </div>
</div>

I think?

Check the JSFiddle here...

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