首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在自己的div之外浮动/显示图像?

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

Stack Overflow用户
提问于 2018-12-26 17:56:41
回答 1查看 55关注 0票数 0

我希望我的徽标浮动在overflow:hidden div之外

这是我的HTML代码:

代码语言:javascript
复制
    .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*/
    }
代码语言:javascript
复制
   <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之外

EN

回答 1

Stack Overflow用户

发布于 2018-12-26 18:13:15

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

代码语言:javascript
复制
.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*/
}
代码语言:javascript
复制
<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>

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53930365

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档