英文:
CSS Code for Div Left-Border with Bullet Points for each Content
问题
我必须在div
的border-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.
I tried with the below code, but my design doesn't match with the above image. The below image shows what I developed.
Below is my html
code for this popup:
<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>
Inside which, I'm appending the content in a loop using jQuery
as below:
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);
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 -->
<div class="action-item">
<div class="bar bar--first">
<div class="bullet "></div>
</div>
<div class="action-item-body">
<div>
<div class="UserTitle pl23">John</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">Foo</div>
<div style="width:160px;float:left">Sun Feb 19 2023 10:08:41 GMT-0500 (Eastern Standard Time)</div>
</div>
<div class="CommentTitle pl23">Comment</div>
<div class="CommentDescription pl23">Lorem ipsum dolor</div>
<br><br>
</div>
</div>
<div class="action-item">
<div class="bar ">
<div class="bullet "></div>
</div>
<div class="action-item-body">
<div>
<div class="UserTitle pl23">John</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">Foo</div>
<div style="width:160px;float:left">Sun Feb 19 2023 10:08:41 GMT-0500 (Eastern Standard Time)</div>
</div>
<div class="CommentTitle pl23">Comment</div>
<div class="CommentDescription pl23">Lorem ipsum dolor</div>
<br><br>
</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 class="UserTitle pl23">John</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">Foo</div>
<div style="width:160px;float:left">Sun Feb 19 2023 10:08:41 GMT-0500 (Eastern Standard Time)</div>
</div>
<div class="CommentTitle pl23">Comment</div>
<div class="CommentDescription pl23">Lorem ipsum dolor</div>
<br><br>
</div>
</div>
<!-- end snippet -->
I have also created a fiddle that uses a Handlebars templating build the HTML.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论