如何使折叠按钮和虚线同时工作

huangapple go评论66阅读模式
英文:

How to make both collapse button and dotted line to work together

问题

以下是您要翻译的内容:

当我删除CSS中的第一行display: flex !important;时,折叠展开按钮按预期工作(单击set1的顶部),但删除了中间的虚线。

当我保留CSS中的第一行display: flex !important;时,折叠展开不起作用(单击set1的顶部),但中间的虚线显示如预期。

相同的工作示例链接:http://jsfiddle.net/k68frxds/6/

如何保持虚线和折叠展开按钮同时工作?谢谢。

<div class="itemDiv">
   <div>
      <a class="accordion-button " data-toggle="collapse" data-target=".lev1"> Set1 </a>
      <p class ="collapse multi-collapse lev1 show">item1 <span class="DataRightAlign"> Set1val</span></p>
      <p class ="collapse multi-collapse lev1 show">item2<span class="DataRightAlign">Set1val</span></p>
   </div> 

   <div>
      <a class="accordion-button " data-toggle="collapse" data-target=".lev3">Set2 </a>
      <p class="collapse multi-collapse lev3 show"> item3<span class="DataRightAlign">Set2val</span></p>
  </div>  
</div>

CSS:

.lev1,.lev2,.lev3 {
    display: flex !important;
    align-items: flex-end;
    margin-top: 5px;
    margin-left: 15px;
}

.lev1:after, .lev2:after, .lev3:after {
    content: '';
    flex: auto;
    min-width: 24px;
    margin: 0 6px;
    height: 2px;
    color: lightgrey;
    margin-bottom: 4px;
    background-image: linear-gradient(to right,currentColor 2px,transparent 1px);
    background-size: 4px 2px;
}

.DataRightAlign {
  flex: none;
  word-wrap: break-word;
  white-space: break-spaces;
  max-width: 62%;    
  float: right;
  margin-right: 20px;
  margin-left: 10px;
  color: black; 
}

.DataRightAlign:last-child {
    order: 1;
    text-align: right;
}
英文:

When I remove the first line in the css display: flex !important;, collapse-expand button works as expected (click on top of set1), but removes the in-between dotted line.

When I keep the first line in the css display: flex !important;, collapse-expand does not work (click on top of set1), but in-between dotted line is shown as expected.

Working fiddle of the same` http://jsfiddle.net/k68frxds/6/

How to keep both dotted lines and collapse expand button to work? Thank you.

&lt;div class=&quot;itemDiv&quot;&gt;
   &lt;div&gt;
      &lt;a class=&quot;accordion-button &quot; data-toggle=&quot;collapse&quot; data-target=&quot;.lev1&quot;&gt; Set1 &lt;/a&gt;
      &lt;p class =&quot;collapse multi-collapse lev1 show&quot;&gt;item1 &lt;span class=&quot;DataRightAlign&quot;&gt; Set1val&lt;/span&gt;&lt;/p&gt;
      &lt;p class =&quot;collapse multi-collapse lev1 show&quot;&gt;item2&lt;span class=&quot;DataRightAlign&quot;&gt;Set1val&lt;/span&gt;&lt;/p&gt;
   &lt;/div&gt; 

   &lt;div&gt;
      &lt;a class=&quot;accordion-button &quot; data-toggle=&quot;collapse&quot; data-target=&quot;.lev3&quot;&gt;Set2 &lt;/a&gt;
      &lt;p class=&quot;collapse multi-collapse lev3 show&quot;&gt; item3&lt;span class=&quot;DataRightAlign&quot;&gt;Set2val&lt;/span&gt;&lt;/p&gt;
  &lt;/div &gt;  
&lt;/div &gt;

Css:

.lev1,.lev2,.lev3 {
    display: flex !important;
    align-items: flex-end;
    margin-top: 5px;
    margin-left: 15px;
}

.lev1:after, .lev2:after, .lev3:after {
    content: &#39;&#39;;
    flex: auto;
    min-width: 24px;
    margin: 0 6px;
    height: 2px;
    color: lightgrey;
    margin-bottom: 4px;
    background-image: linear-gradient(to right,currentColor 2px,transparent 1px);
    background-size: 4px 2px;
}

.DataRightAlign {
  flex: none;
  word-wrap: break-word;
  white-space: break-spaces;
  max-width: 62%;    
  float: right;
  margin-right: 20px;
  margin-left: 10px;
  color: black; 
}

.DataRightAlign:last-child {
    order: 1;
    text-align: right;
}

答案1

得分: 2

请注意,以下是您的内容的翻译部分:

不要为了样式化Bootstrap元素而嵌套您自己的元素进行样式化。

我对您的HTML结构进行了一些更改:

<div class="trackBallDiv">

  <div>
    <a class="accordion-button " data-toggle="collapse" data-target=".lev1">Set1 </a>
    <div class="collapse multi-collapse lev1 show">
      <p class="flex">
        <span>CableValue</span>
        <span class="DataRightAlign">Set1val</span>
      </p>
    </div>
    <div class="collapse multi-collapse lev1 show">
      <p class="flex">
        <span>CableResistance</span>
        <span class="DataRightAlign">Set1val</span>
      </p>
    </div>
  </div>

  <div>
    <a class="accordion-button " data-toggle="collapse" data-target=".lev3">Set2 </a>
    <div class="collapse multi-collapse lev3 show">
      <p class="flex">
        <span>Time</span>
        <span class="DataRightAlign">Set2val</span>
      </p>
    </div>
  </div>

</div>

这些是一些样式更改。我还删除了冗余的样式。

.flex {
  display: flex;
  justify-content: space-between;
}

.lev1, .lev2, .lev3 {
  position: relative;
  margin-top: 5px;
  margin-left: 15px;
}

.lev1::after, .lev2::after, .lev3::after {
  content: '';
  position: absolute;
  width: 80%;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  margin: 0 6px;
  height: 2px;
  color: lightgrey;
  margin-bottom: 4px;
  background-image: linear-gradient(to right, currentColor 2px, transparent 1px);
  background-size: 4px 2px;
}

.DataRightAlign {
  word-wrap: break-word;
  white-space: break-spaces;
  margin-right: 20px;
  margin-left: 10px;
  color: black;
}
英文:

Don't style the Bootstrap element nest your own element for styling.

I made some changes to your HTML structure:

&lt;div class=&quot;trackBallDiv&quot;&gt;

  &lt;div&gt;
      &lt;a class=&quot;accordion-button &quot; data-toggle=&quot;collapse&quot; data-target=&quot;.lev1&quot;&gt; Set1 &lt;/a&gt;
      &lt;div class =&quot;collapse multi-collapse lev1 show&quot;&gt;
      &lt;p class=&quot;flex&quot;&gt;
      &lt;span&gt;CableValue&lt;/span&gt;
      &lt;span class=&quot;DataRightAlign&quot;&gt; Set1val&lt;/span&gt;
      &lt;/p&gt;
      &lt;/div&gt;
      &lt;div class =&quot;collapse multi-collapse lev1 show&quot;&gt;
      &lt;p class=&quot;flex&quot;&gt;
      &lt;span&gt;CableResistance&lt;/span&gt;
      &lt;span class=&quot;DataRightAlign&quot;&gt;Set1val&lt;/span&gt;
      &lt;/p&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  
  
  &lt;div&gt;
      &lt;a class=&quot;accordion-button &quot; data-toggle=&quot;collapse&quot; data-target=&quot;.lev3&quot;&gt;Set2 &lt;/a&gt;
      &lt;div class=&quot;collapse multi-collapse lev3 show&quot; &gt; 
      &lt;p class=&quot;flex&quot;&gt;
      &lt;span&gt;Time&lt;/span&gt;
      &lt;span class=&quot;DataRightAlign&quot;&gt;Set2val&lt;/span&gt;
      &lt;/p&gt;
  &lt;/div &gt;
  
&lt;/div &gt;

These are some styling changes. I also remove redundant styles.

.flex{
    display: flex;
    justify-content: space-between;
 }
 
.lev1,.lev2,.lev3 {
    position: relative;
    margin-top: 5px;
    margin-left: 15px;
}

 .lev1::after, .lev2::after, .lev3::after {
        content: &#39;&#39;;
        position: absolute;
        width: 80%;
        top: 100%;
        left: 50%;
        transform: translateX(-50%);
        margin: 0 6px;
        height: 2px;
        color: lightgrey;
        margin-bottom: 4px;
        background-image: linear-gradient(to right, currentColor 2px, transparent 1px);
        background-size: 4px 2px;
    }
    
.DataRightAlign {
    word-wrap: break-word;
    white-space: break-spaces;
    margin-right: 20px;
    margin-left: 10px;
    color: black;
 
}

答案2

得分: 0

你需要覆盖来自你的库的.collapse.showdisplay样式:

.collapse.show {
    display: flex !important;
}

jsfiddle链接

英文:

You need to override .collapse.show's display style from your library

.collapse.show {
    display: block;
}

to

.collapse.show {
    display: flex !important;
}

jsfiddle link

huangapple
  • 本文由 发表于 2023年5月7日 16:22:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/76192861.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定