1

When building forms,I need to indicate which are required. I follow this recipe:

<span class='glyphicon glyphicon-asterisk' style'color:red;font-size:9px;'></span>Label

My goal is to create 1 CSS class that uses the Bootstrap glyphicon class as well as bootstrap's glyphicon-asterisk But also allowing me to combine my own style rules.I have read that people use LESS mixins to do this. However I am asking if it is possible to go another route

The code looking something like this:

.req{
        position:relative;
        top:1px;
        display:inline-block;
        font-family: 'Glyphicons Halflings';
        font-style:normal;
        font-weight:normal;
        font-size: 9px;
        font-color:red;
        line-height: 1;
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
        content:"\2a";


    }

However for some reason this does not work.

This is the two bootstrap classes I wish to combine.

.glyphicon {
  position: relative;
  top: 1px;
  display: inline-block;
  font-family: 'Glyphicons Halflings';
  font-style: normal;
  font-weight: normal;
  line-height: 1;

  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
.glyphicon-asterisk:before {
  content: "\2a";
}

How can I achieve this without using LESS or SASS or any preprocessor So that when using the code:

<span class='req'></span>Label

I will receive the same output as the original one.

Note I do not want to overwrite the existing bootstrap classes. I want to create a new class in my own style.css that makes use of the two bootstrap classes.

1
  • In the solution you've marked, he hasn't combined the two rules in one... You still have two rules, but renamed. Commented Nov 15, 2016 at 12:27

2 Answers 2

1

There is no font-color CSS property, you have to use color. And if you want to use just one class you can use this code.

.req {
  position: relative;
  top: 1px;
  display: inline-block;
  font-family: 'Glyphicons Halflings';
  font-style: normal;
  font-weight: normal;
  line-height: 1;
  font-size:9px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
.req:before {
  content: "\2a";
  color: red;
}
Sign up to request clarification or add additional context in comments.

1 Comment

Was in the process of submitting this answer myself.This seems to work
0

The problem is that you use the 'content: "\2a"' inside the .req however you can assign content only to :before or :after.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.