简体   繁体   English

根据屏幕大小/媒体查询更改Bootstrap列类属性

[英]Change Bootstrap column class attribute based on screen size/media query

I am using Twitter's bootstrap and I have a problem. 我正在使用Twitter的bootstrap,我有一个问题。 I am using the grid system and in my html have used the col-lg-6 class to create a two different columns with equal width. 我正在使用网格系统,在我的html中使用了col-lg-6类来创建两个宽度相等的不同列。 See code below: 见下面的代码:

<div class="row">
<div class="row sameHeightCols">
        <div class="col-lg-6">
            <div class="contentBlock">
                <h3>Header</h3>
            </div>
        </div>
        <div class="col-lg-6">
            <h3>Header2</h3>
        </div>
    </div>
</div>

The issue I am having is that when it hits a certain screen size it breaks and some of the content in the left block disappears. 我遇到的问题是,当它达到某个屏幕大小时,它会断开,并且左侧块中的某些内容会消失。 This occurs when screen size is between col-lg and col-md . 当屏幕大小介于col-lgcol-md之间时会发生这种情况。 What I would like to to do is change the classes at a certain screen size so it changes to this. 我想要做的是更改某个屏幕大小的类,以便更改为此。

<div class="col-lg-9">
    <div class="contentBlock">
      <h3>Header</h3>
    </div>
</div>
<div class="col-lg-3">
     <h3>Header2</h3>
</div>

Is this possible in css with a media query? 这有可能在带有媒体查询的CSS中吗? or do I need to use javascript? 或者我需要使用javascript吗? Any help would be greatly appreciated as I have done a lot of research and cannot find a solution. 任何帮助将不胜感激,因为我做了大量的研究,无法找到解决方案。 Please also let me know if any further code/info is required. 如果需要任何进一步的代码/信息,也请告诉我。

Thanks. 谢谢。

Paul Fitzgerald , Hi there. Paul Fitzgerald ,你好。 Are you just wanting to change this from 6x6 when lg... to 9x3 at md ? 你只是想把它从lx的6x6改为md的9x3吗?

If so have a look at this Fiddle . 如果这样看看这个小提琴

Resize the window. 调整窗口大小。 I you do not want this to stack then let us know. 我不希望这个堆叠,然后告诉我们。

<div class="container"> 
    <div class="row text-center">
        <div class="col-md-9 col-lg-6 block1"><h2>Header 1</h2></div>
        <div class="col-md-3 col-lg-6 block2"><h2>Header 2</h2></div>    
    </div>    
</div> 

The screenshot below shows the change when resized from LG 6x6 to MD 9x3. 下面的屏幕截图显示了从LG 6x6调整为MD 9x3时的更改。

在此输入图像描述

Added to this post 添加到这篇文章

Paul , I think this is what you are wanting here, to have a new media breakpoint between MD and LG . 保罗 ,我认为这就是你想要的,在MDLG之间有一个新的媒体断点

In the screenshot below I added text to show when it is using LG and XLG and MD . 在下面的屏幕截图中,我添加了文本,以显示它何时使用LGXLGMD

添加媒体断点

Here is the Fiddle . 这是小提琴

Hope this gets you started with how you want this. 希望这可以帮助您了解自己的需求。

No you do not need Java Script you can use media query . 不,您不需要Java Script您可以使用媒体查询。 but you are using bootstrap you don't need that see this table it shows every class according to size of screen try to add multiple classes but every thing can not be appear on every screen size use these classes [ here ] to hide on particular screen size. 但你正在使用bootstrap你不需要看到这个表它显示每个类根据屏幕的大小尝试添加多个类但每个屏幕上都不能出现每个屏幕大小使用这些类[ here ]隐藏在特定的屏幕上尺寸。 If you are trying to create to menu you will need bootstrap java script code and jQuery 如果您尝试创建菜单,则需要引导java脚本代码和jQuery

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

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