2017-05-06 49 views
0

后堆放在对方我有按钮具有这些属性:CSS - <a>元调整

background: #c6cdf2; 
border: 1px solid #8896e4; 
border-radius: 3px; 
padding: 6px 10px 3px 10px; 

一旦页面重新调整他们似乎并不关心填充,并开始相互叠加。

enter image description here

enter image description here

有没有一种方法来计算automaticaly边界之间的适当距离呢?我不想设置一个固定的保证金数量来遇到这个问题。

+0

Flex属性仅支持IE10和IE11,因此可以更好地使用媒体查询。请参阅我的文章。 – Ehsan

回答

1

您可以使用flexbox。不需要媒体查询或额外的代码。简化它。

div { 
 
    display: flex; 
 
    flex-wrap: wrap; 
 
} 
 

 
a { 
 
    background: #c6cdf2; 
 
    border: 1px solid #8896e4; 
 
    border-radius: 3px; 
 
    padding: 6px 10px 3px; 
 
    margin: 10px /* whatever you want here */ 
 
}
<div> 
 
    <a href="#">long long long text</a> 
 
    <a href="#">long long text demo</a> 
 
    <a href="#">short text</a> 
 
</div>

+0

Flex属性仅支持IE10和IE11。 – Ehsan

+1

@ehsan所以? EDGE已经在版本15中 – dippas

1

Flex属性不支持IE9,IE8等更好地使用媒体查询。

@media screen and (max-width: 380px) { 

      .yourSelector { 

      display: block; 
      width: 100%; 

      } 
    } 

和接入margin:0.5%box-sizing: border-box

全码:

.b { 
 

 
    background: #c6cdf2; 
 
    border: 1px solid #8896e4; 
 
    border-radius: 3px; 
 
    padding: 6px 10px 3px 10px; 
 
    margin: 0.5%; 
 
    box-sizing: border-box; 
 
} 
 

 
@media screen and (max-width: 380px) { 
 

 
     .b { 
 
      
 
      display: block; 
 
      width: 100%; 
 
      } 
 

 
}
<a href="#" class="b">Button1 </button> 
 
<a href="#" class="b">Button2 </button> 
 
<a href="#" class="b">Button3 </button> 
 
<a href="#" class="b">Button4 </button> 
 
<a href="#" class="b">Button5 </button>

1

您可以尝试将两个样式属性:

float: left; clear: both;

希望这将有助于。

1

的问题是,您的元素是内联(显示:内联),所以你可以用line-height属性垫衬,或使他们的块,或内联块使用垫衬