Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-28-2012, 10:47 PM   PM User | #1
jamgood96
New to the CF scene

 
Join Date: Mar 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
jamgood96 is an unknown quantity at this point
Naming Headaches for AJAX & CSS

Hey Everyone,

I'm working on a CRM-type project for our company that is driven by CodeIgniter and JavaScript/AJAX. Things have progressed fine so far, but as the site is growing, I'm losing confidence in how I am referencing CSS/HTML elements (divs, classes, form inputs, etc).S ince this is dynamic, I have multiple CSS-popup divs with forms and data entry that are being added and removed throughout the workflow, each one needing to be formatted a certain way.

What is the best way to keep track of all of these? Is there a naming convention that I should be using? When accessing things through AJAX, should I be referencing the class when things change, the form input element, the div id? I know these are very open ended questions with infinite solutions, but I'm curious how people go about managing large sites with dynamic content? An example of how I have some CSS written is below just to give some brief insight.

Code:
/*
PROJECT BOX STYLING
*/
#project_addOrEditProjectBox {
	font-size:14px;}
	#project_addOrEditProjectBox .loading {
		margin-left:-25px;
		margin-top:-25px;}
#project_addOrEditProjectBox label {
	display:block;
	font-size:12px;
	margin-bottom:2px;
	text-align:left;}
	#project_addOrEditProjectBox input[name=street] {
	display:block;
	margin-bottom:4px;
	text-align:left;
	width:295px;}	/*-4px for padding, -2px for border*/
	#project_addOrEditProjectBox input[name=city] {
		margin-right:6px;
		width:174px;} /*-4px for padding, -2px for border*/
	#project_addOrEditProjectBox input[name=state] {
		margin-right:6px;
		text-align:center;
		width:29px;}
	#project_addOrEditProjectBox input[name=zipcode] {
		text-align:center;
		width:59px;}
jamgood96 is offline   Reply With Quote
Old 03-29-2012, 08:47 PM   PM User | #2
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,462
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
whatever you do, aim to reduce repetition. for example, all of your rules have an ID selector in front of them ("#project_addOrEditProjectBox"). You said you have other boxes, so i can't help but imagine that many boxes share properties.

so, you would give all of those boxes a class of "box", and use #project_addOrEditProjectBox only to define deviations from the generic box.

likewise, while many aspects of each box needs customization, i'll bet that .box input {text-align: center} could replace several rules in just the css you have shown. You simply spec text-align: left for anything that the more universal rule breaks. Always opt-in on tags and classes, and opt-out on IDs. Ok Ok, don't always do anything, that's bad advice, but do try to keep repetition down to a minimum.
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.6% IE9:9.8% IE10:10%
rnd me is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:18 AM.


Advertisement
Log in to turn off these ads.