[英]CSS - Firefox and IE browsers doesn't take the given fixed width
Okay, so I am trying to align 5 list items in a row of width 980px.Each of the 5 list items have an anchor tag in them.The anchor tags have a fixed width of 184px and there is 15px padding between two list items.But it is working only in Chrome and Safari. 好吧,所以我试图将980个行中的5个列表项对齐.5个列表项中的每个都有一个anchor标签.anchor标签的宽度固定为184px,两个列表项之间有15px的填充。但它仅在Chrome和Safari中有效。 The width in Firefox and IE browsers are showing up as 186px though I have given the fixed width.
Firefox和IE浏览器的宽度显示为186px,尽管我给出了固定宽度。 So,the last list item is coming in to a second row which is not what I wanted.
因此,最后一个列表项进入第二行,这不是我想要的。
li {
list-style: none;
float: left;
content-align: center;
padding-right: 15px;
display: table-cell;
a{
width: 184px;
height: 230px;
span{
padding-top: 161px;
padding-right: 8px;
padding-left: 8px;
}
}
a:hover {
text-decoration: none;
}
}
li:last-child{
padding-right:0;
}
Can't understand why this is working only for two browswers 无法理解为什么这仅适用于两个浏览器
That is because <a>
tag is inline by default and cannot accept height or width properties, you have to make it a block
. 这是因为
<a>
标记默认是内联的,并且不能接受height或width属性,因此必须将其设置为block
。
Also why are you using display: table-cell
for the li
s? 另外,为什么还要使用
display: table-cell
li
的display: table-cell
?
This code should work (SCSS): 此代码应该可以使用(SCSS):
ul {
width: 980px;
background:red;
list-style: none;
margin: 0;
padding: 0;
}
li {
float: left;
display: block;
padding-right: 15px;
background: blue;
&:last-child {
padding-right: 0;
}
a {
width: 184px;
height: 230px;
color: #FFF;
display: block;
span {
padding-top: 161px;
padding-right: 8px;
padding-left: 8px;
}
&:hover {
text-decoration: none;
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.