多个 div 居中对齐,左对齐,彼此相邻
我试图让多个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我错了,请纠正我,但你的意思是:
我认为?
检查 JSFiddle 此处...
Correct me if I'm wrong but you mean something like:
I think?
Check the JSFiddle here...