Put all styles in css files vs Mixed structure - css

I am told that the good pattern is to put all styles in css files because blah and blah (you can search the reason in google since it's a very popular idea).
However, I am a person always asking why when people trying to sell. Based on my own experience with some project. I think putting all styles in files are harder to maintain, since there are some inheritable or page specific styles.
For example I have a control to display terms and conditions:
.TermsAndConditions
{
background-clip: padding-box;
border: 1px solid #CFC2A7;
border-radius: 5px 5px 5px 5px;
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1), 0 1px rgba(255, 255, 255, 0.6) inset, 1px 0 rgba(255, 255, 255, 0.3) inset, -1px 0 rgba(255, 255, 255, 0.3) inset;
height: 26px;
line-height: 26px;
padding: 0 10px;
text-align: center;
text-decoration: none;
vertical-align: middle;
white-space: nowrap;
position:absolute;
top: 0px;
left:0px;
}
When I need to use it on two of my pages I have to create two specific classes for it:
.HomePageTermsAndConditions
{
position: static;
bottom: 20px;
right:30px;
}
.ImagePreviewPageTermsAndConditions
{
position:absolute;
top: 50px;
left:60px;
}
Home page:
<div class="TermsAndConditions HomePageTermsAndConditions">
</div>
Preview page:
<div class="TermsAndConditions ImagePreviewPageTermsAndConditions">
</div>
Absolutely no styles inline, but there are some problems:
Position information is not shared at all, so the performance gain is very limited based on the network speed nowadays. (e.g. clear: left)
Some styles are not even inheritable, so we have to create css classes for each level, which doesn't save effort.
Hard to maintain, since css classes in files may be inherited or overridden by on another page, when editing a class it’s hard to know what effect it may cause, so it takes times to do testing/debug/fixing round trip.
Hurt performance, some css class will remain there when the page using it is removed. It takes effort to clean them.
So what I proposed is to move page/tag specific styles (like position info) inline like this:
.TermsAndConditions
{
background-clip: padding-box;
border: 1px solid #CFC2A7;
border-radius: 5px 5px 5px 5px;
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1), 0 1px rgba(255, 255, 255, 0.6) inset, 1px 0 rgba(255, 255, 255, 0.3) inset, -1px 0 rgba(255, 255, 255, 0.3) inset;
height: 26px;
line-height: 26px;
padding: 0 10px;
text-align: center;
text-decoration: none;
vertical-align: middle;
white-space: nowrap;
}
<div class="TermsAndConditions" style="position:absolute; bottom: 20px; right:30px;">
</div>
<div class="TermsAndConditions" style="position: static; top: 50px; left:60px;">
</div>
Benifits we can get:
No page specific information in classes. Doesn’t hurt performance since only several styles are in the page
Easier to maintain, since inline style has higher priority, editing an inline style will immediately bring the effect on UI. Also you don’t need to worry about breaking other pages.
When we need to remove a page, we usually don’t need to clean the css. Since page specific css are in the page, it goes with the page. Things in the css files are more likely to be shared.
More object-oriented. Since css classes in files have no page specific information, they are more like a control by itself. It’s easy to plug in to other pages.
For example:
When I need it on a new page, I just copy the html and change the style inline:
<div class="TermsAndConditions" style="position: absolute; top: 50px; left:60px;">
</div>
This is my idea against "putting all styles in css files". I am hoping to see your ideas about it, either good sides or bad sides.
Thanks

I think the best thing is to mix the things...
Usually I use classes, but when i need to specify position/dimensions, i use styles.
Sometimes I use existing classes but mixing it with style, when i need to override class settings.
I think the only case when i will not use style, is when i want to create totally dynamic layout and to have the ability to change it using CSS only.

The benefit of having your styles outside of your HTML is this.
Lets say I have a navbar on every page for example:
<ul class="main-navigation">
<li>my link</li>
<li>my link</li>
<li>my link</li>
<li>my link</li>
</ul>
My styles would then be something like this:
.main-navigation ul li {
color:#000;
}
Now lets say I have the same navbar, but with inline styles this time.
<ul>
<li style="color: #000;"></li>
<li style="color: #000;"></li>
<li style="color: #000;"></li>
<li style="color: #000;"></li>
</ul>
Or lets say I have my styles embeded into my HTML like so.
<style type="text/css">
.main-navigation ul li {
color:#000;
}
</style>
Depending on how your file management is set up. Most likely you would not want to go through every single HTML file to change something as simple as your navigation color. When you could just go into the style sheet and change one line of code.
Hopefully this make sense. But I guess to summarize I would say in some cases it is probably more practical. However I personally believe that separating HTML, CSS, Javascript, and PHP makes troubleshooting a lot easier.

Related

Button looks different depends on graphic card

I have a button and it renders weird in Firefox (I'm testing various versions, but I've see it in all of it). For more details, I use Normalize.css.
After several tests, the only difference between the PC with the issue and the PC with the correct behaviour is the graphic card.
Also, the issue differs depending the page you're seeing (the button is in various pages).
Here you can see a few screenshots in different PCs:
I have made a testcase in jsFiddle: http://jsfiddle.net/5R2NL/1/
Here's the HTML:
<div class="botonVerdeenlace">
<a title="Title" href="#">I feel like a button</a>
</div>
And the relevant CSS:
body{font-size:68.75%}
.botonVerdeenlace {
background: url("http://i.imgur.com/lk4ZJxQ.png") no-repeat scroll left center rgba(0, 0, 0, 0);
display: inline-block;
font-weight: normal;
margin: 0;
padding: 8px 2px 7px 29px;
}
.botonVerdeenlace a, .botonVerdeenlace a:visited {
background: url("http://i.imgur.com/2IgIR37.png") no-repeat scroll right center rgba(0, 0, 0, 0);
border: medium none;
color: #FFFFFF !important;
font-family: Arial,sans-serif;
font-size: 1.1em;
font-weight: normal;
margin: 0;
padding: 8px 1em 7px 7px;
text-align: center;
text-decoration: none;
}
What is causing that issue? It's certanly the video-card?
Is there any way to fix this issue without screw the design for other
users?
EDIT: I try the suggestion from Nico O, and the hardware acceleration doesn't seems to have any influence in the rendering.
EDIT2: Use css3 is not an option, because there are A LOT of buttons in the web. If this is the only solution the client will prefer to leave it "bad".
Maybe it's "Hardware Acceleration (GPU Rendering)" fault. You can disable this on options and test again but you are better served using CSS3.
But my client wants IE7: declare on CSS your normal button that works on IE7 than make a media query that works for any resolution with your CSS3 button, that way the button still nice on IE7 and works pretty well on firefox.

Blogger - Changing style for comment textarea

I most likely know the answer but maybe I'm wrong so lets try.
I want to change the appearance of the comment form from Blogger (blogspot - Google blog system). Sadly, this awful little form is embedded in an iframe so my CSS styles wont work.
Also playing around with jquery is useless, of course.
I know, iframes are not meant to manipulated but maybe its possible for blogger, somehow... in a distant world.
Is there a way or just not possible as i think?
Have you tried styling your comment iframe?
you cannot style content inside iframe, but you could style your iframe .
Below is an example, add this just before closing the <head> tag.
<style type='text/css'>
#comment-editor {
background: #F9F9F9 url(http://2.bp.blogspot.com/-Bdsls_ui_vY/UX-d4NVcHiI/AAAAAAAAB3M/IIzD9w00lDs/s1600/form-gradient.gif) repeat-x scroll -1px -2px;
border: 1px solid rgb(221, 221, 221);
border-radius: 6px 6px 6px 6px;
box-shadow: 5px 5px 5px rgb(204, 204, 204);
padding: 5px;
width: 560px;
height: 224px !important;
}
</style>
So it will look like this!
Screenshot of the resulting comment form!
I never had a need to style comment section in Blogger, so I cannot help you in that regard.
But you could try to replace it with third-party comment systems like IntenseDebate.
It supports custom CSS and URL to external stylesheet and has lots of other useful features too.
If you decide to try it just remember to backup a template before making a switch in case you want to revert back.

ColdFusion datefield interfering other CSS

When I add a cfinput type="datefield", the ColdFusion CFIDE/scripts are interfering another div on the page.
Good:
Bad:
The code:
<aside id="sideLeft">
<--- CMS generated --->
<div class="ktcssmenu thenav_ff_green"><div class="ktvertical ktopts_showtimeout_100 ktopts_hidetimeout_100 ktopts_imgreplace_no ktopts_imgreplacestyle_img ktopts_imgdir_ ktopts_imgnames_">
<ul class='lev1 clearfix'><li class="lev1 pos1 lev1_pos1 first lev1_first">Human Resources Home</li>
<li class="lev1 pos2 lev1_pos2 last lev1_last">Public Site</li>
</ul></div></div>
<--- regular non-CMS code --->
<div class="gspecial">
Restricted Access
New Hire Forms
Jobs / Employment Admin
Eligibility Lists Admin
</div>
...
The CSS:
#sideLeft {
float: left;
width: 230px;
margin-left: -100%;
position: relative;
padding: 10px 10px 10px 10px;
background-color: #f5f5f5;
border: 1px solid #d5d5d5;
}
/* test */
.thenav_ff_green {
border: dashed 5px #990000;
}
.gspecial {
border: dotted 5px #003333;
}
The website is using a CMS, and I cannot edit much within the "green"
pre-packaged Navigation.
The ColdFusion CFIDE/script causing my headache is /CFIDE/scripts/ajax/ext/adapter/yui/ext-yui-adapter.js
I have tried various CSS clearing and floating.
I am willing to try anything again. Thanks.
I feel the best solution would be to not use cfinput, and instead try something like this:
http://jqueryui.com/datepicker/#icon-trigger
Then you'll have much more control over the styling, and functionality as it's something you can actually edit, rather than just receiving whatever rolled in js/css cfinput gives you.
otherwise you might just have to use firebug to find what exactly is causing the issue to add in some extra css to fix it.
CSS bugs like this are tricky to debug without having an example page to play with. Any way you can simmer this down to a page you can share with us?

CSS - removing horizontal space in list menu using display: inline property

I'm new to CSS and have a set target of learning & publishing my website in CSS by the end of the month.
My question:
I'm trying to build a CSS horizontal menu with hover drop downs, however, when I use the display: inline property with li (list) items, I get horizontal spaces between the li (list) items in the bar. How do I remove this space?
Here is the HTML:
<div id="tabas_menu">
<ul>
<li id="tabBut0" class="tabBut">Overview</li>
<li id="tabBut1" class="tabBut">Collar</li>
<li id="tabBut2" class="tabBut">Sleeves</li>
<li id="tabBut3" class="tabBut">Body</li>
</ul>
</div>
And here is the CSS:
#tabas_menu {
position: absolute;
background: rgb(123,345,567);
top: 110px;
left: 200px;
}
ul#tabas_menu {
padding: 0;
margin: 0;
}
.tabBut {
display: inline;
white-space:
list-style: none;
background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(rgba(255,142,190,1)),to(rgba(188,22,93,1)));
background: -moz-linear-gradient(top, rgba(255,142,190,1), rgba(188,22,93,1));
font-family: helvetica, calibri, sans-serif;
font-size: 16px;
font-weight: bold;
line-height: 20px;
text-shadow: 1px 1px 1px rgba(99,99,99,0.5);
-moz-border-radius: 0.3em;
-moz-box-shadow: 0px 0px 2px rgba(0,0,0,0.5);
-webkit-border-radius: 0.3em;
-webkit-box-shadow: 0px 0px 2px rgba(0,0,0,0.5);
padding: 6px 18px;
border: 1px solid rgba(0,0,0,0.4);
margin: 0;
}
I can get the space removed using the float: left/right property but it's bugging me as to why I cannot achieve the same effect by just using the display property.
I had a remarkably similar question a couple weeks ago.
The horizontal spaces are perfectly reasonable. Between inline elements, whitespace matters. This makes perfect sense when you consider the following markup under generic styles:
<b>Label:</b> <span>content</span>
Wouldn't you feel frustrated if this content rendered as the following?
Label:content
The prevalence of block elements in HTML spoils us into forgetting about the role of whitespace. But we must remember that whenever using inline elements (including inline-block elements), that whitespace in the markup actually does matter since HTML is fundamentally a markup and not a coding language.
There a a few solutions to your problem (assuming you want to hold onto the whitespace in the HTML for aesthetic reasons—if this is not important, just remove the space and be done with it), the easiest of which is to apply font-size: 0px to the parent container and then restore the font size to font-size: 16px or whatever it is in each of the inline elements. This makes it so that the text nodes between them have a font size of zero.
The problem is some browsers will render the white space between list items. For example:
<li>item 1</li>
<li>item 2</li>
There is a newline (and probably some tabs) after the </li> on the first line and before the <li> on the next line. Some web browsers will render this as a space. There are two workarounds.
One is to remove all these spaces, like so:
<ul>
<li id="tabBut0" class="tabBut">Overview</li><li id="tabBut1" class="tabBut">Collar</li><li id="tabBut2" class="tabBut">Sleeves</li><li id="tabBut3" class="tabBut">Body</li>
</ul>
This is a kind of ugly solution, but it works.
The other possibility is what you mentioned yourself -- use float: left. Personally, I always go with the float solution.
Using float:left complicates the layout calculation for browsers. If you care about rendering speed and efficiency, remove all whitespace between the <li> items.
<html>
<head>
<style>
ul li, ul li:before,ul li:after{display:inline; content:' '; }
</style>
</head>
<body>
<ul><li>one</li><li>two</li><li>three</li></ul>
<ul>
<li>one</li>
<li>tw`enter code here`o</li>
<li>three</li>
</ul>
</body>
</html>

CSS aligniment problem

I am designing home page of my domain registration website and I am stuck at one place. Please go through the website at http://a2host.in/
In Firefox and Google Chrome the Search and Go Button are in same alignment with the text and select box but in Opera and IE8, they are falling down a bit.
I have tried out all the things but I am not able to figure out the actual problem.
I see a lot of unneccesary styling. In essence, this is what you want:
Basic form without floats
You can tweak the font-sizes and colors here, until you have what you want. But this is a good starting point, because it is cross browser identical.
Also, think about using the <button> element instead of the <input type="button">. It gives you more freedom in styling.
Form-controls are a pain to get them look good in all browsers, especially buttons and select-boxes.
Please comment out the following CSS3 properties (please see below) in the .regbutton class of your stylesheet and then try
.regbutton, .regbutton:visited {
background: #222 url(/getImage.php?src=myUploadedImages/overlay.png) repeat-x;
display: inline-block;
padding: 5px 10px 6px;
color: #fff;
text-decoration: none;
/*-moz-border-radius: 6px;*/ /*comment out all CSS3 properties*/
/*-webkit-border-radius: 6px;*/
/*-moz-box-shadow: 0 1px 3px rgba(0,0,0,0.6);*/
/*-webkit-box-shadow: 0 1px 3px rgba(0,0,0,0.6);*/
/*text-shadow: 0 -1px 1px rgba(0,0,0,0.25);*/
/*border-bottom: 1px solid rgba(0,0,0,0.25);*/
position: relative;
cursor: pointer;
}
try to set border:none for your buttons

Resources