如何在自己的 div 之外浮动/显示图像



我希望我的徽标漂浮在overflow:hidden

div之外

这是我的 HTML 代码:

    .login-card{
        width: 280px;
        background: rgb(255,250,250,0.6);
        margin-left: 45px;
        border-radius: 2px;
        box-shadow: 0 2px 2px rgba(0,0,0,.3);
        overflow: hidden;
    }
    .login-card img{
        width:70%;
        height:70%;
        margin-top: -25px;
        background-color: crimson; /*this is just to cover up the image*/
    }
   <div class="login-card">
        <img src="captiveportal-logo.png"/>
        <form name="login_form" method="">
            <input type="text">
            <input type="password">
            <input type="submit">
        </form>				
 </div>

我真的希望它半漂浮在它的div

我认为您需要另一个额外的外部容器来解决此问题。看看片段。在这种情况下,您应该了解图像大小,因为它现在从设置position: relative;的外部div 继承大小

.outside {
	position:relative;
}
.login-card{
	width: 280px;
	background: rgb(255,250,250,0.6);
	margin-left: 45px;
	border-radius: 2px;
	box-shadow: 0 2px 2px rgba(0,0,0,.3);
	overflow: hidden;
}
.login-card img{
	width:100px;
	height:100px;
	position:absolute;
	left:0;
	top:-25px;
	background-color: crimson; /*this is just to cover up the image*/
}
<div class="outside">
<div class="login-card">
        <img src="https://via.placeholder.com/100.png/09f/fff"/>
        <form name="login_form" method="">
            <input type="text">
            <input type="password">
            <input type="submit">
        </form>
        <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
 </div>
</div>

最新更新