Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
199 views
in Technique[技术] by (71.8m points)

html - Force Item To Bottom Of Page Except for Margin

I have a really simple question: How do I force a div to have the largest height it can, while keeping some padding on the bottom. Normaly, I would use:

min-height: 100%;

However this completely removes any margin at the bottom of the div (The div always reaches ALL the way to the bottom). I need a small amount of margin at the bottom, however no amount margin-bottom will change that. I could make the min-height something like 90%, but I really want the margin bottom to be a fixed value (15px). Is there any way to do this?

question from:https://stackoverflow.com/questions/66047906/force-item-to-bottom-of-page-except-for-margin

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can use calc(100% - [margin-bottom]) like so:

div{
  background-color:red;
  min-height:calc(100% - 5em);
  margin-bottom:5em;
}
html, body{
  height:100%;
}
<div></div>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...