负 margin-top 与浮动组合不能按预期工作(仅在 Firefox 中)
我想尝试创建此屏幕,但右侧的文本字段移至上方。
这是一个 工作示例这是我的代码:
HTML:
<div class="TileMenu">
<div class="TileRow">
<div class="LeftTile">
<div class="TileImage">
<img src="http://page.mi.fu-berlin.de/krudolph/stuff/stackoverflow.png" title="Castle" alt="Castle" />
</div>
<div class="TileText">
<p>Text1</p>
</div>
</div>
<div class="RightTile">
<div class="TileImage">
<img src="http://page.mi.fu-berlin.de/krudolph/stuff/stackoverflow.png" title="House" alt="House" />
</div>
<div class="TileText">
<p>Text 2</p>
</div>
</div>
</div>
<div class="TileRow">
<div class="LeftTile">
<div class="TileImage">
<img src="http://page.mi.fu-berlin.de/krudolph/stuff/stackoverflow.png" title="Satellite" alt="Satellite" />
</div>
<div class="TileText">
<p>Text 3</p>
</div>
</div>
<div class="RightTile">
<div class="TileImage">
<img src="http://page.mi.fu-berlin.de/krudolph/stuff/stackoverflow.png" title="Palace" alt="Palace" />
</div>
<div class="TileText">
<p>Text 4</p>
</div>
</div>
</div>
</div>
CSS:
.TileRow{
padding: 5px 0px;
clear: both;
}
.LeftTile{
width: 49.7%;
float: left;
/*height: 340px;
overflow: hidden;*/
}
.LeftTile img{
width: 100%;
}
.RightTile{
width: 49.7%;
float: right;
/*height: 340px;
overflow: hidden;*/
}
.RightTile img{
width: 100%;
float: right;
}
.TileImage{
width: 49.7%;
}
.TileText{
position: relative;
margin-top: -80px;
max-width: 150px;
height: 50px;
background-color: #FFF;
color: #57abe9;
padding-left: 10px;
display: table;
}
.TileText p{
display: table-cell;
vertical-align: middle;
font-size: 1.3em;
}
在我尝试使用top:-80px;
之前但比我有一个大白每行之间有空格(由于文本字段)。所以现在我使用 margin-top: -80px;
但这似乎只适用于 Firefox。
I want try to create this screen, but text fields on the right side are shifted above.
Here is a working example and here is my code:
HTML:
<div class="TileMenu">
<div class="TileRow">
<div class="LeftTile">
<div class="TileImage">
<img src="http://page.mi.fu-berlin.de/krudolph/stuff/stackoverflow.png" title="Castle" alt="Castle" />
</div>
<div class="TileText">
<p>Text1</p>
</div>
</div>
<div class="RightTile">
<div class="TileImage">
<img src="http://page.mi.fu-berlin.de/krudolph/stuff/stackoverflow.png" title="House" alt="House" />
</div>
<div class="TileText">
<p>Text 2</p>
</div>
</div>
</div>
<div class="TileRow">
<div class="LeftTile">
<div class="TileImage">
<img src="http://page.mi.fu-berlin.de/krudolph/stuff/stackoverflow.png" title="Satellite" alt="Satellite" />
</div>
<div class="TileText">
<p>Text 3</p>
</div>
</div>
<div class="RightTile">
<div class="TileImage">
<img src="http://page.mi.fu-berlin.de/krudolph/stuff/stackoverflow.png" title="Palace" alt="Palace" />
</div>
<div class="TileText">
<p>Text 4</p>
</div>
</div>
</div>
</div>
CSS:
.TileRow{
padding: 5px 0px;
clear: both;
}
.LeftTile{
width: 49.7%;
float: left;
/*height: 340px;
overflow: hidden;*/
}
.LeftTile img{
width: 100%;
}
.RightTile{
width: 49.7%;
float: right;
/*height: 340px;
overflow: hidden;*/
}
.RightTile img{
width: 100%;
float: right;
}
.TileImage{
width: 49.7%;
}
.TileText{
position: relative;
margin-top: -80px;
max-width: 150px;
height: 50px;
background-color: #FFF;
color: #57abe9;
padding-left: 10px;
display: table;
}
.TileText p{
display: table-cell;
vertical-align: middle;
font-size: 1.3em;
}
Before I tried to use top:-80px;
but than I got a big white space between each row (because of the text field). So now I'm using margin-top: -80px;
but this seems only to work in Firefox.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
位置:绝对怎么样?
http://jsfiddle.net/KjakS/8/
How about position: absolute?
http://jsfiddle.net/KjakS/8/
如果在 RightTile 类中删除图像上的
float:right
会怎样?像这样的东西: http://jsfiddle.net/KjakS/7/.RightTile图像{
宽度:100%;
}
What if you remove the
float:right
on the image in the RightTile class? To something like this: http://jsfiddle.net/KjakS/7/.RightTile img{
width: 100%;
}