简体   繁体   English

使用Twitter Bootstrap调整页面大小时在CSS中更改div的高度

[英]Changing height on div in css when resizing page using Twitter Bootstrap

I'm looking for a way to set the height of my div searchResults to 100% when I resize down to col-xs-12 . 我正在寻找一种将大小调整为col-xs-12时将div searchResults的高度设置为100%的方法。 When the searchFilter div shrinks down to col-xs-12 I hide it and its height is set to 20%. searchFilter div缩小到col-xs-12我将其隐藏,并将其高度设置为20%。 The div below it searchResults has a height of 80%, and when I resize down to col-xs-12 I want to change it's height to 100%. 它下面的div searchResults的高度为80%,当我将其尺寸减小为col-xs-12我想将其高度更改为100%。

I tried this in my css but it didn't work. 我在CSS中尝试了此操作,但没有成功。

.searchResults .col-xs-12 {
    height: 100%;
}

I also tried 我也试过

.searchResults > .col-xs-12 {
    height: 100%;
}

Here is my html and css 这是我的HTML和CSS

 .searchFilter { height: 20%; } .searchResults { height: 80%; } .searchResults .col-xs-12 { height: 100%; } 
 <div class="container-fluid"> <div class="row"> <div class="col-lg-5 col-md-5 col-sm-5 hidden-xs"> @*Sidebar*@ <div id="googleResultMap"></div> </div> <div class="col-lg-7 col-md-7 col-sm-7 col-xs-12"> @*Body content*@ <div class="searchFilter col-lg-12 col-md-12 col-sm-12 hidden-xs"> hi </div> <div class="searchResults col-lg-12 col-xs-12 col-sm-12"> @*some content here left out*@ </div> </div> </div> </div> 

Use media queries 使用媒体查询

@media only screen and (max-width : 480px) {
    /* only size 'xs' and below */
    .searchResults {
        height: 100%;
    }
}

H there, What you will need to look at ... use here is media queries at each breakpoint. 在这里,您需要查看的内容...这里是每个断点处的媒体查询

Use a media query for each size you what to change. 对要更改的每种尺寸使用媒体查询。

Just use your class searchFilter like this... 像这样使用您的类searchFilter ...

@media (max-width: 768px) { 
.searchFilter {
height: 100%;
}
}

Have a look at this Bootstrap link about media queries. 看一下有关媒体查询的Bootstrap链接

Added to here: 添加到这里:

Here is a working Fiddle for you to look at. 这是一个工作中的提琴供您查看。
Just resize the window to see the height change at the media breakpoints. 只需调整窗口大小即可查看介质断点处的高度变化。
Note I use vh and not % as I don't know what parent size you are working too here. 注意我使用vh而不是%,因为我也不知道您在这里工作的父级大小。

媒体查询调整大小

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

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