【发布时间】:2016-07-24 04:48:25
【问题描述】:
这似乎是一个非常标准的情况,但 HTML/CSS 的行为很奇怪。我正在为游戏构建个人资料页面,并且还在研究移动响应能力。我似乎无法获得离开的权利。在竖屏模式下(使用 Chrome 移动模拟器扩展)没有问题,但在横屏模式下,div + margin 太宽并出现滚动条。
HTML:
<div class="userProfile" style="display:none">
<div class="profileTop">
<div class="profilePicture">
<img src="somepicture.png"></img>
</div>
<div class="profileName"></div>
</div>
</div>
CSS:
.profileTop {
position: relative;
top: 10%;
left: 15%;
width: 70%;
height: 12%;
margin: 0;
}
.profilePicture {
display: inline-block;
width: 12vw;
}
.profilePicture img {
width: 100%;
height: auto;
vertical-align: top;
}
.profileName {
display: inline-block;
position: relative;
font-family:Stencil;
font-size: 1.3em ;
font-weight: lighter;
color: white;
left: 20%;
top: 35%;
}
奇怪的是,如果我减小“profileTop”类的宽度,右边距会增加,所以整个东西的宽度都是一样的。有什么帮助吗?
编辑:我可以通过减少“userProfile”的宽度来获得一个可行的解决方案,但它仍然困扰着我,这将无法按最初的预期工作。
EDITx2:边距也存在于“userProfile”div 中。我想“profileTop” div 以某种方式跟随其父级,但即使我向两个 div 添加 margin-right: 0 属性,边距仍然存在。 "userProfile" 的父级是 body。
【问题讨论】:
-
旁注,图像是自动关闭的,所以
<img src="somepicture.png"></img>应该只是<img src="somepicture.png" />或<img src="somepicture.png"> -
可以加个codepen demo吗?