Recently, I have been experiencing some difficulty applying CSS correctly to some of the OOTB (out-of-the-box) ASP.NET controls. Earlier today, I was trying to apply a CSS image border using the ASP.NET image control, but couldn't get it to render correctly. In the end, I had to use a regular HTML img tag.

CSS for Image Border

*
{
   margin: 0;
   padding: 0;
}

body
{
   background-color:#827575;
   color: #c6d3d5;
   font: 75%/1.5em Verdana, Helvetica, Geneva, "Helvetica Neue", sans-serif;
}

.test
{
   margin-left: 300px;
   padding-top:50px;
   width: 156px;
}

.imageStyle
{
   padding: 3px;
   background-color: #525252;
   border: 1px solid #c3cfd3;
}

 

ASP.NET Image Control

<div class="test">
  ASP.NET Image Control:
  <asp:Image ID="Image1" ImageUrl="~/Images/fender.jpg"    
     CssClass="imageStyle" runat="server" />
  <div style="clear:both;">Incorrectly Rendered</div>
</div>

 

ASP.NET Image Control Anomaly

 

HTML Image Tag

<div class="test">
  HTML img tag:
  <img src="~/Images/fender.jpg" id="Image2" alt="Correctly Rendered"
     class="imageStyle" runat="server" />
  <div style="clear:both;">Correctly Rendered</div>
</div>

 

Feedback from anyone experiencing similar issues would be welcome. One of the projects on my to-do list this year is to create a custom CSS framework for use with ASP.NET sites, and this is something I'd like to get a handle on in advance. If I come across any other issues like this one, I will post them here.

kick it on DotNetKicks.com

Tags: ,

ASP.NET | CSS




Footer I searched for a long time for a simple CSS solution to the eternal "sticky footer" problem, where the footer goes down to the end of the page. Up to now I have resorted to JavaScript to achieve this, which is not really the most elegant solution. It should be simple, right?

The other day, I stumbled upon what looked like a basic HTML/CSS solution. I wanted CSS that would push the footer to the bottom of the page, irrespective of content height, in an ASP.NET Master Page setup. Thanks to Ryan Fait for this.

It was straightforward enough to get it working for IE7. Firefox 3.0 didn't play nice at first until I moved the wrapper and footer divs out to the master page. Feel free to download the sample below and try it out for yourself - VS 2008 solution. Ignore the red wigglies in the master page. It has been tested in IE7, Firefox 3.0 and Chrome 0.2.149.29.

CSS_Sticky_Footer.zip (19.91 kb)

kick it on DotNetKicks.com  PHP, ASP, .NET, JSP Resources, Reviews

Tags: ,

ASP.NET | CSS



Heart of CSS: The Box Model

by agrace 13. October 2007 06:51

Box Model I wanted to write about positioning in CSS but recently I realized that I needed to go back to the beginning before grappling with issues like the Position and Display properties.

The box model is the starting point to understanding positioning in CSS. In fact, every single element in your markup is actually a box. Make this your personal mantra. Every element on a page is a box described by the content, padding, border and margin properties. This is so simple as to be totally elusive. It isn't immediately obvious because the default value for the border element isn't visible and the background default setting is transparent. To the browser, even a single period is treated as a little box.

Since a box has four sides, the padding, border and margin properties each have four settings for the top, right, bottom and left sides; designers often use the word TRouBLe as a memory jog. For example:

 /*   Top Right Bottom Left   */
 padding: 5px 10px 5px 10px;


Box Model

In theory, padding, border and margin values are optional and should default to zero. In the real world, this is often not the case. The user-agent stylesheet of different browsers may add values for the padding and margin. To overcome this, I always add a universal selector rule to the start of my style sheets to zero these out:

* {
    margin: 0;
    padding: 0;
}


The visible dimensions of the box are the sum of the content + padding + border values. The margin values determine the distance between the elements, horizontally and vertically.

Collapsing Margins

Most designers won't admit to their original ignorance of this one. They may have set several block elements vertically, then added top and bottom margins to each element. When the elements didn't have the expected vertical spacing between them, I'll bet they just shrugged, stuck in a few <br /> tags and marched on. Of course, that never happened me ;-)

Here's how it works: when vertical margins meet, they will collapse to form a single margin whose height will equal the larger of the two combined margins. Mystery solved. Note however, that this rule only applies to boxes in the normal flow of the document.

You can also use negative margins, but that is beyond the scope of this article (I've always wanted to say that).

Margin and Padding Shorthand

You may have been confused in the past when viewing CSS and coming across margin or padding rules with less than four values. This is actually a shorthand syntax. You can use one, two, three or four values within a shorthand declaration:

 /*   Padding on all sides   */
 padding: 5px;

 /*   Top and Bottom: 5px, Left and Right: 10px   */
 padding: 5px 10px;

 /*   Top: 5px, Left and Right: 10px, Bottom: 15px   */
 padding: 5px 10px 15px;


To sum up, whenever you set the width of an element on the page, you are actually setting the width of the content within it. If you set values for margins, padding or borders, you increase the space this element occupies on the page. Understanding this is fundamental, and necessary, before attempting to handle the other issues of positioning in CSS.

kick it on 
DotNetKicks.com  

Tags:

CSS