This is my html code:
<label for="tx_alterneteducationcatalog_subscriberadd[newSubscriber][gender]"
class="error" id="tx_alterneteducationcatalog_subscriberadd[newSubscriber]
[gender]-error">This field is required.</label>
this is my css code:
#tx_alterneteducationcatalog_subscriberadd[newSubscriber][gender]-error{
display: none !important
}
For some reason the float right not working. Even in the firebug it is not showing that I put a float:right !important. Why?
The selector
#tx_alterneteducationcatalog_subscriberadd[newSubscriber][gender]-error
is not valid. The square brackets denote attribute selectors, so what you have is
#tx_alterneteducationcatalog_subscriberadd
[newSubscriber]
[gender]
... followed by, quite literally, a syntax error in -error because an identifier is not expected there.
If you escape all the square brackets, the entire ID selector will be parsed correctly:
#tx_alterneteducationcatalog_subscriberadd\[newSubscriber\]\[gender\]-error
... but I prefer just using an attribute selector to match the ID instead:
[id="tx_alterneteducationcatalog_subscriberadd[newSubscriber][gender]-error"]
You could also select by the for attribute and the .error class rather than id, but it's not clear to me why a validation error would be marked up in a label element in the first place. The text, for one, says absolutely nothing about what field it is "labeling" exactly; all it says is that it's required.
I just noticed there's a line break in your id attribute. If this is how your actual markup appears exactly, then your markup is invalid. That being said you should still be able to account for it in your CSS with the escape sequence \a (see section 4.3.7 of the spec):
#tx_alterneteducationcatalog_subscriberadd\[newSubscriber\]\a\[gender\]-error
[id="tx_alterneteducationcatalog_subscriberadd[newSubscriber]\a[gender]-error"]
Because [] is used to denote attributes in CSS selectors, you cannot use them as classnames or ids unless you use the attribute selector to match the string as such:
*[id="a[b]-c(d)"]{ color: yellow; }
<div id="a[b]-c(d)">Selected</div>
This is not recommended and it's better to use classes for this and restrain them to the relevant conventions.
I finally managed to make this work by using this code:
label[for="tx_alterneteducationcatalog_subscriberadd[newSubscriber][gender]"]{
float: right !important
}
and there was a FTP issue. After uploading it puts me some weird characters. After removing it. It works
Square brackets are not valid characters for css identifiers: http://www.w3.org/TR/CSS21/syndata.html#characters
Related
Today i read:
Don’t use single quotation marks around paths for images. When setting
a background image, resist the urge to surround the path with quote
marks. They’re not necessary, and IE5/Mac will choke.
Meaning instead of:
<img src="pic_mountain.jpg" title="Mountain-View" style="width:304px;height:228px;">
this:
<img src=pic_mountain.jpg title=Mountain-View style=width:304px;height:228px;>
should be perfectly fine. Is this true? No diffrences? It does work normally on my end. Is it about cross-browser compatibility?
Source for the info: Source
The quote is talking about CSS, not HTML.
These all mean the same in CSS:
background-image: url(/path/to/foo);
background-image: url("/path/to/foo");
background-image: url('/path/to/foo');
… except only the first one works in IE5/Mac … which hasn't been supported for a very long time, so isn't worth worrying about.
The two versions of HTML in your question are (for reasons unrelated to the quote you included) also equivalent.
The common view about best practise is that you should always place quotes around HTML attribute values. It saves having to remember which characters that you might want to place in an attribute value turn the quote from optional into required. Space is an obvious example of such a character.
It is valid html but if you then use an attribute that is not valid for an element it will then through an error this link should help.
unquoted attributes
Here is the div:
<div class='something' id='1'>
I got 9 of them with different positions on page so in the .css file I do:
div#1.something {
code...
}
And the thing is that it won't work, I know this is the proper selector but I have also tried div.something#1 and it also doesn't work, as expected. I think there is something wrong with ID as a number, should I change it or there is a way?
Although it's allowed to set a class or id to begin with a digit in HTML5, but it's not allowed in CSS, see the spec:
HTML5: 3.2.5.1 The id attribute
... There are no other restrictions on what form an ID can take; in particular, IDs can consist of just digits, start with a digit, start with an underscore, consist of just punctuation, etc. ...
CSS: 4.1.3 Characters and case
... they cannot start with a digit, two hyphens, or a hyphen followed by a digit. Identifiers can also contain escaped characters and any ISO 10646 character as a numeric code ...
i.e.
<div id="1"> is valid HTML, but you cannot target it with #1 {...} in CSS.
However, you can use [id="1"] {...} or escape it #\31 {...}
Please try this:
You can call either by class or ID.
div.something {
code...
}
or
div#1 {
code...
}
Change id="1" to id="one" since you cannot use numbers in CSS to select an id or class. Then just use div#one { // CSS Here } since you don't really need to include the class. After all you can only have one id with a specific name per page.
Is there any way to shorten a HTML element tag like this:
<input id=ctl00_ctl32_g_9bd32d9e_a30e_48f8_af0e_4c4b7e8ba1f5_createSuggestion>
In CSS so that I don't have to reference the entire thing and just use the createSuggestion part of it like this:
input createSuggestion{
margin-left:10%;
}
For instance, when producing a SQL query, sometimes a 'like %createSuggestion' would be used.
Any ideas?
You could achieve that by attribute selector as follows:
input[id$="createSuggestion"] {
margin-left: 10%;
}
6.3.2. Substring matching attribute selectors
[att$=val] Represents an element with the att attribute whose value
ends with the suffix "val". If "val" is the empty string then the
selector does not represent anything.
Add ClientIdMode="Static" in your server-side control to prevent that entirely.
Relevant codepen: http://codepen.io/anon/pen/ocptF/
EDIT: The codepen uses Jade, and thus messes a few things up. I was not aware of this when starting this question.
Essentially, I thought CSS attr() would copy over an HTML attribute literally, but that is not the case.
I'd like to use the CSS attr function to fill in the content for some pseudoelements. However, it prints out 004 when the HTML attribute is set to \f004, and 08fa when \f08fa.
Relevant lines:
HTML:
<div class="zoomfade" data-fill='\f004' data-unfill='\f08a'></div>
CSS:
.zoomfade:before {
content: attr(data-unfill);
position: absolute;
}
.zoomfade:before {
content: attr(data-fill);
position: absolute;
}
Thanks!
Escape sequences in CSS are only treated specially in CSS syntax. When you specify it in an HTML attribute value then use that value in CSS attr(), it is taken literally. From the CSS2.1 spec:
attr(X)
This function returns as a string the value of attribute X for the subject of the selector. The string is not parsed by the CSS processor. [...]
Since you're specifying character codes in HTML attribute values, you can either use HTML character references, entity references or the Unicode characters themselves. It's worth noting that the two character codes you have do not appear to be valid, however, so they may not work at all.
EDIT: [...] Essentially, I thought CSS attr() would copy over an HTML attribute literally, but that is not the case.
It copies the attribute value according to the DOM, which may be different from how it is represented in the source, e.g. the source markup, or the script that is generating the element.
For example, if the source is represented in raw HTML markup, then as I mention above, you will need to use HTML character escapes, because HTML is parsed by an HTML parser. If the elements are generated using a JS-based template engine such as Jade, then the character escapes take the form of \u followed by the hexadecimal code-points. In both cases, the respective parsers will translate the escape sequences into their representative characters, and the characters themselves are what is stored in the DOM as part of the attribute value.
Of course, again there's always the alternative of just using the Unicode characters directly. If your source files are all encoded as UTF-8, you should have no problem using the characters directly.
I have some markup which contains the firebug hidden div.
(long story short, the YUI RTE posts content back that includes the hidden firebug div is that is active)
So, in my posted content I have the extra div which I will remove server side in PHP:
<div firebugversion="1.5.4" style="display: none;" id="_firebugConsole"></div>
I cant seem to get a handle on the regex I would need to write to match this string, bearing in mind that it won't always be that exact string (version may change).
All help welcome!
Regex is not the best tool for the job, but you can try:
<div firebugversion=[^>]*></div>
The […] is a character class. Something like [aeiou] matches one of any of the lowercase vowels. [^…] is a negated character class. [^aeiou] matches one of anything but the lowercase vowels.
The * is the zero-or-more repetition. Thus, [^>]* matches a sequence of anything but >.
If you want to target the id specifically, you can try:
<div [^>]*\bid="_firebugConsole"[^>]*></div>
The \b is the word boundary anchor.
Match this regex -
<div.*id="_firebugConsole".*?/div>
I would suggest this:
\<div firebugversion="(.+)" style="(.+)" id="(.+)"\>
Then you have three groups:
firebugversion
style
id
This one is a little more complicated, and probably not perfect, but it will:
Match any div containing the attribute firebugversion
Match the firebugversion attribute no matter which order attributes appear in the tag
Match the div, even if it contains content or spacing between it and its closing tag (i've seen the firebug tag with a   ; tag inside it before) Note: it does lazy matching so it will only match the next tag, rather than the last it finds in the document
<(div)\b([^>]*?)(firebugversion)([^>]*?)>(.*?)</div>