Forum Moderators: not2easy
#wrap {
}
#nav {
}
#nav .subs {
}
#mod1 {
}
#footer {
}
Sorry I couldn't resist.
However... It may be easy to write a script, but what would be the point when you have to write out the styles anyways... Might as well write out the tags, ids and classes while your at it. Right?
For CSS I use stylizer and it makes things very easy.
However... It may be easy to write a script, but what would be the point when you have to write out the styles anyways... Might as well write out the tags, ids and classes while your at it. Right?
When you have a large site there can be alot of ids and classes and this would save time typing that out. Maybe 20 mins or so.
<?php
function getId($input){
$first = ' id="';
$field = substr(strstr(strstr($input, $first), '"'),1);
$end = strstr($field, "\"");
$field = str_replace($end, "", $field);
return "#".$field." {\n\t\n}";
}
function getClass($input){
$first = ' class="';
$field = substr(strstr(strstr($input, $first), '"'),1);
$end = strstr($field, "\"");
$field = str_replace($end, "", $field);
return ".".$field." {\n\t\n}";
}
$sent = false;
if(isset($_POST['sub'])){
$cssfilename = $_POST['cssfilename'];
$string = $_POST['string'];
$lines = explode("\n", $string);
$n = count($lines);
$i=0;
header('Content-Disposition: attachment; filename="'.$cssfilename.'.css"');
$ar = null;
while($i < $n){
$var = $lines[$i];
$dif = $n-1;
if($i != $dif){
$var = substr($var, 0, -1);
}
if(getId($var)){
$ar .= getId($var);
$ar .= ",";
}
if(getClass($var)){
$ar .= getClass($var);
$ar .= ",";
}
$i++;
}
$array = substr($ar,0,-1);
$array = explode(",", $array);
$array = array_unique($array);
$nan1 = "# {\n\t\n}";
$nan2 = ". {\n\t\n}";
foreach($array as $value){
if($value != $nan1 && $value != $nan2){
echo $value."\n";
}
}
$sent = true;
}
?>
<?if(!$sent):?>
<br />Get CSS from HTML<br /><br />
<form action="get_css_from_html.php" method="post" />
Your CSS File Name<input type="text" name="cssfilename" value="style" size="7" />.css
<br />
Enter HTML Here<br />
<textarea name="string" rows="20" cols="100"></textarea>
<br />
<input type="submit" name="sub" value="enter" />
</form>
<?endif;?>
However... Maybe it is just me, but I still can't rationalize the point to this. And this is my reason why:
I usually write my CSS as I am constructing my pages. When I create a div (or any other element) I automatically style it. I personally haven't met anyone who will create a whole site(small or huge), only to style for it after the fact. Even if you take over a project that was created by someone else, 9 times out of 10 there is already a working css file to edit.
Now I do see this useful for html tags. For me it is usually later in my process when I do this. Stuff like p, ul li (unless I am building a h-menu), h1/h2..., and so on, I just throw in and style it last. But by looking at your PHP it looks like this was left out. I know little about PHP, so is it possible to do this for the HTML tags?
As of right now, using Notepad++, I have created macros that will auto generate empty html pages of each doctype that include the basics of an html document(head with empty title/meta/css link and empty body ready for me to fill in the blanks. I also have a macro set to generate a css document that has all the basic classes, ids, tags, and rules that I most commonly use.
Sorry. I wasn't trying to steal your thunder or anything. I personally don't see how I would benefit from something like this. But I do like it!
I am all for writing code by hand because you need to understand the code. But once you understand the code then I believe some tools can be helpful and save time.
Stylizer is not really a code writer or wizzy wig. If you know css and understand it, then this tool will help speed things up. And give you more accurate layouts. With writing css by hand you have to save, refresh, save, refresh.
I do like your idea of storing an html & css template in the macros.
Honestly: why bother with that ?
I think it'll distract greatly from the important things such as selectors having specificity, the cascade, etc.
It might well look like a good idea on first looks, but I can't think of a real life scenario where it would be productive in the end, even in the hands of somebody who really knows CSS inside-out.
Although not very well, there is a feature in Dreamweaver that does this. However when it assigns style names it does it like this:
.style1
.style2
.style3
and so on.
You would still have to go back and edit regardless. As I have already stated, interesting concept but useless in the long run.
I will stick with my macros and create my styles as I construct the layout.
Try thinking of how the script in drooh's example might be useful, and under which circumstances one might need it.
For example, I would definitely find it useful (with adjustments to keep the IDs and classes semantically grouped one after another) for a breakdown of the IDs and classes used in the HTML code, which also might be useful in cases you are not allowed to modify the HTML code, or need to process the page in bulk, etc.
We all have our own way of work, and, while suggestions are always good, no need to criticize each others' ways too much, also having in mind that the issue has been actually resolved.
IDs and classes semantically grouped one after another
I forgot to mention that, Ive always liked to have my css go in the order of my document from top to bottom. this definitely does that for you.
Also, this idea stems from the whole separation of content and design. If you have fully thought out the design and template then you should be able to run with the markup for quite awhile before needing to tweak things.
this idea is all meant to be for the start of your project, the start of your styling. From there its obvious that you would need to edit the css but at least this way they are in order and the base it there for you.