首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >text-align:居中不使用div元素

text-align:居中不使用div元素
EN

Stack Overflow用户
提问于 2013-06-19 04:08:56
回答 1查看 47.9K关注 0票数 8

我已经搜索了大约45分钟,在这里找不到我的问题的解决方案。我希望我的图库类div (它们将被动态创建)仅使用gallery_container规则在css div的中心对齐。我正在学习,所以任何解释都会有帮助!

提前感谢!

代码语言:javascript
复制
<head>
    <style>
    #gallery_container{
        text-align: center; 
        width:100%;
        overflow: auto; 
        background:orange;  
    }
    .gallery{
        text-align: left;   
        border-style: solid;
        border-width:3px;
        border-top-left-radius: 40px;
        border-bottom-right-radius: 40px; 
        background:yellow;
        width:335px;
        padding:20px;
        float:left;
        margin:15px;
    }
    .gallery h2{
        margin-top:0;
    }
    .gallery img{
        height:120px;
        width:160px;
        float:right;
    }
</style>

<body>
    <div id ='content_gallery'>
        <h2>Gallery</h2>

        <div id='gallery_container'>
            <div class = gallery>
                <img src = 'bowling_01.png'>
                <h2>Company bowling</h2>
                <h4>Date: June 14, 2013</h4>
                <p>The company heads to Boca Bowl for our monthly bowling event!</p>
            </div>

            <div class = gallery>
                <img src = 'bowling_01.png'>
                <h2>Company bowling</h2>
                <h4>Date: June 14, 2013</h4>
                <p>The company heads to Boca Bowl for our monthly bowling event!</p>
            </div>

            <div class = gallery>
                <img src = 'bowling_01.png'>
                <h2>Company bowling</h2>
                <h4>Date: June 14, 2013</h4>
                <p>The company heads to Boca Bowl for our monthly bowling event!</p>
            </div>
        </div>
    </div>
</body>

这里是小提琴http://jsfiddle.net/9gwKc/1/

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-06-19 21:33:51

这可以通过使用inline-block显示器来完成,float:left将始终将元素发送到尽可能靠左的位置。

代码语言:javascript
复制
.gallery {
   text-align: left;   
   border-style: solid;
   border-width:3px;
   border-top-left-radius: 40px;
   border-bottom-right-radius: 40px; 
   background:yellow;
   width:335px;
   padding:20px;
   /*float:left; remove this*/
   margin:15px;

   /*add this*/ 
   display:inline-block;
   position:relative;
}
票数 15
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17177950

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档