Forum Moderators: not2easy

Message Too Old, No Replies

can i make this shorter

         

tonynoriega

2:13 pm on Mar 13, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



i have several hidden divs that all have paragraphs in it...

can i make this line shorter?


#mem0 p, #mem1 p, #mem2 p, #mem3 p, #mem4 p, #mem5 p, #mem6 p{
padding-left:7px;
margin:3px 0px 0px 0px;
}

rocknbil

4:52 pm on Mar 13, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Do you really need to ID those elements? Just make them a class, or add a class to them if you need the ID for something.

.mem p{
padding-left:7px;
margin:3px 0px 0px 0px;
}

#mem0 { /*some specific selector */}

<div id="mem0" class="mem"><p>content</p></div>

tonynoriega

9:08 pm on Mar 13, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



they need to be unique becuase they are called by an onmouseover javascript.. so i have to have unique ID's

londrum

9:12 pm on Mar 13, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



well you can save a few piddly little bytes with
margin:3px 0 0;

instead of
margin:3px 0px 0px 0px;

rocknbil

6:21 am on Mar 14, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



they need to be unique becuase they are called by an onmouseover javascript.. so i have to have unique ID's

Right . . . but you can still use a class for common attributes. simple example, not using mouseovers but . . .


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<style type="text/css">
.mem {
padding-left:7px;
margin:3px 0 0 0;
display:none;
}
</style>
<script type="text/javascript">
function showGraph(obj) {
if (document.getElementById) {
var val=obj.options[obj.selectedIndex].value;
if (val != '') {
for (i=0;i<=5;i++) {
var p = 'mem'+i;
var graph=document.getElementById(p);
graph.style.display=(i==val)?'block':'none';
}
}
}
}
</script>
</head>
<body>
<form action="">
<select name="showhide" id="showhide" onChange="showGraph(this);">
<option value="">Try it</option>
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
</form>
<p id="mem0" class="mem">mem 0</p>
<p id="mem1" class="mem">mem 1</p>
<p id="mem2" class="mem">mem 2</p>
<p id="mem3" class="mem">mem 3</p>
<p id="mem4" class="mem">mem 4</p>
<p id="mem5" class="mem">mem 5</p>
</body>
</html>

tonynoriega

2:05 pm on Mar 16, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



ahh, i see.... got it now.