CSS button not styling - asp.net

I must be missing something obvious, but can someone explain what I'm doing wrong with my CSS? I would like all buttons to have a certain format, except a few. I was expecting to use CssClass in order to override the few that should be different, but they all seem to use the standard one.
My CSS:
.btn
{
border:none;
background-color:red;
}
input[type="submit"]
{
border: 2px solid black;
background-color:green;
}
All the buttons take the second value (green background, with a border). However, I have this button:
<asp:Button ID="btnAdd" CssClass="btn" runat="server" Text="Add" />
I was expecting this to have no border, and a red background, but it's the same as every other button.
Any ideas what I'm doing wrong?
Thanks

The type='button' rule probably beats the btn rule in specificity. You could use !important but that won't work in IE < 8 and is bound to give problems in the long run.
Try this first:
input[type="submit"].btn
{
border:none;
background-color:red;
}

Place your .btn below you input[type="submit"] rule. If that still does not work add !important.
.btn
{
border:none !important;
background-color:red !important;
}
See here for CSS precedence: http://www.w3.org/TR/CSS2/cascade.html

It's also worth noting that attribute selectors such as input[type="submit"] won't work in IE, they do in FF though.

Related

Changing other elements in CSS

I have always wonder why this wouldn't work as it would make so much sense.
CSS:
#button1:hover {
background: green;
#button2 {
background: red;
}
}
HTML
<button id="button1"></button>
<button id="button2"></button>
If I hover over Button1, Button2's background should also change.
Is there a workaround to this other than the use of Javascript?
You can use the adjacent selector,
#button1:hover {
Background: green;
}
#button1:hover + #button2 {
Background: red;
}
Have a look at all the css selectors: http://css-tricks.com/almanac/
Oh by the way it's only possible to apply css on hover to elements after the hovered element. Parent elements and elements before the hovered element cannot be styled with css on hover. It's a limitation of css.
This can be done but CSS lacks the ability to provide powerful conditional statements. However if you look into SASS CSS LESS it is starting to happen.

Weird :active behavior in IE8

I'm having an issue with IE8 where when an image is clicked inside of a link, the :active selector is not being triggered by IE.
Example:
HTML:
<img src="http://www.w3schools.com/images/pulpit.jpg">
CSS:
a {
display:inline-block;
padding:10px;
border:1px solid #F00;
}
a:hover {
border-color:#0F0;
}
a:active {
border-color:#00F;
}
Live demo: jsFiddle
When clicking the area around the image, the link acts normally, but when clicking the image itself, it fails to update.
Any ideas on why this is happening and if there are any workarounds? Since it is mostly working I don't mind appending some JavaScript if needed.
It may work better if you put the states on the img, but I can't get rid of the outline. http://jsfiddle.net/wSp7J/3/

Display first letter only

Lets say this markup:
<div id="socialMedia">
<a class="Twitter">Twitter</a>
</div>
What i want is only to be visible the first letter of the text (in this case, just a T)
(Actually I won't end up using it but I am curious about this; sure can be helpfull later)
So this was my a attempt:
#socialMedia .Twitter{
display:none;
}
#socialMedia .Twitter:first-letter {
display: block !important;
}
I was able to check that it won't achieve it. Question is why? and is there some work-around this?
-EDIT-
We are looking for IE=+7/8 version capable solutions..
Salut
Try something like this:
.Twitter {
font-size: 0;
}
.Twitter:first-letter {
font-size: 12px;
}
<div class="Twitter">Twitter</div>
Maybe this is not the best solution, but it works.
Edit: Disclaimer: this does not work according to comments. Please don't use as-is without checking it fits your needs.
If you check the specification for the :first-letter pseudo-element, you'll notice the following:
The :first-letter pseudo-element must select the first letter of the first line of a block, if it is not preceded by any other content (such as images or inline tables) on its line.
The important word here is "block."
You are trying to use the pseudo-element on an <a/> tag with class of Twitter. By default, anchor tags are inline elements (not block level elements).
For your given markup, one solution to your problem would be to style the anchor this way:
.Twitter {
display:block;
visibility:hidden;
}
.Twitter:first-letter {
visibility:visible;
}​
I'm not sure exactly what you are going for, but that is good enough for experimental purposes. Check out a demo here: http://jsfiddle.net/H7jhF/.
Another way is to use color: transparent
.twitter{
display: block;
color: transparent;
}
.twitter:first-letter{
color: #000;
}
<div id="socialMedia">
<a class="twitter">Twitter</a>
</div>
JSFiddle
However, this won't work for lte IE8.
References:
IE7 IE8 IE9 color:transparent property
color: transparent is not working in Internet Explorer
What you're doing is like hiding a parent element and trying to show one of its children, it won't work because the parent's style overrides it. The parent element also has to be a block level element for it to work. Like a div or p tag, or display: block; on the a tag.
Here's something using color:
HTML
<div id="socialMedia">
<a class="Twitter">Twitter</a>
</div>
CSS
body {
background-color:#FFF;
}
.Twitter{
display: block;
color:#FFF;
}
.Twitter:first-letter {
color:#000;
}
shoot the content off the page and show the letter using dynamic content:
.twitter{
text-indent:-9999px;
display:block;
position:relative;
}
.twitter:before,.twitter::before{
content:"T";
position:absolute;
width:10px;
height:15px;
z-index:100;
text-indent:9999px;
}
at play in this fiddle:
http://jsfiddle.net/jalbertbowdenii/H7jhF/67/
Why not just use JavaScript and split the string into an array and use the first item in the array. Or charAt()
The pure-CSS answers use visibility and color tricks to hide the remaining letters, but they are still present and affecting layout. It could cause layout issues, e.g. if you wish to float the element and put something beside it.
I found a funny way to do this without hidden elements. The trick is to shrink the entire word down to almost nothing and then blow up just the first letter. It's a bit like OP was trying to do, but it works because it's operating on a continuous spectrum rather than display: none which just shuts down anything inside it. (Kind of an analogue > digital situation.)
Demo
HTML:
<div>Ding Dong</div> and other stuff
CSS:
div {
font-size: 0.0000016px;
float: left;
}
div::first-letter {
color: red;
font-size: 10000000em;
}
Result:
Here's what I do:
.Twitter{
display:block;
width:1ch;
overflow:hidden;
white-space: nowrap;
}

IE6 <input type='text' /> width issue

I have an annoying IE6 layout bug
This screenshot shows the problem:
Problem: Text inputs i.e. <input type='text' /> are wrong size.
The text inputs are a bit wonky. They are supposed to be 248px wide (like the textarea) and on the same horizontal level as their labels. All other browsers appear to obey the following code but our friend IE6 doesn't
.simple_form input[type='text'],.simple_form input[type='email'],.simple_form textarea
{
width:240px;
border:1px solid #ccc;
padding:3px
}
I dunno what I'm doing wrong here and it's driving me nuts. The page in question is here. The inputs are significantly wider than 248px in IE6. Does IE6 have a problem understanding input[type='text'] when used in CSS?
Can post more code
IE6 doesn't support the attribute selector in CSS.
You will to select those elements using an IE6 compatible way, such as classes.
In addition to the previous answers, also remember to keep said css selector in a separate selector. So for example,
input[type="text"], input.text {
color: red;
}
This will be completely ignored by IE6. But...
input[type="text"] {
color: red;
}
input.text {
color: red;
}
should work.
IE6 does not support CSS attribute selectors. Try a selector like the following instead:
.simple_form input.text {
...
}
In addition, remember the differences in the box model for IE6.
Yes our red headed step child, in my experience does not resolve well with attributes. Instead do something like
.input {/*your styles*/}
Not only will it be browser adaptable but with a css reset you will find it browser persistent as well.

CSS :hover in Sharepoint works in Chrome but not IE8( or 7 compat)

I have a DataFormWebPart rendering:
<th class="MenuItem">
<xsl:attribute name="onclick" >window.location="<xsl:value-of select="substring-before(#URL, ', ')" ></xsl:value-of>"</xsl:attribute>
<xsl:value-of select="#Comments" disable-output-escaping="yes" />
</th>
With CSS like:
.MenuItem
{
background-color:aqua;
border: thick red solid;
border-top: 0;
border-bottom: 0;
padding:.25em;
padding-left:1em;
padding-right:1em;
}
.MenuItem:hover
{
background-color:green;
}
In IE the :hover is getting ignored, Chrome it works.
If I create the above in a simple html file is works as expected in IE.
My theory is that WSS is messing with the CSS somehow....
Anybody know what or how to trace what is messing with the :hover selector?
the :hover is not accepted on all elements by all browsers. To fix this you have to either place an "a" tag inside of .menuitem and use .menuitem a and and .menuitem a:hover, or use javascript to perform something on a hover
you could easily use jQuery's .hover function to perform an action.
Since many pointed out that only a few elements allow the :hover pseudo in IE, here's how the code would look:
<th class="MenuItem">
<a href="#">
<xsl:attribute name="onclick" >window.location="<xsl:value-of select="substring-before(#URL, ', ')" ></xsl:value-of>"; return false;</xsl:attribute>
<xsl:value-of select="#Comments" disable-output-escaping="yes" />
</a>
</th>
.MenuItem
{
border: thick red solid;
border-top: 0;
border-bottom: 0;
}
.MenuItem a
{
display: inline-block;
padding:.25em;
padding-left:1em;
padding-right:1em;
background-color:aqua;
}
.MenuItem a:hover
{
background-color:green;
}
With jQuery or other js ways, it would keep the original code, change the .MenuItem a:hover to a .MenuHover class and:
$(document).ready(function() {
$(".MenuItem").hover(function() {
$(this).addClass("MenuHover");
}, function() {
$(this).removeClass("MenuHover");
});
});
IE 6, 7 and 8 (when in quirks mode) do not support the CSS :hover pseudo class on arbitrary elements. There are javascript shims to make IE recognize :hover.
I found that the browser version and SharePoint add significant complexity to CSS. I think your solution will be to troubleshoot.
First, you need to understand the order that the CSS files are processed in by viewing the resulting HTML. SharePoint adds its own references to CSS that might override your own CSS classes. I would also suggest using Firebug and/or IE8's developer tools to understand which classes are applied to your HTML elements and/or any parent elements.
I found that the HTML declaration (strict, transitional) influenced how some browsers determined which class to apply to a given element when a conflict exists. I also found that SharePoint adds !important to a few of their CSS classes which also impacts how the browser makes a decision in the presence of conflicting CSS.
I hope this helps. I know it's not an answer but perhaps it will help you identify/resolve the problem.

Resources