set background opacity in css [duplicate] - css

This question already has answers here:
RGB to hex and hex to RGB
(59 answers)
Closed 8 years ago.
I want to make the background of an element semi-transparent in css. I am aware that there is a way to do this using
background-color: rgba(100,100,100,0.5);
but I am trying to dynamically create the css in my rails application, and the variable I am using is a hex code. Is there an equivalent to rgba() that will allow me to use my hex code as a parameter?

You can convert your hex code to rgb here: http://www.javascripter.net/faq/hextorgb.htm
Edit:
Then he can do it in ruby.
Create a function that takes the hex-string, split the string in three parts and convert each part like this:
hex_part = "ff"
hex_part.to_i 16
Edit 2:
hex = "ff88­00"
hex_parts = hex.s­can(/.{1,2­}/)
hex_parts[0] = hex_parts[0].to_i 16 // Will make first part to dec.
hex_parts[1] = hex_parts[1].to_i 16
hex_parts[2] = hex_parts[2].to_i 16
dec = hex_p­arts.join(­",") // Join the parts with a "," and you will get "255,136,0".

if you enclose your element in a div tag with, let's say, class="opac", you can just use jQuery that way:
$('.opac').animate({opacity: .2},500);
this will make your 'opac' object's opacity to 20% when a particular event is triggered, for instance, if a link within a div tagged with Add_Something is clicked:
$('#Add_Something a').click(function() {
$('.opac').animate({opacity: .2}, 500);
});
'500' is just the speed in which the object will become semi-transparent ...

Related

Dynamic font sizing?

Is it possible to adjust the size of the font, depending on the length of the word?
I have a situation where I need to display one word, on one line. But the word can vary between 1 and 10 characters long. I would like the text to be a maximum font-size of 65px, but adjust the more characters are added so that when all 10 are used, the word doesn't get pushed out of view.
The dimensions are always going to be fixed (portrait iPod), just the length of the word is variable.
Any CSS ninjas out there mind teaching an old dog a new trick :)
you can use javascript to change font-size according to string length -
var str = "Hello World!";
var n = str.length;
if(n>10){
document.getElementById("id").style.font = "italic bold 20px arial,serif";
}
hope this help..

Multiline title on a JavaFx Chart

Is there some means - short of extending the JavaFX charting base class(es) - to specify a multi-line title string?
As seen in the screenshot the title is the only element 'wanting' more space.
I had seen some references to using a newline '\n' and even a pipe character '|' in the string but they apparently do not work for the title.
I just threw this in a sample I had and it worked.
chart.setTitle("really long title...........\n.............and some more ");
Label l = (Label)chart.lookup(".chart-title");
l.setWrapText(true);
The \n sets the break point if I don't want it at the limit.
As you can see it's just a Label, the hard part is getting it.
You can also use a css file with the selector. I think it's already centered.
.chart-title{
-fx-wrap-text : true;
-fx-alignment : center;
}

How can I display unicode in QGraphicsTextItem? [duplicate]

This question already has answers here:
How to specify a unicode character using QString?
(4 answers)
Closed 7 years ago.
I would like to be able to display Unicode in QGraphicsTextItem (or a subclass of it).
The only way to set text in QGraphicsTextItem seems to be
setPlainText(text);
Trying
setPlainText(QString::fromUtf8("Caf\x00e9 Frap\x00e9"));
or
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("utf8"));
setPlainText("Café Frapé");
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("utf8"));
setPlainText("Caf\x00e9 Frap\x00e9");
I get:
Caf? Frap?
It seems that no matter what I do (which I am not sure is correct) I do not get the output right...
Do QGraphicsTextItem support unicode ? Is maybe the setPlainText function at fault - but then what are the alternatives ? (I looked into setDocument but it also sets plain text...)
Edit - copying the special characters inside the QGraphicsTextItem works, once on screen, but still unable to place any unicode from code.
In a class inheriting QGraphicScene, I used:
QString text(QString::fromUtf8(xt.text));
...
QGraphicsTextItem *t = addText(text = text.replace("\\n", "\n"), font);
The dot source is utf8:
digraph so {
Café -> Frapé
}
And the rendering:
You can find here the C++ code.
I think you should use the
QGraphicsTextItem item.
item.setHtml( "Café Frapé" );
function instead of the mentioned. Read this QGraphicsTextItem::setHtml.

Using netbeans digitalclock sample

I am a Java beginner with a question about the operation of the Digitalclock.java example in Netbeans 8.0.2
I want to alter the display to show only Hours and Minutes and change the color. I have found within the code a way to eliminate the display of the Seconds digits and change the color. What I can't do is get rid of the ":" or center the display.
1) Where is the ":" being generated from?
2) How would I center the display?
Thank you,
The colon ":" in this case is not an actual character rather it is being generated by using multiple instances of the java circle class and can be found in line 114 - 117 of the DigitalClock.java file. Centering the the new four digit clock can be accomplished by changing the clock.setLayoutX at line 78. – Six just now edit

How to Convert Qcolor value to hex value?

I have implemented a QColor dialog box which opens on certain condition. To get the selected color after final selection I use the method selectedColor() which returns the value in QColor. When I print that value, it's like this:
<PyQt4.QtGui.QColor object at 0x01DD7880>
I want color value in hex value like this: #DFDFDF (for grey). If it's not hex, correct me.
Is there any function to convert that?
Any suggestions welcome.
You need to print selectedColor().name() to print the actual color value in hex. See the QColor Documentation
To amplify a bit, maybe confuse, maybe clarify... (For Python newbies)
color = QColorDialog.getColor(pWidget.textBackgroundColor(), pWidget, 'Get Text Highlighting Color')
The above will return a QColor using the QColorDialog, for those of us who don't want to be stuck with named colors like 'Blue', 'red', green etc.
fg = color.name()
In this case I am converting the QColor to a string HEX for use in a style sheet.
Widget.setStyleSheet('background-color: ' + bg + ';color: ' + fg)
This is how such a converted value can be used in a style sheet.
Note how to concatenate more than one stylesheet attribute. Also, side note, sometimes changing one attribute cancels previous changes to others.

Resources