Is not the first time that I have this "problem". Other times, I did solve it avoiding the problem, but now I want to face it.
The idea is to load some file "myBeautifulStyles.css" with a simple css code like this:
#charset "UTF-8";
/* CSS Document */
h1, h2, h3, p, a {
font-family:Arial, Helvetica, sans-serif;
}
h1 {
font-size:16px;
font-weight:bold;
}
h2 {
font-size:14px;
font-weight:bold;
}
h3 {
font-size:12px;
font-weight:bold;
}
p {
font-size:12px;
font-weight:normal;
}
If I just loaded it as a text and try a StyleSheet.parseCSS() the result is null, the .styleNames returns an empty Array. I'm wondering if is about the text (break-line marks, initial codes...) or something else is missing. The examples around the web are always single line code. It's easy to clean this text and put it in a single line, but will work?
And most important, what's the best approach of this task?
Edit: as required, this code loads de css file trough a php (for avoiding caches):
var ur:URLRequest = new URLRequest(httpBase+"admin_arqs.php");
ur.method = URLRequestMethod.POST;
var Vars:URLVariables = new URLVariables();
Vars.op = "ler";
Vars.url = httpBase+"conteudos_estilos.css";
ur.data = Vars;
var ul:URLLoader = new URLLoader();
ul.dataFormat = URLLoaderDataFormat.TEXT;
ul.addEventListener(Event.COMPLETE, estilos);
ul.addEventListener(IOErrorEvent.IO_ERROR, ioerror);
ul.load(ur);
function estilos(e){
e.currentTarget.removeEventListener(e.type, arguments.callee);
e.target.removeEventListener(IOErrorEvent.IO_ERROR, ioerror);
var Res = JSON.decode(clearRes(String(e.target.data)));
if(Res.erro!="OK"){
msg("Erro: "+Res.msg);
} else {
ini_edit(Res.dados);
}
}
function ioerror(e){
e.currentTarget.removeEventListener(e.type, arguments.callee);
e.target.removeEventListener(Event.COMPLETE, estilos);
msg("Erro de IO!");
}
This part set the stylesheet:
trace("Estilos em string: "+css);
var estilos:StyleSheet = new StyleSheet();
estilos.parseCSS(css);
texto.styleSheet = estilos;
trace("Estilos definidos: "+estilos.styleNames);
The first trace generate the css text is displayed above. The second should display an Array with names. I also try tracing estilos.styleName.length and is zero.
texto is the TextField and css came from the Res.dados.
Seems like this line #charset "UTF-8"; at the head of css file causes the problem. Try to remove it and see if it solving the issue.
Related
Im absolutely new to typo3 and want to set up a simple contact form. So I created a form and added it to the page. My template record looks like this:
page = PAGE
page.typeNum = 0
page.10 < styles.content.get
page.includeCSS {
file1 = fileadmin/templates/css/style.css
}
I can see the form and it works appropriately, but unfortunately my css doesnt do anything.
My style.css looks like this:
p {
font-family: arial;
font-size: 120px;
}
Gotta admit i have no knowledge about CSS too. The changes I made had absolutely no impact on my page. Do these infos help you by any chance? I just have no idea how to fix it on my own, been searching for a solution all day long.
you should learn more about the structure of CSS-files. maybe you inspect some with your browser from other sites.
Then you will notice it is something like:
p {
font-family: arial;
}
For file pathes in typoscript or objects and attributes: don't insert spaces:
:
page.10 < styles.content.get
page.includeCSS {
file1 = fileadmin/templates/css/style.css
}
Your style.css should only contain this:
p {
font-family: arial;
font-size: 120px;
}
... and you'll see the difference ;)
Probably only a copy&paste error, but your TypoScript (aka template record) has spaces where it shouldn't:
...
file1 = fileadmin/templates/css/style.css
...
120px will result in a really big font ;-)
Set the style-definition to the body-tag (so for all elements below the body), not only for the p.
body {
font-family: Arial, sans-serif;
font-size: 12px;
}
You should define the styling of the input fields seperately. With some browsers the inheritance from the body tag definitions seem not to work.
input, textarea { font-size:1.25em; font-family:serif; border:1px solid darkgray; }
Something like that.
Is it possible to fake lowercase letters on a font that has only one letter type, which is ALL CAPS?
This is a sentence on Stack Overflow.
Looks like this when the font is applied:
THIS IS A SENTENCE ON STACK OVERFLOW.
I want the capitals to be a slightly larger font size as in the example below. But without the additional HTML markup.
body {
font-family: Arial, sans-serif;
font-size: 12px;
}
span {
font-size: 1.4em;
}
<span>T</span>HIS IS A SENTENCE ON <span>S</span>TACK <span>O</span>VERFLOW
I'd say the best way to achieve this is with JavaScript (so you could keep the markup dynamic). The JS part that you'd need is this (remember to add .small-caps class to your text elements):
function smallCaps() {
var elements = document.querySelectorAll('.small-caps')
Array.prototype.forEach.call(elements, function(e) {
var text = e.innerHTML.toUpperCase()
e.innerHTML = text.replace(/\b([A-Za-z0-9])/g, '<span class="caps">$1</span>')
})
}
And also remember to add styles for the .caps class:
.caps {
font-size: 1.4em;
}
See it in action either in a fiddle or below:
smallCaps()
// This is what you need:
function smallCaps() {
var elements = document.querySelectorAll('.small-caps')
Array.prototype.forEach.call(elements, function(e) {
var text = e.innerHTML.toUpperCase()
e.innerHTML = text.replace(/\b([A-Za-z0-9])/g, '<span class="caps">$1</span>')
})
}
.caps {
font-size: 1.4em;
}
<h1 class="small-caps">HELLO WORLD</h1>
<h2 class="small-caps">Nifty FOOBAR title</h2>
Sentence case in font-variant: small-caps. The titleCase() function works perfectly with the letters wrapped in <span>s.
I want the capitals to be a slightly larger font size as in the example below. But without the additional HTML markup.
The first 4 comments on OP are correct. I'd like to reaffirm #Pete's comment:
css can only target the first letter or word in a sentence, other than that you will need extra html otherwise how would css know you want the first letter and then the s of stack and o of overflow?
Thus, you will get answers of every variety and each successful answer will have markup in some form or another. With JavaScript, you could have a range determined by a whitelist/dictionary but covering any range of proper nouns would be very limited. Capabilities of that magnitude should be possible with a language like Python, Java, C/C++, etc.
Demo
var main = document.body;
var text = main.textContent;
titleCase(text);
main.style.fontVariant = 'smallCaps';
function titleCase(str) {
return str.replace(/\w\S*/g, function(txt) {
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
});
}
body {
font-family: Arial, sans-serif;
font-size: 12px;
}
span {
font-size: 1.4em;
}
<span>T</span>HIS IS A SENTENCE ON <span>S</span>TACK <span>O</span>VERFLOW
Question:
I need to add the internal style below to a Telerik Report. Please note a0 and a1 are classes.
The style sheet is given below: How do I convert this into an XML style sheet that a telerik report accepts.
Refer to : http://www.telerik.com/help/reporting/style-understanding-style-selectors.html
But the link does not give you detail on how to add a hyperlink selector into an XML style sheet.
CSS below:
a.a0:hover {
text-decoration: underline;
}
a.a1:link {
text-decoration: underline;
}
Below is how I worked around the above issue:
ReportViewer.prototype.OnReportLoadedOld = ReportViewer.OnReportLoaded;
ReportViewer.prototype.OnReportLoaded = function() {
this.OnReportLoadedOld();
var reportFrame = document.getElementById(this.reportFrameID);
var reportDocument = reportFrame.contentWindow.document;
var body = reportDocument.getElementsByTagName("body")[0];
$(".a1", body).css("text-decoration", "underline");
$(".a0", body).css("text-decoration", "underline");
You can achive the hover like this:
$(".a1", body).hover(function() {
$(".a1", body).css("text-decoration", "underline");
}, function () {
$(".a1", body).css("text-decoration", "underline");
});
If I've got elements like this:
A
B
A
C
I know I can use something like
body
{
counter-reset:section;
}
a:before
{
counter-increment:section;
content:counter(section)". ";
}
to get
1. A
2. B
3. A
4. C
but is there a way to get the following?
1. A
2. B
1. A
3. C
ie. uniquely identify all links on a page by prefixing the text with the same number.
Note: hardcoding specific URLs isn't an option, I'm potentially dealing with hundreds of links and don't know the URLs ahead of time.
I realize this would be easy/possible with javascript, I am only interested in CSS-based solutions or an explanation of why this isn't possible with CSS.
Ok, I got what you mean with your question. Just with plain CSS it's not possible (at least not cross-platform..)
If you can use javascript, you have several possibilities.
My preference would be to use a data-attribute to hold the value, for this example I chose data-counter. If you do like this, the CSS becomes trivial:
CSS
a:before
{
content:attr(data-counter)". ";
}
And the Javascript would look like this if you have jQuery:
JS with jQuery
var linkcounter = {};
var counter = 0;
$("a").each(function() {
if (!linkcounter.hasOwnProperty($(this).attr("href"))) {
counter++;
linkcounter[$(this).attr("href")] = counter;
}
$(this).attr("data-counter", linkcounter[$(this).attr("href")]);
});
or like this without jQuery:
vanilla JS
var linkcounter = {};
var counter = 0;
var anchors = document.getElementsByTagName('a');
for(var i = 0; i < anchors.length; i++) {
if (!linkcounter.hasOwnProperty(anchors[i].getAttribute("href"))) {
counter++;
linkcounter[anchors[i].getAttribute("href")] = counter;
}
anchors[i].setAttribute("data-counter", linkcounter[anchors[i].getAttribute("href")]);
}
You can view the version without jQUery here: http://jsfiddle.net/ramsesoriginal/CVW7Y/5
And the version with jQuery here: http://jsfiddle.net/ramsesoriginal/CVW7Y/4
Sadly there is no CSS only way to do this (yet). I hope this helps.
I don't think you can get this behaviour with pure CSS, and you need Javascript. And there are always cases like this:
http://google.com/
http://google.com
google.com
google.com/
www.google.com
You get the point.
In jQuery this is quite trivial, so I'd suggest you use that.
If using jQuery is OK, this can be done by manipulating the :before pseudo element's content:
Demo: http://jsfiddle.net/rwMWx/2/
JS
var labels = [
"1",
"2",
"1",
"3"
// and so on...
];
// OR maybe put in some algo for this sequence
$('a').each(function(i) {
$(this).attr('data-label', labels[i] + '. ');
});
CSS
a:before {
content: attr(data-label);
color: red;
text-align: left;
padding-right: 10px;
font-size: 11px;
display: inline;
}
You could use :contains but I'm not sure how supported it is so you might be better off with JavaScript.
a:contains("A") {
/* Styles here */
}
a:contains("B") {
/* Styles here */
}
EDIT:
Apparently :contains isn't supported at all. I'll leave this up here though so no one else bothers putting it.
You could use :contains in jQuery though and add a class accordingly.
$('a:contains(A)').addClass('CLASS_NAME');
try this code:
var counter = 0, cache = {};
$('a').each(function (i, a) {
a = $(a);
var href = a.attr('href');
var c = cache[href];
if (!c) {
counter++;
c = counter;
cache[href] = c;
}
a.text(c + '. ' + a.text());
});
I'm using jQuery, and that's how it works: http://jsfiddle.net/pDLbQ/
I cannot change attributes of HTMLFlow, i would like to use my defined css for the HTMLFlow and then setAttribute for FontSize in the constructor but nothing changes.
First I extend HMTLFlow like this.
class MyHTMLFlow extends HTMLFlow{
public MyHTMLFLow(width, fontSize){
setStyle("myHtmlFlow");
//here i tried all posibilites but nothing works
setAttribute("fontSize",fontSize);
getElement().getStyle().setProperty("fontSize",fontSize);
//the width works ok
setWidth(width);
}
.myHtmlFlow{
width:250;
font-size:12px;
}
Please help me to make HTMLFlow size defined.
Use setStyleName, I used this and it works:
HTMLFlow newsFlow = new HTMLFlow();
newsFlow .setPadding(7);
newsFlow .setStyleName("plSectionText");
with my css:
.plSectionText {
font-size: 1.3em;
}