-1

I am creating a WP Widget that draws a barcode. I can generate a barcode that works just fine when I just place it on an admin page (à la Hello Dolly!).

enter image description here

The tags that make up the barcode explicitly set the height and width of the bars and spaces and everyone is happy.

When I apply the same plug-in code to a widget, the width is left alone, but the height is scaled down for some reason.

enter image description here

The result is a barcode approximately 1 pixel high which doesn't scan right. I am interested in finding out why / how my explicit styling is being overridden in the widget class.

EDIT: The only css contained in the plug-in is here:

// We need some CSS to position the paragraph
function barcode_css() {
        $x = is_rtl() ? 'left' : 'right';

        echo "
        <style type='text/css'>
        #barcode {
                float: $x;
                padding-$x: 15px;
                padding-top: 5px;
                margin: 0;
                font-size: 11px;
        }
        </style>
        ";
}
Brian Anderson
  • 1,661
  • 1
  • 17
  • 27

2 Answers2

0

Have you tried adding !important to your css?

  • I got it working. Your suggestion put me on the right path, but I did not need to use !important. I used inline style instead of trying to set the height and width attributes directly and relying on css to sort things out. – Brian Anderson Jun 16 '17 at 15:12
  • This is not really the best answer to the question. Try to avoid ```!important``` in your style, unless it's the only possible way. Read about it: https://stackoverflow.com/questions/3706819/what-are-the-implications-of-using-important-in-css#answer-3706876 – Marten Jun 16 '17 at 15:36
0

It is working now. Instead of trying explicitly set attributes for height and width I used inline CSS according to this answer: https://stackoverflow.com/a/15000373/769938

Once I adjusted my widget's php it started working.

enter image description here

Brian Anderson
  • 1,661
  • 1
  • 17
  • 27