I have some css, which when inside my CSS file isn't applied to my designer in Visual Studio, but is applied to the page when I publish it. This issue is slowing down site development massively as I'm trying to pick up CSS as I go...
Here's a sample bit of CSS:
.header {
background-color: #ccc;
border-bottom: 1px solid #666;
color: #222;
display: block;
font-size: 20px;
font-weight: bold;
padding: 100px 100px 100px 100px;
text-align: center;
text-decoration: none;
text-shadow: 0px 1px 0px #fff;
background-image: -webkit-gradient(linear, left top, left bottom,
from(#ccc), to(#999));
}
Me applying the CSS on the page:
<header>
<asp:Label ID="lblQuestion" runat="server" Font-Bold="True" Font-Size="16pt" Text="Your question goes here..." CssClass="header"></asp:Label>
</header>
Me adding the CSS to the page:
<link rel="stylesheet" type="text/css" href="mycss.css" media="only screen and (max-width: 480px)" />
I'm pretty new to CSS, so I'm hoping someone can tell me what I'm doing that is stopping Visual Studio rendering the CSS properly in the designer...
Also, if I put my CSS tags directly in the page then it works, but I'd much rather keep my CSS out in it's own file, where it can be reused.
Example style working:
<style>
.header {
background-color: #ccc;
border-bottom: 1px solid #666;
color: #222;
display: block;
font-size: 20px;
font-weight: bold;
padding: 100px 100px 100px 100px;
text-align: center;
text-decoration: none;
text-shadow: 0px 1px 0px #fff;
background-image: -webkit-gradient(linear, left top, left bottom, from(#ccc), to(#999));
}
</style>
Thanks
I suggest taking a look at Jeff Widmer's blog post, Why does Visual Studio not resolve my CSS class names?
Basically, site relative path's aren't supported by Visual Studio. It is the same reason why intellisense doesn't work for javascript.
He offers a fix for this issue:
<link href="/content/default.css" rel="stylesheet" type="text/css" />
<% if (false) {%>
<link href="../../content/default.css" rel="stylesheet" type="text/css" />
<% } %>
UPDATE:
The problem here was the media element in the link tag for the css. It doesn't appear that VS knows what that tag is and thus doesn't try to resolve the url.
In this case, the css file is in the same folder as the page, so it would work. But, if the css file is moved into another folder, then it would stop working and the fix above would solve the issue.
Related
I have a problem with 2 buttons with CSS. I want to align two buttons next to each other. But CSS does not even like I wanted it. Because a button is bottom and a another button is top. See image: http://home.arcor.de/freedownload/buttonwrong.jpg
Maybe you have a solution for me? That would be fully appreciated.
Here is HTML Code:
<head>
<link href="formular.css" type="text/css" rel="stylesheet">
</head>
<span id="form1"><input type="text" id="form_username" name="username"></span><span id="form2"><input type="image" src="loginbutton.png"></span>
And here is CSS Code:
#form_username {
background: white url(username.png) left no-repeat;
background-position: 8px;
color: #adadad;
padding: 8px;
padding-left: 32px;
font-family: Verdana;
font-size: 12px;
width: 200px;
border: 1px solid #e4e4e4;
outline: 3px solid #efefef;
}
Try adding this style to your #form_username
float: left;
Demo
I have to apply the border-radius CSS property to a button, but only when the browser is not Internet Explorer 9. Otherwise I want to use the background-image property. I tried to apply the background-image for IE9 using conditional comments, but it is not working (the border-radius property from the "general" CSS is being applied to IE9 also, instead of the background-image).
How do I change this to make it apply the desired CSS according to the browser version?
/*For IE9*/
<!--[if lte IE 9]>
.PopupBtn
{
background-image: url("../Images/new-btn.png");
height: 28px;
width: 99px;
border-left-width: 0px;
border-top-style: none;
border-right-style: none;
border-bottom-style: none;
border-left-style: none;
cursor: pointer;
}
<![endif]-->
/*Style.css(general)*/
.PopupBtn
{
-moz-box-shadow: inset 0px 2px 1px 0px #0d0d0d;
-webkit-box-shadow:inset 0px 2px 1px 0px #0d0d0d;
box-shadow:inset 0px 2px 1px 0px #0d0d0d;
background:-webkit-gradient(linear, left top, left bottom, color-stop(0.05, #fffcff), color-stop(1, #000000));
background:-moz-linear-gradient(center top, #fffcff 5%, #000000 100%);
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#fffcff', endColorstr='#000000');
background-color:#fffcff;
-moz-border-radius:22px;
-webkit-border-radius:22px;
border-radius:22px;
display:inline-block;
color:#fcfcfc;
font:bold 13px trebuchet ms;
text-decoration:none;
text-shadow:1px 0px 0px #000000;
min-width:90px;
height:30px;
cursor:pointer;
border-style:none;
}
Better use jQuery for this.
if ($.browser.msie && parseInt($.browser.version, 10) == 9)
$('.PopupBtn').css({'background-image':'url(../Images/new-btn.png)','height':'28px','width':'99px'});
See http://api.jquery.com/css/ The advantage is that you not only have to use less code, but you can adjust everything, not just css. This is only just an example, you have to fill in the rest :)
IE's conditional comments are actually html comments, so you cant have them in a css file they have to be in a webpage. Somewhere in you webpage you'll have
<!--[if lte IE 9]>
<style>
.PopupBtn
{
background-image: url("../Images/new-btn.png");
height: 28px;
width: 99px;
border-left-width: 0px;
border-top-style: none;
border-right-style: none;
border-bottom-style: none;
border-left-style: none;
cursor: pointer;
}
</style>
<![endif]-->
or even an external style sheet link betwwen the comments
May be it will use full for You:
<script src="http://ie7-js.googlecode.com/svn/version/2.1(beta4)/IE9.js"> </script>
use this java script in head tag.
You need to place the Internet Explorer Conditional Comments on the actual web page and not in the CSS file.
Avoid adding inline CSS code. Instead, put them in their own CSS file. It's a good idea to separate your CSS files. Make one for the IE "hacks" and another for your regular stylesheet.
So, for example, put your IE specific CSS in ie.css file:
ie.css:
.PopupBtn {
background-image: url("../Images/new-btn.png");
height: 28px;
width: 99px;
border-left-width: 0px;
border-top-style: none;
border-right-style: none;
border-bottom-style: none;
border-left-style: none;
cursor: pointer;
}
Place your regular stylesheet in style.css.
In the <head> tag put:
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<!-- [if lte IE 9]>
<link rel="stylesheet" type="text/css" href="ie.css">
<![endif]-->
</head>
Note:
IE will still apply any styles from your regular style sheet that it understands. So,
make sure the Conditional Comments and ie.css style sheet is applied after the regular style sheet. This way, it can override any styles you don't want.
Make sure you explicitly override any styles you don't want in ie.css, otherwise, it will "bleed" through and show up in IE
See my JSFiddle link below. If you run it in IE 9, you'll see a green gradient with the word "Hello" in red. If you run it in any other browser, you should see a black gradient with the word "Hello" in white.
http://jsfiddle.net/mKrRL/
I seem to be having an issue with Chrome's computes styles. On certain elements on certain installations of chrome, the computed style differs from the css
The error occurs on several elements throughout the page but does not appear in safari or firefox on the same computer. Only half of the developers on the project have had this issue and it seems to come and go every few days...
Any ideas?
EDIT: I have a retina MPB and another developer with the issue has a 13" MacBook Air both running Mountain Lion
EDIT 2: This is the block of css that produces the computed style in the screenshot (although not the only one with the error
#nav-items div.item {
margin-left: -4px;
height: 64px;
display: inline-block;
text-align: center;
font-family: "HelveticaNeueW01-77BdCn 692722";
font-size: 26px;
text-shadow: 0px 1px 0px rgba(255,255,255,0.90);
line-height: 64px;
background-color: eee;
border-top: 1px double #ccc;
}
I reproduced the same issue with the following code and View -> Zoom In (once)
This changed my font size from 26px to 26.363636016845703px
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
#nav-items div.item {
margin-left: -4px;
height: 64px;
display: inline-block;
text-align: center;
font-family: "HelveticaNeueW01-77BdCn 692722";
font-size: 26px;
text-shadow: 0px 1px 0px rgba(255,255,255,0.90);
line-height: 64px;
background-color: eee;
border-top: 1px double #ccc;
}
</style>
</head>
<body>
<div id="nav-items">
<div class="item">Hello World</div>
</div>
</body>
</html>
The fix was to change the zoom back to normal: View -> Actual Size
I've added googles translate app to a site using the following
code
<div id="google_translate_element"></div><script>
function googleTranslateElementInit() {
new google.translate.TranslateElement({
pageLanguage: 'en',
autoDisplay: false,
layout: google.translate.TranslateElement.InlineLayout.SIMPLE
}, 'google_translate_element');
}
</script><script src="//translate.google.com/translate_a/element.js?
cb=googleTranslateElementInit"></script>
The app seems to work for a couple of languages. When translating to other
languages all the css is removed.
I'm keeping an eye on specific elements (such as a li in the header, or a div), and then running the translation. I can see that neither the header scripts (ie the css), or the elements are being changed by the app. It's just that the styles are no long applied (firebug tells me 'This element has no style rules')
The problem occurs on Firefox but not Chrome or Opera.
Any ideas what's going on here?
In case anyone else has the same issue -
The php that compresses the css files was adding a title to the scripts so
<link title="Default" media="screen" type="text/css" href="/modules/pd_smoothgallery/jd.gallery.css" rel="stylesheet">
was being changed to
<link title="Par défaut" media="screen" type="text/css" href="/modules/pd_smoothgallery/jd.gallery.css" rel="stylesheet">
I removed the title and the translation works fine for all languages.
(not sure why firebug wasn't highlighting this change, but it wasn't).
#google_translate_element span{
color:white!important;
font-size:15px;
border-left:1px solid transparent!important;
line-height: 22px;
}
.goog-te-gadget-simple {
background-color: #5191CD !important;
border-left: 1px solid transparent !important;
border-top: 1px solid transparent !important;
border-bottom: 1px solid transparent!important;
border-right: 1px solid transparent !important;
}
.goog-te-gadget-icon {
margin-left: 0px;
margin-right: 0px;
width: 0px!important;
height: 0px !important;
border: none;
vertical-align: middle;
}
I have two css files included on my page.
<link rel="stylesheet" href="/css/screen.css" />
<!--[if IE 8]>
<link rel="stylesheet" href="/css/ie8.css"/>
<![endif]-->
Now in screen.css I have a style like this
ul.treelayout{
list-style: none;
margin: 0px 0px 10px 0px;
background-color: #fff;
padding: 3px;
border-radius: 5px;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border: 1px solid #007b40;
}
I would like to remove the radius related styles in the ie.css such that the result style of ul.treelayout in IE is
ul.treelayout{
list-style: none;
margin: 0px 0px 10px 0px;
background-color: #fff;
padding: 3px;
border: 1px solid #007b40;
}
It seems that due to the fact that the styles cascade simply writing the class without the styles in ie.css doesn't do the trick. Any ideas?
Thanks
Regards
Gabriel
Ok mine is not to reason why ;) - but you can do this the other way around and only give the border-radius styles to NON-IE browsers.. in fact with a combination of Conditional comments you can give the border radius styles to IE9 and other browsers, I don't know which script you mean is clashing but maybe you can also just give the script to the browsers that need it?
here's an example (not using border-radius but hopefully you may get the idea..)
<style type="text/css" media="screen">
div {
padding: 40px;
color: #fff;
}
</style>
<!--[if IE]>
<style type="text/css" media="screen">
div {background: #00f}
</style>
<![endif]-->
<!--[if (!IE)|(gt IE 7)]><!-->
<style type="text/css" media="screen">
div {background: #f00}
</style>
<!--<![endif]-->
HTML:
<div>
<p>background is red in non-IE browsers,and IE gt 7 - but background is blue in other IE's</p>
</div>
About the above conditional comments..
the first is a regular style
the second is a "traditional" hidden conditional comment which Only IE sees
the third is a revealed comment which all browsers see but IE still reads the arguments
you would put the common rules in a normal sheet, and the border radius rules inside a sheet in the third style comment
you can change the argument of the third comment it's basically saying if NOT IE OR is gt IE7
More Information on arguments: About Conditional Comments
ul.treelayout{
list-style: none;
margin: 0px 0px 10px 0px;
background-color: #fff;
padding: 3px;
border-radius: 0;
-moz-border-radius: 0;
-webkit-border-radius: 0;
border: 1px solid #007b40;
}
ta da.
Due to the way the stylesheet will cascade, you only need to have this in your ie8.css:
ul.treelayout {border-radius: 0;}
This will keep all of the styles the same, except it will remove the IE border radius. If you want further IE changes you can add them in as you like.
When overwriting a stylesheet that is always included, you only need to add styles you want to overwrite or have show up in the browser you're customising for. This makes the css file smaller, which is better for your users.