简体   繁体   English

如何覆盖Bootstrap CSS中定义的媒体查询

[英]How can i overwrite media queries defined in Bootstrap CSS

I dont want media Queries defined in bootstrap CSS to override my custom CSS when user resizes his window.. 我不希望在用户调整窗口大小时,在bootstrap CSS中定义的媒体查询覆盖我的自定义CSS。

my code HTML 我的代码HTML

<div class="row">
<div class="col-xs-6">
<dl class="dl-horizontal dl-horizontal-info custom">
<dt>item 1</dt>
<dd>description 1 </dd>
<dt>item 2</dt>
<dd>description 2</dd>
<dt>item 3</dt>
<dd>description 3</dd>
<dt>item 4</dt>
<dd>description 4</dd>
<dt>item 5</dt>
<dd>description 5</dd>
</dl>
</div>
<div class="col-xs-6">
<dl class="dl-horizontal dl-horizontal-info custom">
<dt>item 11</dt>
<dd>description 11 </dd>
<dt>item 12</dt>
<dd>description 12</dd>
<dt>item 13</dt>
<dd>description 13</dd>
<dt>item 14</dt>
<dd>description 14</dd>
<dt>item 15</dt>
<dd>description 15</dd>
</dl>
</div>
</div>

CSS CSS

@import url("http://maxcdn.bootstrapcdn.com/bootswatch/3.2.0/cerulean/bootstrap.min.css");
@import url("http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css");

.custom > dt{width:120px;}
.custom > dd{margin-left:130px}

http://jsfiddle.net/afLka00x/ http://jsfiddle.net/afLka00x/

If i resize the window to lower than 768px, the media query from Bootstrap CSS overrides my custom css and dt dd aligns vertically, i want them to align horizontally. 如果我将窗口调整到低于768px,来自Bootstrap CSS的媒体查询会覆盖我的自定义css并且dt dd垂直对齐,我希望它们水平对齐。

How can i do so ? 我怎么能这样做?

i have found this code in Bootstrap.css causing this 我在Bootstrap.css中发现了这个代码

CSS CSS

@media (min-width: 768px) {
  .dl-horizontal dt {
    float: left;
    width: 160px;
    clear: left;
    text-align: right;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .dl-horizontal dd {
    margin-left: 180px;
  }
}

so i have modified above to this code in my custom.css 所以我在custom.css中修改了上面的代码

CSS CSS

@media (min-width: 768px) {
  .dl-horizontal dt {
    width:120px;
  }
  .dl-horizontal dd {
    margin-left:130px
  }
}

But dl-horizontal dl-horizontal-info still aligns vertically after i resize the window. 但是在调整窗口大小后, dl-horizontal dl-horizontal-info仍然垂直对齐。

i want my dl to look like this , even after i resize the window. 我希望我的dl看起来像这样,即使在我调整窗口大小之后。

期望的对齐

and not like this 而不是这样

错误的对齐

I dont want media Queries defined in bootstrap CSS to override my custom CSS when user resizes his window. 我不希望在用户调整窗口大小时,在bootstrap CSS中定义的媒体查询覆盖我的自定义CSS。

Well, they don't. 好吧,他们没有。

Bootstrap is not “overriding” your given formatting in that regard – but it is adding float:left , which causes the behavior you want in the first place, only when the viewport width is above 767px: 在这方面,Bootstrap没有“覆盖”你给定的格式 - 但是它正在添加 float:left ,这会导致你想要的行为,只有当视口宽度高于767px时:

@media (min-width: 768px)
  .dl-horizontal dt {
    float:left;
  }
}

So below 768px this formatting is missing, and therefor the default styling from the browser stylesheet is applied. 因此,在768px以下缺少此格式,因此应用了浏览器样式表的默认样式。

If you want your dt to float left even below that viewport width, then you have to add it via your own rules too: 如果你希望你的dt甚至低于那个视口宽度,那么你也必须通过你自己的规则添加它:

.custom > dt{
  float:left;
  width:120px;
}

http://jsfiddle.net/afLka00x/1/ http://jsfiddle.net/afLka00x/1/

Try this in your Custom.css 在Custom.css中试试这个

@media (min-width: 768px) {
        .dl-horizontal > dt{  width: 120px!important;float: left;
      clear: both;}
}

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

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