简体   繁体   English

基于容器的实际宽度的Twitter Bootstrap 3断点

[英]Twitter Bootstrap 3 breakpoints based on actual width of container

I am using Bootstrap 3 (and Angular) for a webapp. 我正在将Bootstrap 3(和Angular)用于Web应用程序。 I have sidebars which can be toggled, they are not using bootstrap (but table-cell layout) 我有可以切换的侧边栏,它们没有使用引导程序(而是表格单元格布局)

I created a demo here: http://plnkr.co/edit/0pGjRqfqF21lGvhuNb9k?p=preview 我在这里创建了一个演示: http : //plnkr.co/edit/0pGjRqfqF21lGvhuNb9k?p=preview

Is it possible to make bootstrap columns break relative to the actual with of the container they are in? 是否可以使引导程序列相对于它们所在的容器的实际值中断?

Example: A col-sm-* should break if its container (aside-main) is <768px, not the screen ? 示例:如果col-sm- *的容器(aside-main)小于768px,而不是屏幕,则应中断。

<div class="row" ng-controller="demoCtrl">
<div class="aside-container">
  <div class="aside-main">
    <div class="col-sm-12">
      <h2>Main Content Area</h2>
      <div class="row">
        <div class="col-sm-6">
          <strong>column 1</strong>             
        </div>
        <div class="col-sm-6">
          <strong>column 2</strong>             
        </div>
      </div>
    </div>
  </div>
  <div class="aside" ng-if="asideIn">
    <div class="col-sm-12">
      <h2>Aside Area</h2>
      here is the aside content
    </div>
  </div>
</div>

In 2018 seems there are such possibilities. 在2018年似乎有这种可能性。

According to the documentation of project https://github.com/marcj/css-element-queries all you have to do is following. 根据项目https://github.com/marcj/css-element-queries的文档,您所要做的就是遵循。

Let's say you have following html element. 假设您有以下html元素。

<div class="parent">
    <h2>Test</h2>
</div>

And you define following css 然后定义以下css

.parent h2 {
    font-size: 12px;
}

.parent[min-width~="400px"] h2 {
    font-size: 18px;
}

.parent[min-width~="600px"] h2 {
    padding: 55px;
    text-align: center;
    font-size: 24px;
}

.parent[min-width~="700px"] h2 {
    font-size: 34px;
    color: red;
}

And include scripts 并包含脚本

<script src="src/ResizeSensor.js"></script>
<script src="src/ElementQueries.js"></script>

Functionality of the project will find html elements that css is referring to and will only listen to changes of those elements. 该项目的功能将找到css所引用的html元素,并且仅侦听这些元素的更改。

"no performance issues since it listens only on size changes of elements that have element query rules defined through css. " “没有性能问题,因为它仅侦听具有通过css定义的元素查询规则的元素的大小变化。”

eg when an element that is "watched" exceeds width of 400 on watched element will be added css attribute min-width 400px and defined css will be applied to it. 例如,当“被监视”的元素在被监视元素上的宽度超过400时,将添加css属性min-width 400px并将已定义的css应用于该元素。

Also for this to work you need to trigger the event listening or initialization yourself: 另外,要使此方法起作用,您需要自己触发事件侦听或初始化:

var ElementQueries = require('css-element-queries/src/ElementQueries');

 //attaches to DOMLoadContent
ElementQueries.listen();

//or if you want to trigger it yourself.
// Parse all available CSS and attach ResizeSensor to those elements which have rules attached
// (make sure this is called after 'load' event, because CSS files are not ready when domReady is fired.
ElementQueries.init();

It's not exactly breaking bootstrap columns, but you can control css based on the width of the container. 它并没有完全打破引导程序列,但是您可以根据容器的宽度来控制CSS。 Should suffice. 应该足够了。

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

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