CSS代码用于为每个内容添加左边框和项目符号。

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

CSS Code for Div Left-Border with Bullet Points for each Content

问题

我必须在divborder-left上添加蓝色,并在每个内容的开头添加如下图所示的项目符号。

我尝试了以下代码,但我的设计与上面的图像不匹配。下面的图像显示了我开发的内容。

以下是此弹出窗口的HTML代码:

<div id="AuditModal" class="modal">
    <div class="modal-content">
        <div>
            <h1 class="chart-heading-cls AuditTitle">Audit</h1>
            <a class="modal-close"><img class="Close closemodal" src="~/Close.svg"></a>
        </div>
        <div id="Audit">
            <div class="card-content">
            </div>
        </div>        
    </div>
</div>

在其中,我正在使用jQuery循环追加内容,如下所示:

markup = "<div><div class='UserTitle UserTitleBullet pl23'>" + ActionData[i].ACTION_TAKEN_BY + "</div><div style='float:right'><img src='../raised.svg' class='material-icons' alt='Alert'/></div></div>" +
         "<br /><div class='RDTitle pl23'><div style='width:160px;float:left'>" + Role + "</div><div style='width:160px;float:left'> " + Date + "</div></div>" +
         "<div class='CommentTitle pl23'>Comment</div>" +                        
         "<div class='CommentDescription pl23'>" + ActionData[i].DESCRIPTION + "</div>" +
         "<br /><br />";
 tableBody = $("#Audit");
 tableBody.append(markup);

以下是我的CSS代码:

.UserTitleBullet {
  background: #1A9AD4;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  text-align: center;
}
#Audit {
  border-left: 3px solid #1A9AD4;
  margin-top: 24px;
  margin-bottom: 24px;
  overflow-y: auto;
  height: 302px;
}

你能帮助我实现原始设计中的效果吗?

英文:

I have an html block in which I have to add blue color for the border-left of its div and add bullet points at the starting of each content as shown in the below image.

CSS代码用于为每个内容添加左边框和项目符号。

I tried with the below code, but my design doesn't match with the above image. The below image shows what I developed.

CSS代码用于为每个内容添加左边框和项目符号。

Below is my html code for this popup:

&lt;div id=&quot;AuditModal&quot; class=&quot;modal&quot;&gt;
&lt;div class=&quot;modal-content&quot;&gt;
    &lt;div&gt;
        &lt;h1 class=&quot;chart-heading-cls AuditTitle&quot;&gt;Audit&lt;/h1&gt;
        &lt;a class=&quot;modal-close&quot;&gt;&lt;img class=&quot;Close closemodal&quot; src=&quot;~/Close.svg&quot;&gt;&lt;/a&gt;
    &lt;/div&gt;
    &lt;div id=&quot;Audit&quot;&gt;
        &lt;div class=&quot;card-content&quot;&gt;
        &lt;/div&gt;
    &lt;/div&gt;        
&lt;/div&gt;
&lt;/div&gt;

Inside which, I'm appending the content in a loop using jQuery as below:

markup = &quot;&lt;div&gt;&lt;div class=&#39;UserTitle UserTitleBullet pl23&#39;&gt;&quot; + ActionData[i].ACTION_TAKEN_BY + &quot;&lt;/div&gt;&lt;div style=&#39;float:right&#39;&gt;&lt;img src=&#39;../raised.svg&#39; class=&#39;material-icons&#39; alt=&#39;Alert&#39;/&gt;&lt;/div&gt;&lt;/div&gt;&quot; +
         &quot;&lt;br /&gt;&lt;div class=&#39;RDTitle pl23&#39;&gt;&lt;div style=&#39;width:160px;float:left&#39;&#39;&gt;&quot; + Role + &quot;&lt;/div&gt;&lt;div style=&#39;width:160px;float:left&#39;&#39;&gt; &quot; + Date + &quot;&lt;/div&gt;&lt;/div&gt;&quot; +
         &quot;&lt;div class=&#39;CommentTitle pl23&#39;&gt;Comment&lt;/div&gt;&quot; +                        
         &quot;&lt;div class=&#39;CommentDescription pl23&#39;&gt;&quot; + ActionData[i].DESCRIPTION + &quot;&lt;/div&gt;&quot; +
         &quot;&lt;br /&gt;&lt;br /&gt;&quot;;
 tableBody = $(&quot;#Audit&quot;);
 tableBody.append(markup);

Here is my CSS code:

.UserTitleBullet {
  background: #1A9AD4;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  text-align: center;
}
#Audit {
  border-left: 3px solid #1A9AD4;
  margin-top: 24px;
  margin-bottom: 24px;
  overflow-y: auto;
  height: 302px;
}

Can you help me to achieve what is in the original design?

答案1

得分: 1

这是一个关于CSS的问题,不涉及到jQuery或JavaScript。

挑战在于左侧的蓝色进度条具有显示条件,使得简单的border-left不足以满足要求:对于第一项,没有蓝色显示在标记之上;对于最后一项,没有蓝色显示在标记之下。因此,我们需要一种方法来改变标记上方和下方的颜色。

我的解决方案是使用CSS线性渐变背景。我不是用它来渐变从一种颜色到另一种颜色,而是用它来突然从一种颜色变为另一种颜色。

接下来,我将标记置于条的内部,并将其绝对定位,使其直接居中于颜色变化的位置。

我的方法使用修改器类来为列表中的第一项和最后一项具有不同的条样式 - .bar--first.bar--last。它还使用flexbox将条定位在项目内容的左侧,并确保其延伸到内容的整个高度。

#Audit {
  /* ... */
}

.action-item {
  /* ... */
}

.action-item-body {
  /* ... */
}

.bar {
  /* ... */
}

.bar.bar--first {
  /* ... */
}

.bar.bar--last {
  /* ... */
}

.bullet {
  /* ... */
}

.bullet.bullet--active {
  /* ... */
}

HTML代码如下:

<div class="action-item">
  <div class="bar bar--first">
    <div class="bullet "></div>
  </div>
  <div class="action-item-body">
    <!-- ... -->
  </div>
</div>

<div class="action-item">
  <div class="bar ">
    <div class="bullet "></div>
  </div>
  <div class="action-item-body">
    <!-- ... -->
  </div>
</div>

<div class="action-item">
  <div class="bar bar--last">
    <div class="bullet bullet--active"></div>
  </div>
  <div class="action-item-body">
    <!-- ... -->
  </div>
</div>

我还创建了一个使用Handlebars模板构建HTML的fiddle

英文:

This is a CSS question, not a jQuery or JavaScript one.

The challenge is that the blue progress bar at the left has display conditions that make a simple border-left insufficient: For the first item, there is no blue shown above the bullet; and for the last item, there is no blue below the bullet. Therefore, we need a way to change the color of the bar above and below the bullet.

My solution is to use a CSS linear-gradient background. Instead of using it to gently transition from one color to another, I am using it to abruptly change from one color to another.

Next, I put the bullet inside the bar and position it absolutely so that it is directly centered to where the color changes.

My approach uses modifier classes to have different styling of the bar for the first and last items in the list - .bar--first and .bar--last. It also uses flexbox to position the bar to the left of the item content and ensure that it extends to the full height of the content.

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

#Audit {
  height: 302px;
  margin-top: 24px;
  margin-bottom: 24px;
  margin-left: -5px;
  margin-right: -5px;
  overflow-y: auto;
  padding: 0 5px;
}

.action-item {
  display: flex;
}

.action-item-body {
  flex: 1 1 100%;
  padding: 0 20px;
}

.bar {
  background: #1a9ad4;
  position: relative;
  width: 4px;
}

.bar.bar--first {
  background: linear-gradient(to bottom, white 10px, #1a9ad4 10px, #1a9ad4);
}

.bar.bar--last {
  background: linear-gradient(to bottom, #1a9ad4 10px, white 10px, white);
}

.bullet {
  background: #1a9ad4;
  border-radius: 50%;
  position: absolute;
  height: 10px;
  left: -3px;
  top: 7px;
  width: 10px;
}

.bullet.bullet--active {
  box-shadow: 0 0 10px #1a9ad4;
}

<!-- language: lang-html -->

&lt;div class=&quot;action-item&quot;&gt;
  &lt;div class=&quot;bar bar--first&quot;&gt;
    &lt;div class=&quot;bullet &quot;&gt;&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class=&quot;action-item-body&quot;&gt;
    &lt;div&gt;
      &lt;div class=&quot;UserTitle pl23&quot;&gt;John&lt;/div&gt;
      &lt;div style=&quot;float:right&quot;&gt;
        &lt;img src=&quot;../raised.svg&quot; class=&quot;material-icons&quot; alt=&quot;Alert&quot;&gt;
      &lt;/div&gt;
    &lt;/div&gt;
    &lt;br&gt;
    &lt;div class=&quot;RDTitle pl23&quot;&gt;
      &lt;div style=&quot;width:160px;float:left&quot;&gt;Foo&lt;/div&gt;
      &lt;div style=&quot;width:160px;float:left&quot;&gt;Sun Feb 19 2023 10:08:41 GMT-0500 (Eastern Standard Time)&lt;/div&gt;
    &lt;/div&gt;
    &lt;div class=&quot;CommentTitle pl23&quot;&gt;Comment&lt;/div&gt;             
    &lt;div class=&quot;CommentDescription pl23&quot;&gt;Lorem ipsum dolor&lt;/div&gt;
    &lt;br&gt;&lt;br&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;div class=&quot;action-item&quot;&gt;
  &lt;div class=&quot;bar &quot;&gt;
    &lt;div class=&quot;bullet &quot;&gt;&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class=&quot;action-item-body&quot;&gt;
    &lt;div&gt;
      &lt;div class=&quot;UserTitle pl23&quot;&gt;John&lt;/div&gt;
      &lt;div style=&quot;float:right&quot;&gt;
        &lt;img src=&quot;../raised.svg&quot; class=&quot;material-icons&quot; alt=&quot;Alert&quot;&gt;
      &lt;/div&gt;
    &lt;/div&gt;
    &lt;br&gt;
    &lt;div class=&quot;RDTitle pl23&quot;&gt;
      &lt;div style=&quot;width:160px;float:left&quot;&gt;Foo&lt;/div&gt;
      &lt;div style=&quot;width:160px;float:left&quot;&gt;Sun Feb 19 2023 10:08:41 GMT-0500 (Eastern Standard Time)&lt;/div&gt;
    &lt;/div&gt;
    &lt;div class=&quot;CommentTitle pl23&quot;&gt;Comment&lt;/div&gt;             
    &lt;div class=&quot;CommentDescription pl23&quot;&gt;Lorem ipsum dolor&lt;/div&gt;
    &lt;br&gt;&lt;br&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;div class=&quot;action-item&quot;&gt;
  &lt;div class=&quot;bar bar--last&quot;&gt;
    &lt;div class=&quot;bullet bullet--active&quot;&gt;&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class=&quot;action-item-body&quot;&gt;
    &lt;div&gt;
      &lt;div class=&quot;UserTitle pl23&quot;&gt;John&lt;/div&gt;
      &lt;div style=&quot;float:right&quot;&gt;
        &lt;img src=&quot;../raised.svg&quot; class=&quot;material-icons&quot; alt=&quot;Alert&quot;&gt;
      &lt;/div&gt;
    &lt;/div&gt;
    &lt;br&gt;
    &lt;div class=&quot;RDTitle pl23&quot;&gt;
      &lt;div style=&quot;width:160px;float:left&quot;&gt;Foo&lt;/div&gt;
      &lt;div style=&quot;width:160px;float:left&quot;&gt;Sun Feb 19 2023 10:08:41 GMT-0500 (Eastern Standard Time)&lt;/div&gt;
    &lt;/div&gt;
    &lt;div class=&quot;CommentTitle pl23&quot;&gt;Comment&lt;/div&gt;             
    &lt;div class=&quot;CommentDescription pl23&quot;&gt;Lorem ipsum dolor&lt;/div&gt;
    &lt;br&gt;&lt;br&gt;
  &lt;/div&gt;
&lt;/div&gt;

<!-- end snippet -->

I have also created a fiddle that uses a Handlebars templating build the HTML.

huangapple
  • 本文由 发表于 2023年2月19日 18:36:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/75499511.html
匿名

发表评论

匿名网友

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

确定