【发布时间】:2018-06-20 05:19:49
【问题描述】:
所以请原谅我,我对 CSS 很陌生,这是我的第一个真正的项目,我遇到了一些问题,p 被我的第二个 img 的 float:left 元素略微偏离中心.
这是我的 HTML
<div>
<img id="fishnchips" src="image1.jpeg" alt="Fish n Chips">
<img id="chicken" src="Friedchickenredbasket.jpeg" alt="Chicken Basket">
</div>
<!--End of images-->
<div class="header-p">
<p>Coming Soon!</p>
</div>
</header>
<p><div id="address">123 Main St.</div></p>
我尝试将两个图像自己包装在一个 div 中,但没有成功。我尝试将img 放在.header-p 中。那也没用。
评论部分是我尝试过的另一个修复,但也没有奏效。这是我能够让顶部图像#fishnchips 位于左上角但在左边距有轻微填充的唯一方法,而它下方的图像#chicken 略低于顶部图像,也在左侧。我想要的是使段落居中,而不是让float:left 将其稍微偏离中心。
当我测试它时,如果我删除float:left,“即将推出!”并且地址都回到了正确的位置。但是我还没有找到float:left 的替代品,它可以使图像仅使用 css 保持在屏幕的左侧。
这是我的 CSS:
#fishnchips {
position: fixed;
top: 25px;
left: 25px;
right: 10px;
height: 20%;
float: left;
margin-left: 0px;
}
#chicken {
/* position: fixed;
top: 25px;
left: px;
right: 10px;
height: 40%;
float: left;
margin-left: 0px;*/
margin-top: 40px;
height: 10%;
width: 20%;
right: 0;
float: left;
clear: both;
display: inline-block;
}
.header-p {
font-family: 'Permanent Marker', cursive;
font-size: 50px;
text-align: center;
padding-top: .01 em;
}
#address {
color: #410101;
font-weight: 200;
font-size: 1.5em;
}
【问题讨论】: