Making tags look like real world tags

css

(Harry) #1

I was looking for having CSS for tags like this: 18%20PM

But my current tags look like this:

See txpower and alfa are tags.

Here’s the CSS I am using:

.discourse-tag.box {
    border: 1px solid #595959;
    border-radius: 3px;
    background-color: transparent;
    padding: 1px 6px;
    font-weight: bold;
}

For the sake of differentiability, I wanted my tags to look like real tags, but CSS from the internet is breaking the discourse’s CSS in unimaginable ways. and I just can’t get it right. Can anyone help with the CSS changes I need?


(Daniela) #2

I was looking to use something similar years ago, you can try to use this and customize it as you wish

.discourse-tag.box {
  position: relative;
  display: inline-block;
  text-decoration: none;
  background-color: #bfbfbf !important;
  height: 26px;
  line-height: 26px;
  padding: 0 20px 0 23px;
  margin: 0 10px 0 0;
}
.discourse-tag.box::before {
  position: absolute;
  content: '';
  background: #fff;
  border-radius: 100%;
  height: 6px;
  left: 10px;
  width: 6px;
  top: 10px;
  box-shadow: inset 0 1px rgba(0, 0, 0, 0.25);
}
.discourse-tags .discourse-tag.box::after {
  position: absolute;
  content: '';
  background: #fff;
  border-bottom: 13px solid transparent;
  border-left: 10px solid #bfbfbf;
  border-top: 14px solid transparent;
  right: 0;
  top: 0;
}
a.discourse-tag.box {
    color: #fff !important;
}

Almost certainly if you have plugins that add elements to the title, as the voting plugin you will need to make corrections.


(Harry) #3

Awesome! I made some edits like colours and width equal to category and here is my CSS for that:

.discourse-tag.box {
    position: relative;
    display: inline-block;
    text-decoration: none;
    background-color: #646464 !important;
    border-radius: 3px 0 0 3px;
    height: 21px;
    line-height: 21px;
    padding: 0 13px 0 22px;
    margin: 0 10px 0 0;
}
.discourse-tag.box::before {
    position: absolute;
    content: '';
    background: #000;
    border-radius: 100%;
    height: 6px;
    left: 8px;
    width: 6px;
    top: 8px;
    box-shadow: inset 0 1px rgba(0,0,0,0.25);
}
.discourse-tags .discourse-tag.box::after {
  position: absolute;
  content: '';
  background: black;
  border-bottom: 11px solid transparent;
  border-left: 10px solid #646464;
  border-top: 10px solid transparent;
  right: 0;
  top: 0;

}
a.discourse-tag.box {
    color: #d4d4d4 !important;
}

Note that I disabled my earlier CSS Completely as it was conflicting with the newer one. and made it honor the black theme :slight_smile:

Here is what it looks like:

53%20PM

Although I did want to have the triangle on the left hand side which is more real-like and gives a sense of real tag. which is tied from the triangular end and flat on the other end. But nevermind. I’ll learn some CSS and would post update to it.

Thanks a lot for your code @Dax! You are awesome! :smile:


(Markus) #4

Nice CSS code snippet :slight_smile: Thanks!

I experienced a minor issue with my css code: Not sure why, but with Safari and Chrome (!) …

  • … on my iPhone 8+, all of the tags have a thin line on the right next to the flap.
  • … on my iPad mini 4, only some thin lines will appear on the right next to the flap. (e.g. tags with 2 characters)
  • … on my Mac everything is just fine

It seems, the “after” css container is repeating itself. How can I fix this?

I made them a litte bit thinner … 03

See CSS Code
.discourse-tag.box {
    position: relative;
    display: inline-block;
    text-decoration: none;
    font-weight: normal;
    background-color: #e28a54 !important;
    border-radius: 3px 0 0 3px;
    height: 20px;
    line-height: 20px;
    padding: 0 13px 0 21px;
    margin: 0 10px 0 0;
}
.discourse-tag.box::before {
    position: absolute;
    content: '';
    background: #ffffff;
    border-radius: 100%;
    height: 6px; 
    left: 7px;
    width: 6px;
    top: 7px;
    box-shadow: inset 0 1px rgba(0,0,0,0.25);
}
.discourse-tags .discourse-tag.box::after {
  position: absolute;
  content: '';
  background: white;
  border-bottom: 11px solid transparent;
  border-left: 10px solid #e28a54;
  border-top: 10px solid transparent;
  right: 0;
  top: 0;

}
a.discourse-tag.box {
    color: #fff !important;
}

(Daniela) #5

Just delete the line border-radius: 3px 0 0 3px;
This fix the thin line problem on IOS (and Chrome) for short tags (thanks to @Simon_Cossar that help me to debug with his Mac).

I will update the code above

PS. I have no Iphone, so check if the fix works even there


(Harry) #6

That’s exactly my issue. In some lines with 2 tags, I see a flap on my iOS device, both safari and chrome. But seems to work fine on on MacOS.

Apart from that, can you change the direction of the triangle in the Tag, like this: 18%20PM I tried my beginner CSS skills but couldn’t achieve that. Can you help me out with that?

I changed color of my code to Red (my theme color) and it looks awesome as yours :slight_smile:
But using colours on tags drives focus on tags constantly rather than the titles which are more important. So I’d still keep the tags in kind of background and content in front.

Here is what it looks like: 24%20AM
Just in case somebody else want a red tag on black theme. here is my CSS code for that:

CSS for Red Tag on Black Background

.discourse-tag.box {
position: relative;
display: inline-block;
text-decoration: none;
font-weight: normal;
background-color: #9c0c16 !important;
border-radius: 3px 0 0 3px;
height: 20px;
line-height: 20px;
padding: 0 13px 0 21px;
margin: 0 10px 0 0;
}
.discourse-tag.box::before {
position: absolute;
content: ‘’;
background: #000;
border-radius: 100%;
height: 6px;
left: 7px;
width: 6px;
top: 7px;
box-shadow: inset 0 1px rgba(0,0,0,0.25);
}
.discourse-tags .discourse-tag.box::after {
position: absolute;
content: ‘’;
background: #000;
border-bottom: 11px solid transparent;
border-left: 10px solid #9c0c16;
border-top: 10px solid transparent;
right: 0;
top: 0;

}
a.discourse-tag.box {
color: #fff !important;
font-weight: bold;
}


(Harry) #7

Commenting the code did help. but we loose the beauty of the tag.
look: image

flat edges :expressionless:


(Chris Beach) #8

Alternatively, to restyle the bullet to a tag icon:

.discourse-tag.bullet::before {
  font-size: 1.0em;
  top: 0em;
  margin-right: 3px;
  content: "\f02b";
  color: #ccc;
}

for:

21


(Harry) #9

That’s also quite cool.
It is space saver and doesn’t drive focus away from the main content!
Thanks for sharing :slight_smile:

For people who might discover issue. Just change the tag type from box to bullet in Admin > Settings