[英]How to show two element at the top and bottom of the div which is auto height in css
I have two div one is left and one is right.我有两个 div,一个在左边,一个在右边。 and have two element in right div and I want to place one at the top of the div and another one is at the bottom.
并在右侧 div 中有两个元素,我想将一个放在 div 的顶部,另一个放在底部。 the height of left element is auto so is right one and we can not fix the height because of dynamic content.
左元素的高度是自动的,右元素的高度也是自动的,由于动态内容,我们无法固定高度。
#mainDiv.list_desc { width: 80%; height: 100%; display: inline-block; vertical-align: top; } #mainDiv.list_desc.title { font-size: 44px; color: #000066; padding: 15px; } #mainDiv.list_desc.tag { width: 100%; padding: 15px; } #mainDiv.list_desc.tag.facility_tag { display: inline-block; text-align: left; width: 25%; font-size: 22px; color: #000066; } #mainDiv.list_desc.desc { font-size: 26px; padding: 15px; } #mainDiv.list_price { width: 19%; height: 100%; display: inline-block; border: 1px solid blue; } #mainDiv.list_price.top_price { height: 90%; border: 1px solid black; font-size: 48px; text-align: right; padding: 15px; } #mainDiv.list_price.bottom_button { height: 10%; border: 1px solid blue; } #mainDiv.list_price.bottom_button.select_room_btn { width: 100%; border: 1px solid #000066; text-align: center; font-size: 26px; }
<div id="mainDiv"> <div class="list_section"> <div class="singlelist"> <div class="list_desc"> <div class="title">My title</div> <div class="tag"> <div class="facility_tag tag1">Tag1</div> <div class="facility_tag tag2">Tag2</div> <div class="facility_tag tag3">Tag3</div> </div> <div class="desc">If you have ever looked for new fonts to download, then 'the quick brown fox jumps over the lazy dog' is a sentence that you have probably seen before. This pangram is often seen next to fonts that are on display. The font's style is applied to the pangram, giving an example of what the font would look like in a sentence and also for the individual letters. This is one of the common uses of pangrams these days; to display different styles of fonts.If you have ever looked for new fonts to download, then 'the quick brown fox jumps over the lazy dog' is a sentence that you have probably seen before. This pangram is often seen next to fonts that are on display. The font's style is applied to the pangram, giving an example of what the font would look like in a sentence and also for the individual letters. This is one of the common uses of pangrams these days; to display different styles of fonts.If you have ever looked for new fonts to download, then 'the quick brown fox jumps over the lazy dog' is a sentence that you have probably seen before. This pangram is often seen next to fonts that are on display. The font's style is applied to the pangram, giving an example of what the font would look like in a sentence and also for the individual letters. This is one of the common uses of pangrams these days; to display different styles of fonts.</div> </div> <div class="list_price"> <div class="top_price">$100</div> <div class="bottom_button"> <div class="select_room_btn">Select This</div> </div> </div> </div> </div> </div>
Js fiddle: https://jsfiddle.net/pbvfr1hq/ js小提琴: https://jsfiddle.net/pbvfr1hq/
Select this button should be at the bottom of description in right div. Select 此按钮应位于右侧 div 的描述底部。
On the div that wrapps the items you want to adjust, say display: flex;在包装您要调整的项目的 div 上,说 display: flex; flex-direction: column;
弹性方向:列; justify-content: space-between;
justify-content: 之间的空格; *the first and last div will be placed on top and bottom
*第一个和最后一个div将放在顶部和底部
(EDITED) Your CSS should look like this: (已编辑)您的 CSS 应如下所示:
#mainDiv .list_desc{
height:100%;display:inline-block;vertical-align:top;
}
#mainDiv .list_desc .title{
font-size:44px;color:#000066;padding:15px;
}
#mainDiv .list_desc .tag{
width:100%;padding:15px;
}
#mainDiv .list_desc .tag .facility_tag{
display:inline-block;text-
align:left;width:25%;font-size:22px;color:#000066;
}
#mainDiv .list_desc .desc{
font-size:26px;padding:15px;
}
#mainDiv .list_price{
height:100%;display:inline-block;border:1px solid blue;
}
#mainDiv .list_price .top_price{
border:1px solid black;font-size:48px;text-align:right;padding:15px;
}
#mainDiv .list_price .bottom_button{
border:1px solid blue;
}
#mainDiv .list_price .bottom_button .select_room_btn{
width:100%;border:1px solid #000066;text-align:center;font-size:26px;
}
#mainDiv .singlelist {
display: -webkit-flex;
display: -ms-flex;
display: flex;
justify-content: space-between;
}
#mainDiv .list_desc {
-ms-flex: 0 0 80%;
flex: 0 0 80%;
max-width: 80%;
}
#mainDiv .singlelist .list_price{
display: -webkit-flex;
display: -ms-flex;
display: flex;
flex-direction: column;
height: auto;
-ms-flex: 0 0 20%;
flex: 0 0 20%;
max-width: 20%;
border: none;
}
#mainDiv .singlelist .list_price .top_price{
height: auto;
}
#mainDiv .singlelist .list_price .bottom_button{
margin-top: auto;
}
I think you can use display:grid
to solve your problem.我认为您可以使用
display:grid
来解决您的问题。
.singlelist { display: grid; grid-template-columns: 80% auto; grid-template-row: auto; column-gap: 0; row-gap: 0; } #mainDiv.list_desc { width: 100%; height: 100%; display: inline-block; vertical-align: top; } #mainDiv.list_desc.title { font-size: 44px; color: #000066; padding: 15px; } #mainDiv.list_desc.tag { width: 100%; padding: 15px; } #mainDiv.list_desc.tag.facility_tag { display: inline-block; text-align: left; width: 25%; font-size: 22px; color: #000066; } #mainDiv.list_desc.desc { font-size: 26px; padding: 15px; } #mainDiv.list_price { width: 100%; height: 100%; display: inline-block; border: 1px solid blue; display: flex; flex-direction: column; justify-content: space-between; flex-grow: 1; } #mainDiv.list_price.top_price { border: 1px solid black; font-size: 48px; text-align: right; padding: 15px; } #mainDiv.list_price.bottom_button { border: 1px solid blue; } #mainDiv.list_price.bottom_button.select_room_btn { width: 100%; border: 1px solid #000066; text-align: center; font-size: 26px; }
<div id="mainDiv"> <div class="list_section"> <div class="singlelist"> <div class="list_desc"> <div class="title">My title</div> <div class="tag"> <div class="facility_tag tag1">Tag1</div> <div class="facility_tag tag2">Tag2</div> <div class="facility_tag tag3">Tag3</div> </div> <div class="desc">If you have ever looked for new fonts to download, then 'the quick brown fox jumps over the lazy dog' is a sentence that you have probably seen before. This pangram is often seen next to fonts that are on display. The font's style is applied to the pangram, giving an example of what the font would look like in a sentence and also for the individual letters. This is one of the common uses of pangrams these days; to display different styles of fonts.If you have ever looked for new fonts to download, then 'the quick brown fox jumps over the lazy dog' is a sentence that you have probably seen before. This pangram is often seen next to fonts that are on display. The font's style is applied to the pangram, giving an example of what the font would look like in a sentence and also for the individual letters. This is one of the common uses of pangrams these days; to display different styles of fonts.If you have ever looked for new fonts to download, then 'the quick brown fox jumps over the lazy dog' is a sentence that you have probably seen before. This pangram is often seen next to fonts that are on display. The font's style is applied to the pangram, giving an example of what the font would look like in a sentence and also for the individual letters. This is one of the common uses of pangrams these days; to display different styles of fonts.</div> </div> <div class="list_price"> <div class="top_price">$100</div> <div class="bottom_button"> <div class="select_room_btn">Select This</div> </div> </div> </div> </div> </div>
You will want to write media queries in order to make it responsive.您将需要编写媒体查询以使其具有响应性。
You can learn about grid
property here: https://css-tricks.com/snippets/css/complete-guide-grid/您可以在此处了解
grid
属性: https://css-tricks.com/snippets/css/complete-guide-grid/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.