【问题标题】:Need to override some styles需要覆盖一些样式
【发布时间】:2018-06-07 01:05:37
【问题描述】:

Hi 我的引导表看起来并不完美。
其他页面需要一些外部样式,这些样式从我的自定义 CSS 应用到我的表格。
我必须缩小引导表列之后的空间。我需要覆盖这些样式。

请帮助我覆盖这些样式并完美地查看表格。

<style type="text/css">
 thead {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    width: 100%;
}

tbody {
    overflow-y: scroll;
}

thead > tr, tbody > tr, tfoot > tr {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
}

thead, tfoot {
    flex-shrink: 3;
}



th, tbody td 
{
    width: 20%; /* this can vary */
    overflow-x: hidden;
    text-overflow: ellipsis;
    display: inline-block;
}


.container{
  margin: 20px 0;
}
 </style>


 
<div class="row">
	<div class="col-md-12">
		<div class="form-group">
			<input type="submit" class="btn btn-primary addnew" value="Add New" ng-click="addNew()">
				<input ng-hide="!jobGroupDetails.length" type="button" class="btn btn-danger" ng-click="remove()" value="Remove">
				</div>
				<div class="scrollable">
					<table class="table table-striped table-bordered table-condensed">
						<thead>
							<tr>
								<th>
									<input type="checkbox" ng-model="selectedAll" ng-click="checkAll()" />
								</th>
								<th>JobGroupName</th>
								<th>Start Date</th>
								<th>End Date</th>
							</tr>
						</thead>
						<tbody>
							<tr ng-repeat="jobGroupDetail in jobGroupDetails">
								<td>e1</td>
								<td>e2</td>
								<td>e3</td>
							</tr>
						</tbody>
					</table>
				</div>
				<div class="text-center">
					<button type="button" class="btn btn-primary" value="Submit" ng-click="saveJobData()">Submit</button>
					<button type="button" class="btn btn-primary" value="Submit" ng-click="initiateLambda()">Initiate Lambda</button>
				</div>
			</div>
		</div>
	</div>
	

嗨,我的引导表看起来并不完美。其他页面需要一些外部样式,这些样式从我的自定义 CSS 应用到我的表格,我必须缩小引导表列之后的空间。我需要覆盖这些样式。

【问题讨论】:

    标签: html css twitter-bootstrap-3


    【解决方案1】:

    删除所有分配给display的属性:

    <table>, <thead>, <tbody>, <th>, <td>, <tfoot>, <tr>
    

    表节点有自己的行为,并被设计为在&lt;table&gt; 标签的范围内互锁。

    演示


    .container {
      margin: 20px 0;
    }
    
    table {
      width: 100%;
    }
    
    tbody {
      overflow-y: scroll;
    }
    
    th,
    td {
      max-width: 22%;
    }
    
    fieldset.btn-group.btn-group.btn-group {
      display: inline-block;
      margin: 1em 0;
      cursor: pointer
    }
    
    .textTrunc {
      position: relative;
    }
    
    .text-truncate {
      position: absolute;
      top: 0em;
      max-width: 24%;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
    '
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.1/css/bootstrap.min.css" />
    
    <main class='container'>
    
      <section class="row">
        <div class="col-md-12">
          <fieldset class="btn-group ">
            <input type="button" class="btn.btn btn-primary addnew" value="ADD">
            <input type="button" class="btn.btn btn-danger" value="DEL">
          </fieldset>
          <section class="scrollable">
    
            <table class="table table-striped table-bordered table-condensed">
              <thead>
                <tr>
                  <th>
                    <input type="checkbox" ng-model="selectedAll" ng-click="checkAll()" />
                  </th>
                  <th>JobGroupName</th>
                  <th>Start Date</th>
                  <th>End Date</th>
                </tr>
              </thead>
              <tbody>
                <tr>
                  <td class='textTrunc'>
                    <div class='text-truncate text-nowrap'>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis
                      aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</div>
                  </td>
                  <td class='textTrunc'>
                    <div class='text-truncate text-nowrap'>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis
                      aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</div>
                  </td>
                  <td class='textTrunc'>
                    <div class='text-truncate text-nowrap'>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis
                      aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</div>
                  </td>
                  <td class='textTrunc'>
                    <div class='text-truncate text-nowrap'>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis
                      aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</div>
                  </td>
                </tr>
              </tbody>
            </table>
    
          </section>
    
          <fieldset class="btn-group float-right">
            <button type="submit" class="btn btn-primary">Submit</button>
            <button type="button" class="btn btn-success">Initiate Lambda</button>
          </fieldset>
        </div>
      </section>
    </main>

    【讨论】:

      【解决方案2】:

      首先,对&lt;table&gt;元素应用一个类,然后CSS通过该类定位各种表格元素,例如.my-table td { font-weight: 700 }

      请注意 Chris Coyiers 的文章 Fixed Table Layouts

      在我看来,表格有一个 CSS 属性是 得到很好的支持,鲜为人知,而且超级有用。它改变了方式 表格的呈现方式使其更坚固,更 可预测的布局。

      table {
        table-layout: fixed;
      }
      

      【讨论】:

        【解决方案3】:

        我想在编码方面帮助您……但从长远来看,最好还是自己想办法成为一名优秀的开发人员。我将为您提供一些有关如何在 CSS 中解决问题的资源和想法。我不是 CSS Ninja,但我是 animate.css 库的贡献者之一。

        这里有很棒的资源:@​​987654321@ 您可以尝试在使用 CSS 时使用不同的优先级技术。

        如果您将样式表放在下面,它将是您工作中的优先事项。

        例子:

        <link rel="stylesheet" href="assets/css/stylesheet1.css" type="text/css">
        <!-- Below is the new style for the page -->
        <link rel="stylesheet" href="assets/css/stylesheet2.css" type="text/css">
        

        您可能需要查看这个以便更好地理解...
        What are the priorities among CSS selectors

        也可以看看这个:https://www.w3.org/TR/CSS21/cascade.html#cascade

        最好也阅读一下... https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity

        这里的想法和线索是 CSS Priority :)

        我只是告诉你如何解决你的问题而不是用勺子喂食......我希望这能解决你的问题。好的!

        【讨论】:

        • “如果你把你的 CSS 放在首位,它将是你工作中的优先事项。” 你确定吗?我一直认为规则集越是 down,它的属性将覆盖它之前的所有其他匹配属性(即顶部将被它之后的任何东西覆盖)。 Cascading样式表的名称,cascading就像瀑布一样。顺便说一句,虽然不禁止外部链接,但不鼓励使用 only links 的答案,发布代码和某种解释是 SO 上最需要的答案类型。
        • 对不起,我忘记了这些东西……我只是回顾了 CSS 的优先主题并在这里编写了一些测试代码。添加到样式中的最新代码是最优先的。如果您将内联样式与 !important 进行比较,那么获胜者就是 !important。
        • 确实如此!important 将始终覆盖,但要查看级联样式的行为,请比较具有相同选择器、相同属性和不同值的 2 个规则集。前任。 .div0 {color:blue} 然后下一行是:.div0 {color:red} 所有.div0 文本将是红色的。不是蓝色的。
        • 同意...我已经尝试过,而且,我对此有很好的参考,但我忘记了它的链接。最新的东西是最强大的。作为覆盖 !important 的额外内容,您还需要将 !important 放入元素的内联样式中。
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-04-20
        • 2015-04-07
        • 1970-01-01
        • 2013-10-18
        • 2020-12-20
        相关资源
        最近更新 更多