-2

My HTML code looks as follows:

<div class="row">
    <div class="col-md-6 col-sm-6 col-xs-6">
        <section class="widget index">
            <header>
                <h4>
                    <i class="fa fa-bars"></i> Status word <small> </small>
                </h4>
            </header>                                           
            <div class="body">
                - Output A: <div class="dash_data_A"></div>
                - Output B: <div class="dash_data_B"></div>
                - Output C: <div class="dash_data_C"></div>

The display on the website looks as follows:

- Output A:
false
- Output B:
true
- Output C:
false

First wish: The output value should be on the same line (avoid line break), like this:

- Output A: false
- Output B: true
- Output C: false

Second wish: The output value should change the font color of false (red) and true (green).

Do I have to implement that in the css-file? Or in the js? Or even both? What do you recommend?

3
  • We need a demo including your CSS.
    – Paulie_D
    Commented Dec 19, 2014 at 13:31
  • For first --- use wrapper div for each output and the value, for the value use a span tag instead of div ---- For second on JS assign a class based on the value. Try that and if you have problems make a good question including all the code
    – DaniP
    Commented Dec 19, 2014 at 13:33
  • @Kevin try my answer..i have added both css and js solutions Commented Dec 19, 2014 at 14:07

4 Answers 4

5

By default, a div is a block level element, which means it takes up the entire width and causes elements to continue on the next line, under it...which is what you're seeing. So to fix that, you need to change the display type of the divs that need to be inline OR use a different tag that is inline by default, such as span.

.dash_data_A,
.dash_data_B,
.dash_data_C {

    display: inline-block;

}

To handle the color part, I would apply a class depending on what the result is, like this:

<div class="dash_data_A false"></div>
<div class="dash_data_B true"></div>
<div class="dash_data_C false"></div>

And then the CSS:

.true {
    color: green;}

.false {
    color: red;}
0

Add the following CSS:

.dash_data_A, .dash_data_B, .dash_data_C, .title {
  float: left;
}

And then wrap the "output"-stuff in a div as well.

A quick JSfiddle, it's not perfect, but it functions. You should make it perfect yourself :)

0

You can also simplify the code too.

<div class="dash_data false"></div>
<div class="dash_data true"></div>
<div class="dash_data false"></div>

.dash_data {
 display: inline;
 //float: left;
}
0

1. one option using only css is

CSS

.dash_data_A, .dash_data_B, .dash_data_C, .title {
    float: left;
}
.false{
    color:red;
}
.true{
    color:Green;
}

DEMO FIDDLE

2. second option

if the true,false values are generated dynamically use jquery

FIDDLE JS DEMO

JQUERY

var option = "";
$(function () {
    $('.option').each(function () {
        option="";
        option = $(this).html();
         alert(option);
        if (option.trim() == 'true') {
            $(this).addClass('true');
        } else {
            $(this).addClass('false');
        }

    });
});

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.