<?xml version="1.0" encoding="UTF-8"?> <rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
> <channel><title>David Pratt &#187; css</title> <atom:link href="http://daipratt.co.uk/tag/css/feed/" rel="self" type="application/rss+xml" /><link>http://daipratt.co.uk</link> <description>Concerned about Website Construction &#38; SEO</description> <lastBuildDate>Wed, 25 Jan 2012 07:16:58 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.1.4</generator> <item><title>Calculate text width and height with JavaScript</title><link>http://daipratt.co.uk/calculate-text-width-and-height-with-javascript/</link> <comments>http://daipratt.co.uk/calculate-text-width-and-height-with-javascript/#comments</comments> <pubDate>Thu, 22 Apr 2010 08:43:06 +0000</pubDate> <dc:creator>David Pratt</dc:creator> <category><![CDATA[Tech]]></category> <category><![CDATA[css]]></category> <category><![CDATA[javascript]]></category> <category><![CDATA[ui]]></category> <guid
isPermaLink="false">http://daipratt.co.uk/?p=1123</guid> <description><![CDATA[A tutorial that shows you how to measure the height and width of a text element using JavaScript.]]></description> <content:encoded><![CDATA[<p>Occasionally when putting together an advanced layout it&#8217;s necessary to have a level of control over the UI that can&#8217;t be achieved with CSS alone.</p><p>One situation might be in displaying a place name. Say for instance that place name had to be rendered in block that has a width of 200px, with a height that can flex as necessary to accomodate the content. This won&#8217;t be a problem in 99.9% of situations, but what happens if the place name is Llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch?! Yes this place <a
href="http://maps.google.co.uk/maps?f=q&#038;source=s_q&#038;hl=en&#038;geocode=&#038;q=Llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch&#038;sll=53.800651,-4.064941&#038;sspn=22.383401,67.631836&#038;ie=UTF8&#038;hq=&#038;hnear=Llanfair+Pwllgwyngyll,+Gwynedd,+United+Kingdom&#038;ll=53.223096,-4.206047&#038;spn=0.17636,0.528374&#038;z=12" target="_blank">does exist</a>! In cases like this you might want to apply a special class name, or maybe dynamically adjust the font-size so that it fits within the allowed container. The consequences of not defending against this situation might be that the layout behaves unpredicatably, breaks, or perhaps some of the word could be hidden by the overflow property in the CSS being set to hidden or something.</p><p>So, should you find yourself in a situation where you need to measure the height and width of a text element, this code might help you:</p><h5>HTML</h5><pre class="brush:php">
&lt;p id="place-name"&gt; Llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch&lt;/p&gt;
</pre><h5>CSS</h5><pre class="brush:css">
#place-name{
    position: absolute;
    height: auto;
    width: auto;
}
</pre><h5>JavaScript</h5><pre class="brush:javascript">
var oPlaceName = document.getElementById("place-name");
if (oPlaceName){
	var iHeight = oPlaceName.clientHeight + 1;
	var iWidth = oPlaceName.clientWidth + 1;
	if (iWidth &gt; 200){
		//Deal with the long text.
	}
}
</pre><p>I have prepared a <a
href="/examples/text-width.html" target="_blank">quick standalone example</a> should you want to see this in action.</p><p>A place name might have been a bad example, but it could have quite easily have been any other type of field who&#8217;s length or height you might want explicit control over. Other applications of this that I can think of quickly could be adjusting the font-size of headings so that they never wrap, perhaps adjusting letter spacings so that they have aligned edges, or whatever else the designers .psd file shocks you with! With a clever implementation, this sort of thing could be achieved without the user even noticing, but that&#8217;s a job for someone else!</p> ]]></content:encoded> <wfw:commentRss>http://daipratt.co.uk/calculate-text-width-and-height-with-javascript/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>Removing unwanted stylesheets from Drupal</title><link>http://daipratt.co.uk/removing-unwanted-stylesheets-from-drupal/</link> <comments>http://daipratt.co.uk/removing-unwanted-stylesheets-from-drupal/#comments</comments> <pubDate>Wed, 16 Dec 2009 13:18:21 +0000</pubDate> <dc:creator>David Pratt</dc:creator> <category><![CDATA[Tech]]></category> <category><![CDATA[css]]></category> <category><![CDATA[drupal]]></category> <guid
isPermaLink="false">http://daipratt.co.uk/?p=748</guid> <description><![CDATA[A way of stripping unwanted stylesheets out of a Drupal site by using a preprocess function in the template.php file.]]></description> <content:encoded><![CDATA[<p>One of the things that irritates me about adding modules in Drupal, is that they often have their own stylesheets associated with them that get automatically added to the site upon module activation.  Not always, but very often you&#8217;ll find that the rules within these supporting stylesheets result in one or more of the following undesirable side-effects:</p><ul><li>possess rules that clash, or are made redundant by rules that you already have in place</li><li>control aspects of the module administration that a user would never see</li><li>cater for features that the module provides that you don&#8217;t need, or haven&#8217;t activated</li><li>offer browser and device support that is not part of the site requirements</li><li>you have themed a modules mark-up, thus rendering its own stylesheet obsolete</li></ul><p>Generally there is no easy way, or no way at all to disable these stylesheets from the admin or module settings.</p><p>If you took a typical Drupal setup with a <a
href="http://drupal.org/project/zen">Zen starter theme</a> and add about 10 of the popular modules, it wouldn&#8217;t be unthinkable for the number of stylesheets to breach the 20 mark! 20 stylesheets!</p><div
id="attachment_802" class="wp-caption alignnone" style="width: 379px"><img
src="http://daipratt.co.uk/wp-content/uploads/2009/12/css.png" alt="Even before you start adding your own stylesheets..." title="Initial CSS" width="369" height="86" class="size-full wp-image-802" /><p
class="wp-caption-text">Even before you start adding your own stylesheets...</p></div><p>I know that the stylesheets can be cached and served as one file, but when you&#8217;re debugging the CSS and adding new sections to a site of any real size, you will inevitably end up playing specificity wars and having to reset rule properties more often than you&#8217;d like.  This all leads to bloated CSS that is a pain to debug and maintain.</p><p>To overcome this in the past and regain some sort of control over what CSS ends up on the site, I have adopted a code butchers approach and taken to ripping out the line seen below in the page.tpl.php file, and then just manually adding the stylesheets in the html.</p><pre class="brush: php">print $styles; //bye, bye</pre><p>That&#8217;s a problem solved, but another problem created in that sometimes you do actually want a modules stylesheet to be used. Determining the CSS file location(s) that a module uses can be difficult, especially when there are configuration options within a module that force different sets of stylesheets to be used such as in the popular <a
href="http://drupal.org/project/fivestar">fivestar</a> module.</p><p>I&#8217;m sure there are probably better, cleaner ways to achieve this, but what I do now is cull the Zen starter theme.info of all superfluous stylesheets and then add the <a
href="http://api.drupal.org/api/function/phptemplate_preprocess_page/6">phptemplate_preprocess_page</a> function within the template.php file with code that removes the remaining unwanted stylesheets, like so:</p><pre class="brush: php">function phptemplate_preprocess_page(&amp;$vars){
	//Get the loaded stylesheets as an array
	$stylesheets = drupal_add_css();
&nbsp;
	//Remove the default style sheets
	unset($stylesheets['all']['module'] ['modules/aggregator/aggregator.css']);
	unset($stylesheets['all']['module'] ['modules/node/node.css']);
	unset($stylesheets['all']['module'] ['modules/system/defaults.css']);
	unset($stylesheets['all']['module'] ['modules/system/system.css']);
	unset($stylesheets['all']['module'] ['modules/system/system-menus.css']);
	unset($stylesheets['all']['module'] ['modules/taxonomy/taxonomy.css']);
	unset($stylesheets['all']['module'] ['modules/user/user.css']);
&nbsp;
	//Remove some of the popular module stylesheets - add / remove your own here
	unset($stylesheets['all']['module'] ['sites/all/modules/cck/modules/fieldgroup/fieldgroup.css']);
	unset($stylesheets['all']['module'] ['sites/all/modules/cck/theme/content-module.css']);
	unset($stylesheets['all']['module'] ['sites/all/modules/date/date.css']);
	unset($stylesheets['all']['module'] ['sites/all/modules/filefield/filefield.css']);
	unset($stylesheets['all']['module'] ['sites/all/modules/link/link.css']);
&nbsp;
	//Set the styles
	$vars['styles'] = drupal_get_css($stylesheets);
}</pre><p>This function will do the trick for all of the Drupal system stylesheets and a few of the popular modules.  There is a big drawback to all this stylesheet optimisation of course, which is you&#8217;ll notice that your admin area falls apart and becomes completely unusable due to the fact that the supporting stylesheets aren&#8217;t present.  To overcome this is simple in most cases &#8211; you just need to set your administration theme (Administer -> Site Configuration -> Administration theme) to use a different theme and all module stylesheets will be pulled in &#8211; I usually go for the comforting shades of Garland.</p> ]]></content:encoded> <wfw:commentRss>http://daipratt.co.uk/removing-unwanted-stylesheets-from-drupal/feed/</wfw:commentRss> <slash:comments>3</slash:comments> </item> <item><title>Dots appearing around images when you click them</title><link>http://daipratt.co.uk/dots-appearing-around-images-when-you-click-them/</link> <comments>http://daipratt.co.uk/dots-appearing-around-images-when-you-click-them/#comments</comments> <pubDate>Sun, 22 Nov 2009 11:42:30 +0000</pubDate> <dc:creator>David Pratt</dc:creator> <category><![CDATA[Tech]]></category> <category><![CDATA[css]]></category> <category><![CDATA[html]]></category> <guid
isPermaLink="false">http://daipratt.co.uk/?p=641</guid> <description><![CDATA[To fix this, set the outline property of the anchor element to zero, like so: a{outline:0};]]></description> <content:encoded><![CDATA[<p>A quick tip!  If you every get an undesirable dotted border appearing around an image when you click it e.g:</p><div
id="attachment_643" class="wp-caption alignnone" style="width: 346px"><img
class="size-full wp-image-643" title="Undesirable dots around an image" src="http://daipratt.co.uk/wp-content/uploads/2009/11/Picture-1.png" alt="Dots appearing around an image after you click it" width="336" height="209" /><p
class="wp-caption-text">Dots appearing around an image after you click it</p></div><p>All you need to do to fix it is set the outline property of the anchor element to zero, like so:</p><pre class="brush: plain">
a{outline:0};
</pre><p>Happy days.</p> ]]></content:encoded> <wfw:commentRss>http://daipratt.co.uk/dots-appearing-around-images-when-you-click-them/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Wrap text on an HTML input button with CSS</title><link>http://daipratt.co.uk/wrap-text-on-an-button-with-css/</link> <comments>http://daipratt.co.uk/wrap-text-on-an-button-with-css/#comments</comments> <pubDate>Thu, 19 Nov 2009 16:43:16 +0000</pubDate> <dc:creator>David Pratt</dc:creator> <category><![CDATA[Tech]]></category> <category><![CDATA[css]]></category> <category><![CDATA[html]]></category> <guid
isPermaLink="false">http://daipratt.co.uk/?p=609</guid> <description><![CDATA[You can wrap text on a HTML button by using the white-space:normal; CSS rule. This tutorial shows you how.]]></description> <content:encoded><![CDATA[<p>Text on a standard HTML input button doesn&#8217;t wrap by default, which can be a bit of a pain if you need to say something a bit more descriptive than a typical  &#8220;add&#8221;, &#8220;go&#8221; or &#8220;submit&#8221;.   The default behaviour for the width of a button is to expand the width to fit the text within &#8211; as with all inline elements.</p><p>When you have a lot of text within the value attribute of a button, it renders something like this:</p><p
class="center"> <input
type="button" value="A lot of descriptive text on a button" /></p><pre class="brush: php">
&lt;input type="button" value="A lot of descriptive text on a button" /&gt;
</pre><p>If you then reduce the width of the button with a bit of css, you get cropped button text like so:</p><p
class="center"> <input
type="button" value="A lot of descriptive text on a button" style="width:100px;" /></p><pre class="brush: php">
&lt;input type="button" value="A lot of descriptive text on a button" style="width:100px;" /&gt;
</pre><p>To wrap the text on the button isn&#8217;t immediately obvious, you might try altering the display property, but it probably won&#8217;t occur to you to try the following css rule:</p><pre class="brush: plain">
white-space:normal;
</pre><p>Which will produce something like:</p><p
class="center"> <input
type="button" value="A lot of descriptive text on a button" style="width:100px; white-space:normal;" /></p><pre class="brush: php">
&lt;input type="button" value="A lot of descriptive text on a button" style="width:100px; white-space:normal;" /&gt;
</pre><p>Now ain&#8217;t that great! It doesn&#8217;t work in IE6 by the way, so you might need a plan B&#8230;</p><p>If you can make do without wrapping the text on the button, you should check out this method to <a
href="http://www.p51labs.com/simply-buttons-v2/">make prettier buttons</a>.</p> ]]></content:encoded> <wfw:commentRss>http://daipratt.co.uk/wrap-text-on-an-button-with-css/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> </channel> </rss>
