tjot
(Tomasz)
2021 年9 月 14 日 11:00
1
Hi there,
this is my first try at creating a custom theme, so please be understanding.
I’m trying to customize the category list page, so it should look like this:
The idea is to remove the left border and to add “pills”.
SCSS for adding pills is quite easy:
.category-list tbody .category {
border-left: none;
position: relative;
padding-left: 50px;
&::after {
content: "";
width: 20px;
height: 80%;
position: absolute;
background-color: red;
border-radius: 20px;
top: 50%;
transform: translateY(-50%);
left: 10px;
}
}
but I’m unable to access the category color that is available here: discourse/index.html.erb at 1472e47aae5bfdfb6fd9abfe89beb186c751f514 · discourse/discourse · GitHub
is there an easy way to access that color from CSS?
3 个赞
At the moment there’s not an easy way to do this.
What we could do is move these colors to CSS custom properties instead of setting them inline, which would make the colors easily accessible in any CSS/SCSS. I don’t know when we’ll be able to get to that, but I’ll keep it on my list of to-dos.
7 个赞
tjot
(Tomasz)
2021 年9 月 16 日 06:35
3
That would be awesome
BTW is there any other way to achieve the view I want?
I’ve read that I can override templates for specific parts of Discourse, which template file I must override and how should I do that in my custom theme?
1 个赞
tjot
(Tomasz)
2021 年9 月 17 日 11:45
4
My current workaround is to override components/parent-category-row template.
I’m adding extra div element like this:
{{#unless noCategoryStyle}}
<div class="pill" style="background-color:#{{category.color}}"></div>
{{/unless}}
I’d like to avoid overriding templates because they might change in the future.
@awesomerobot a build-in way to access category color would be awesome
2 个赞
saquetim
(Sérgio Saquetim)
2022 年1 月 7 日 13:01
5
@tjot ,
可以通过 ::after 伪元素的边框来实现您想要的效果的 CSS 技巧。
.category-list tbody .category {
border-left: none;
position: relative;
padding-left: 50px;
> h3:first-child {
border-width: 0;
border-style: solid;
border-color: inherit;
&::after {
content: "";
width: 0px;
height: 70%;
position: absolute;
border-radius: 20px;
border-width: 10px;
border-style: solid;
border-color: inherit;
top: 50%;
transform: translateY(-50%);
left: 10px;
}
}
}
请注意,我已将样式直接应用于标题的 h3 元素,因为它是在应用了内联样式的 td 的直接子元素。因此,如果模板将来移除它,您将不得不调整您的 CSS。
但是,您可以跳过覆盖 components/parent-category-row,正如您想要的。
3 个赞