[英]How do I align a div background with the bottom of its contents
I have a background I want to use that contrasts nicely with my content, except for the bottom 25% or so of the image. 我有一个我想要使用的背景,与我的内容形成鲜明对比,除了图像的底部25%左右。 How can I align that 25% position with either the bottom of the content, or a set distance from the bottom of the div? 如何将25%的位置与内容的底部或div底部的设定距离对齐? The height of the content varies with page width, and the background has size cover 内容的高度随页面宽度而变化,并且背景具有大小覆盖
HTML HTML
<div class="firstPanel">content here</div>
CSS CSS
.firstPanel {
background-image: URL("path-to-background");
background-position: 50% 70%;
background-repeat: no-repeat;
background-size: cover;
width: 100%;
padding: 20px;
padding-bottom: 100px;
}
From what I understood in your question,in the CSS you would add this : 据我对您的问题的理解,在CSS中,您应该添加以下内容:
margin-bottom:25%;
This specifies a margin in percent of the width of the containing element. 这指定了包含元素宽度百分比的边距。
Use this in css file 在css文件中使用它
*{
margin: 0;
padding: 0;
}
It clears all the unavoidable space from page. 它清除页面上所有不可避免的空间。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.