Using CSS to Fix Anything: 20+ Common Bugs and Fixes

IE Bug Fixes

1- Bug Fix: IE Double Margin Float Bug- It’s an Internet Explorer-exclusive bug wherein an element that is floated – and given a margin in the same direction as the float – ends up with twice the specified margin size. The fix is extremely simple. All you have to do is apply a display: inline rule to your floated element. So you simply go from something like this:

<code>#content {<br />    float: left;<br />    width: 500px;<br />    padding: 10px 15px;<br />    margin-left: 20px; }</code></pre> <p>To something like this:</p> <pre><code>#content {<br />    float: left;<br />    width: 500px;<br />    padding: 10px 15px;<br />    margin-left: 20px;<br />    display:inline;<br />}</code></pre> <p class="image-20"><a href=""><img src="" alt="CSS Tips" /></a></p> <hr> <p>2-<strong>Overcoming the Box Model Hack</strong>- If you want to specify a width to any div, do NOT specify padding or margins. Just create an inner div with no width set and specify its padding and margins instead. So instead of doing this:</p> <pre><code>#main-div{<br />width: 150px;<br />border: 5px;<br />padding: 20px;<br />}</code></pre> <p>Do something like this:</p> <pre><code>#main-div{<br />width: 150px;<br />}<br />#main-div div{<br />border: 5px;<br />padding: 20px;<br />}</code></pre> <hr> <p>3-<a href="" class="showcase">Min-height attribute ignored in IE</a>- “min-height” attribute works well in Firefox but IE ignores it. IE’s height act as FF’s min-height. Note: in IE 7 problem was fixed.</p> <pre><code>/* for understanding browsers */<br />.container {<br />width:20em;<br />padding:0.5em;<br />border:1px solid #000;<br />min-height:8em;<br />height:auto;<br />}<br />/* for Internet Explorer */<br />/*\*/<br />* html .container {<br />height: 8em;<br />}<br />/**/</code></pre> <p>4- <a href="" class="showcase">Min-Width for IE </a>-A fix for the lack of min-width in Internet Explorer.</p> <hr> <h4 class="title">Centering a Block Element</h4> <p>5-<a href="" class="showcase">Centering Block Element</a>- There are multiple techniques for centering a block element; and the choice for the technique depends on whether you have the size set in percentages or in more absolute values.</p> <p>Centering an entire page’s contents:</p> <pre><code>body{<br />text-align: center;<br />}<br />#container<br />{<br />text-align: left;<br />width: 960px;<br />margin: 0 auto;<br />}</code></pre> <hr> <p>6-<a href="" class="showcase">Vertical Align with CSS</a>- If you want to know how you can achieve vertical-align functionality the right way, simply specify the line-height for your text the same height as that of the container’s.</p> <pre><code>#wrapper {<br />	width:530px;<br />	height:25px;<br />	background:url(container.gif) no-repeat left top;<br />	padding:0px 10px;<br />}<br />#wrapper p {<br />	line-height:25px;<br />}</code></pre> <hr> <h4 class="title">Column Issues</h4> <p>7- <a href="" class="showcase">Top reasons your CSS columns are messed up</a>- An easy-to understand article on how to fix common CSS Column issues with helpful diagrams and code snippets.</p> <p class="image-20"><a href=""><img src="" alt="CSS Tips" /></a></p> <hr> <p>8-<a href="" class="showcase"> The Expanding Box Bug</a>-When you try to create a two-column float layout, IE will create a “float drop”, and it’s caused by having over-sized content in a fixed-width floated div that must fit into a particular spot in the layout. Several possible workarounds are detailed in this post.</p> <p class="image-20"><a href=""><img src="" alt="CSS Tips" /></a></p> <hr> <h4 class="title">CSS Positioning</h4> <p>9- <a href="" class="showcase">Understanding CSS Positioning part 1</a>- An interesting series of articles that doesn’t only cover positioning, but also properties that define layout such as display and float, and a preview of the new CSS3 layout modules. The first part will introduce the positioning and display property. <a href="">Part1</a>, <a href="">Part2</a>, <a href="">Part3</a> gives you a deep understanding of the possibilities you have in positioning.</p> <p class="image-20"><a href="" class="showcase"><img src="" alt="CSS Tips" /></a></p> <hr> <p>10- <a href="" class="showcase">What is the difference between relative and absolute positioning?</a>- Whether to use relative or absolute positioning can be extremely frustrating to people just getting started with CSS. The answer to this question will add a bit of clarity to this confusion.</p> <pre><code>#redSquare<br />{<br />position: relative;<br />bottom: 40px;<br />right: 40px;<br />}<br /></code></pre> <p>To get this:</p> <p class="image-20"><a href=""><img src="" alt="CSS Tips" /></a></p> <hr> <p>11-<a href="" class="showcase">HangTab</a>- Create a Sticky Tag from the Edge of the Browser Window (Even with Centered Content). Check out <a href="">Panic’s website for their software Coda</a>.</p> <pre><code>#hang_tab {<br />position: absolute;<br />top: 7px;<br />left: 0px;<br />width: 157px;<br />height: 93px;<br />}</code></pre> <p class="image-20"><a href=""><img src="" alt="CSS Tips" /></a></p> <hr> <h4 class="title">CSS Float Concept</h4> <p>12- <a href="" class="showcase">CSS Float Theory: Things You Should Know</a>- <a href="">SmashingMagazine</a> browsed through dozens of related articles and selected the most important things you should keep in mind developing css-based layouts with floats.</p> <pre><code><div> <!-- float container --><br /><div style="float:left; width:30%;"><p>Some content</p></div><br /><p>Text not inside the float</p><br /><div style="clear:both;"></div><br /></div><br /></code></pre> <hr> <p>13- <a href="" class="showcase">Floatutorial: Simple tutorials on CSS Floats</a>- Floatutorial takes you through the basics of floating elements such as images, drop caps, next and back buttons, image galleries, inline lists and multi-column layouts.</p> <p class="image-20"><a href=""><img src="" alt="CSS Tips" /></a></p> <hr> <p>14- <a href="" class="showcase">Clear Your Floats - The Right Way</a>- Float clearing can be one of the most frustrating aspects of CSS development, one of the best ways is to use the <a href="">EasyClearing</a> on your site.</p> <pre><code>/* EasyClearing */<br />#container:after<br />{<br />	content: ".";<br />	display: block;<br />	height: 0;<br />	clear: both;<br />	visibility: hidden;<br />}<br /><br />#container<br />{display: inline-block;}<br /><br />/* Hides from IE-mac \*/<br />* html #container<br />{height: 1%;}<br /><br />#container<br />{display: block;}<br />/* End hide from IE-mac */</code></pre> <p class="image-20"><a href=""><img src="" alt="CSS Tips" /></a></p> <hr> <h4 class="title">Easier Rounded Corner Solutions</h4> <p>15- <a href="" class="showcase">Mike asks the CSS Guy for recommendations on rounded corners</a>- “Simplest way is to use a giant gif, then I’ll markup my box”</p> <pre><code><div class="roundBox"><br />  <p>beautifully-encapsulated paragraph</p><br />  <div class="boxBottom"></div><br /></div></code></pre> <p>“And give it the background”</p> <pre><code>.roundBox {<br />  background:transparent url(roundBox.gif) no-repeat top left;<br />  width:340px;<br />  padding:20px;<br />}<br />.roundBox .boxBottom {<br />  background:white url(roundBox.gif) no-repeat bottom left;<br />  font-size:1px;<br />  line-height:1px;<br />  height:14px;<br />  margin:0 -20px -20px -20px;<br />}</code></pre> <hr> <p>Also <a href="">Askthecssguy</a> explains the <a href="">technique used in Google Analytics</a>, which works by leaving a 1px notch in every corner to get the rounded corner effect which is a new way of creating rounded corners without using static images. You can see an example <a href="">here</a>.</p> <p class="image-20"><a href=""><img src="" alt="CSS Tips" /></a></p> <hr> <p>16-<a href="" class="showcase">3 Simple Steps in Coding a Rounded Corners Layout</a>- Alen Grakalic’s approach to coding a fixed width, rounded corners layout in 3 simple steps. He also created a<a href=""> demo here</a>. </p> <p class="image-20"><a href=""><img src="" alt="CSS Tips" /></a></p> <hr> <h4 class="title">CSS Form Issues</h4> <p>17- <a href="" class="showcase">Tips For Creating Great Web Forms</a>- Cris Coyer shares with us some tips for floating labels, :focus Pseudo Class, using hints and more. He also created the <a href="">Nice & Simple Contact Form</a>, which he first posted about <a href="">here</a>. </p> <pre><code>label {<br />	float: left;<br />	text-align: right;<br />	margin-right: 15px;<br />	width: 100px;<br />}</code></pre> <hr> <p class="image-20"><a href=""><img src="" alt="CSS Tips" /></a></p> <hr> <p>18- <a href="" class="showcase">Clean and pure CSS FORM design</a>- For CSS lovers, this tutorial illustrates a proposal about how to design a pure CSS form without using html tables. You can grab the code <a href="">here</a>. </p> <p class="image-20"><a href=""><img src="" alt="CSS Tips" /></a></p> <hr> <p>19-<a href="" class="showcase">Autopopulating text input fields with JavaScript</a>- Sometimes we need to explain to users what they are supposed to enter into text input fields. One common workaround when no label can be displayed is to put some placeholder text in the text field and let that act as the label. This tutorial introduces a nice solution, with JavaScript enabled, the label element is hidden and the value of the input element’s title attribute is copied to the value attribute. If JavaScript is disabled, the label is displayed above the text input, which is left empty. A simple demo, where you can see this in action is <a href="">here</a>. </p> <p class="image-20"><a href=""><img src="" alt="CSS Tips" /></a></p> <hr> <h4 class="title">Worth checking CSS Tricks</h4> <p>20-<a href="" class="showcase"> Cross browser Horizontal Rule with Background Image</a>- You’d like to create a cross-browser horizontal rule that utilizes a custom image as the content separator. </p> <pre><code> {<br />background: #fff url(myhrimg.gif) no-repeat scroll center;<br />height: 10px<br />}<br /> hr {<br />display: none<br />}</code></pre> <hr> <p>Your tag should look like this:</p> <pre><code><div class="hr"><hr /></div></code>
Technorati Tags: