简体   繁体   English

CSS在div上自动向左浮动?

[英]CSS float left with margin auto on div?

hello friends can i set float:left with the margin:auto 你好朋友可以设置float:left margin:auto

this is my html code 这是我的HTML代码

<div class='gallary'>
      <div>1</div>
      <div>2</div>
      <div>3</div>
      <div>4</div>
</div>

my css code this is not working. 我的css代码不起作用。

.gallary{
     width:100%;
 }
 .gallary div{
       float:left;
       margin:0 auto;
  }

please help. 请帮忙。 Thank you. 谢谢。

just use inline-block instead of float 只使用内联块而不是浮点数

.gallary div {
    display: inline-block;
    margin: 0 auto;
}

try this is very help fully. 试试这是非常有帮助的。 i hop this is used full for you. 我跳这是用来满满的。

.gallary{
 width:100%;
 }

.gallary div{
       vertical-align:top;
       display:inline-block;
       margin:0 auto;
}

Try using display: inline-block; 尝试使用display: inline-block; to maintain the divs at the same line and text-align:center; 保持div在同一行和text-align:center; do align to the center: 与中心对齐:

Here's the fix: http://jsfiddle.net/4xxvb/3/ 这是修复: http//jsfiddle.net/4xxvb/3/

I tested it and got it working, all you have to do is: 我测试了它并使其正常工作,您所要做的就是:

.gallary{
    width: 100%;
    text-align: Center;
}
.gallary div{
    display: Inline-block;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM