简体   繁体   English

div下段右

[英]Paragraph Bottom Right of Div

I have two divs that each have a paragraph link at the bottom right of the div. 我有两个div,每个div的右下角都有一个段落链接。 When I add the code bottom: 0; position: absolute; 当我添加代码bottom: 0; position: absolute; bottom: 0; position: absolute; , it pulls both the links together into the far right div instead of keeping them in their own divs. ,它将两个链接放到最右边的div中,而不是将它们保留在自己的div中。 How can I set this so that the link stays inside of it's own container at the bottom right corner? 如何设置此值,以使链接保留在右下角自己的容器内?

 .header-unit { height: 300px; position: relative; margin-top: 5px; background-size: cover; background-position: center; background-repeat: no-repeat; background-image: url("/images/liberty.jpg"); } #messageContainer { margin-left: 200px; /* padding-top: 450px; */ position: relative; display: inline-block; } h1 { font-family: 'Montserrat', sans-serif; font-size: 2em; line-height: 1.15; text-transform: uppercase; } #knowledge, #practice { padding: 25px; width: 350px; height: 300px; display: block; color: #fff; } .linksect { bottom: 0; right: 25px; position: absolute; } #knowledge { background: #8b8b8b; } #practice { background: #554a58; } .indexheader { font-family: 'Montserrat', sans-serif; font-size: 2em; line-height: 1.15; text-transform: uppercase; color: #554a58; } .firmvalues { margin-top: 50px; } 
 <link href="https://www.w3schools.com/w3css/4/w3.css" rel="stylesheet" /> <div class="header-unit"> <div id="messageContainer" class="w3-row"> <div id="knowledge" class="w3-col l6"> <h1>Knowledge. Experience. Commitment. </h1> <p>The attorneys of ....</p> <p class="linksect"><a href="/page/3/attorneys">Our Attorneys <span class="fa fa-angle-double-right" aria-hidden="true"></span></a></p> </div> <div id="practice" class="w3-col l6"> <h1>Practice Areas</h1> <p>Business and Commercial Law<br> Insurance Coverage and Indemnity Law<br> Medical and Dental Malpractice<br> Probate Law and Practice<br> and more...</p> <p class="linksect"><a href="/page/2/practices">Practice Areas <span class="fa fa-angle-double-right" aria-hidden="true"></span></a></p> </div> </div> </div> 

You can provide context for position:absolute by adding a non-static position property to the ancestor element you want the absolutely positioned element to be relative to. 您可以通过向您希望绝对定位的元素相对的祖先元素添加非静态position属性来为position:absolute提供上下文。 position:relative is usually a good choice because it keeps your element in the document flow. position:relative通常是一个不错的选择,因为它将元素保留在文档流中。 (Note that I added it to the #knowledge,#practice rule.) (请注意,我已将其添加到#knowledge,#practice规则中。)

 .header-unit { height: 300px; position: relative; margin-top: 5px; background-size: cover; background-position: center; background-repeat: no-repeat; background-image: url("/images/liberty.jpg"); } #messageContainer { margin-left: 200px; /* padding-top: 450px; */ position: relative; display: inline-block; } h1 { font-family: 'Montserrat', sans-serif; font-size: 2em; line-height: 1.15; text-transform: uppercase; } #knowledge, #practice { padding: 25px; width: 350px; height: 300px; display: block; color: #fff; position: relative; } .linksect { bottom: 0; right: 25px; position: absolute; } #knowledge { background: #8b8b8b; } #practice { background: #554a58; } .indexheader { font-family: 'Montserrat', sans-serif; font-size: 2em; line-height: 1.15; text-transform: uppercase; color: #554a58; } .firmvalues { margin-top: 50px; } 
 <link href="https://www.w3schools.com/w3css/4/w3.css" rel="stylesheet" /> <div class="header-unit"> <div id="messageContainer" class="w3-row"> <div id="knowledge" class="w3-col l6"> <h1>Knowledge. Experience. Commitment. </h1> <p>The attorneys of ....</p> <p class="linksect"><a href="/page/3/attorneys">Our Attorneys <span class="fa fa-angle-double-right" aria-hidden="true"></span></a></p> </div> <div id="practice" class="w3-col l6"> <h1>Practice Areas</h1> <p>Business and Commercial Law<br> Insurance Coverage and Indemnity Law<br> Medical and Dental Malpractice<br> Probate Law and Practice<br> and more...</p> <p class="linksect"><a href="/page/2/practices">Practice Areas <span class="fa fa-angle-double-right" aria-hidden="true"></span></a></p> </div> </div> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM