Archive for the ‘css’ Category.

CSS Image Opacity / Transparency

Creating transparent images with CSS is easy.

Note: This is not yet a CSS standard. However, it works in all modern browsers, and is a part of the W3C CSS 3 recommendation.

Example 1 – Creating a Transparent Image

First we will show you how to create a transparent image with CSS.

Regular image:

klematis Continue reading ‘CSS Image Opacity / Transparency’ »

CSS Image Gallery

CSS can be used to create an image gallery.

Image Gallery

The following image gallery is created with CSS:

<html>
<head>
<style type=”text/css”>
div.img
  {
  margin:2px;
  border:1px solid #0000ff;
  height:auto;
  width:auto;
  float:left;
  text-align:center;
  }
div.img img
  {
  display:inline;
  margin:3px;
  border:1px solid #ffffff;
  }
div.img a:hover img
  {
  border:1px solid #0000ff;
  }
div.desc
  {
  text-align:center;
  font-weight:normal;
  width:120px;
  margin:2px;
  }
</style>
</head>
<body>

<div>
  <a target=”_blank” href=”klematis_big.htm”>
  <img src=”klematis_small.jpg” alt=”Klematis” width=”110″ height=”90″ />
  </a>
  <div>Add a description of the image here</div>
</div>
<div>
  <a target=”_blank” href=”klematis2_big.htm”>
  <img src=”klematis2_small.jpg” alt=”Klematis” width=”110″ height=”90″ />
  </a>
  <div>Add a description of the image here</div>
</div>
<div>
  <a target=”_blank” href=”klematis3_big.htm”>
  <img src=”klematis3_small.jpg” alt=”Klematis” width=”110″ height=”90″ />
  </a>
  <div>Add a description of the image here</div>
</div>
<div>
  <a target=”_blank” href=”klematis4_big.htm”>
  <img src=”klematis4_small.jpg” alt=”Klematis” width=”110″ height=”90″ />
  </a>
  <div>Add a description of the image here</div>
</div>

</body>
</html>

CSS Navigation Bar

Navigation Bars

Having easy-to-use navigation is important for any web site.

With CSS you can transform boring HTML menus into good-looking navigation bars.


Navigation Bar = List of Links

A navigation bar needs standard HTML as a base.

In our examples we will build the navigation bar from a standard HTML list.

A navigation bar is basically a list of links, so using the <ul> and <li> elements makes perfect sense: Continue reading ‘CSS Navigation Bar’ »

CSS Pseudo-elements

CSS pseudo-elements are used to add special effects to some selectors.

Syntax
The syntax of pseudo-elements:

selector:pseudo-element {property:value;}

CSS classes can also be used with pseudo-elements:

selector.class:pseudo-element {property:value;}

Continue reading ‘CSS Pseudo-elements’ »

CSS Horizontal Align

Aligning Block Elements

A block element is an element that takes up the full width available, and has a line break before and after it.

Examples of block elements:

  • <h1>
  • <p>
  • <div>

For aligning text, see the CSS Text chapter.

In this chapter we will show you how to horizontally align block elements for layout purposes.

Continue reading ‘CSS Horizontal Align’ »

Elements Float

Elements are floated horizontally, this means that an element can only be floated left or right, not up or down.

A floated element will move as far to the left or right as it can. Usually this means all the way to the left or right of the containing element.

The elements after the floating element will flow around it.

The elements before the floating element will not be affected.

If an image is floated to the right, a following text flows around it, to the left: Continue reading ‘Elements Float’ »

CSS Positioning: Relative Absolute

Positioning

The CSS positioning properties allow you to position an element. It can also place an element behind another, and specify what should happen when an element’s content is too big.

Elements can be positioned using the top, bottom, left, and right properties. However, these properties will not work unless the position property is set first. They also work differently depending on the positioning method.

There are four different positioning methods.

Continue reading ‘CSS Positioning: Relative Absolute’ »

CSS Display and Visibility

Hiding an Element – display:none or visibility:hidden

Hiding an element can be done by setting the display property to “none” or the visibility property to “hidden”. However, notice that these two methods produce different results:

visibility:hidden hides an element, but it will still take up the same space as before. The element will be hidden, but still affect the layout.

Example:
h1.hidden {visibility:hidden;} Continue reading ‘CSS Display and Visibility’ »

Grouping Selectors

In style sheets there are often elements with the same style.

h1{color:green;}
h2{color:green;}
p{color:green;}

To minimize the code, you can group selectors.

Separate each selector with a comma.

In the example below we have grouped the selectors from the code above:

h1,h2,p{color:green;} Continue reading ‘Grouping Selectors’ »

CSS Padding Properties

Padding

The padding clears an area around the content (inside the border) of an element. The padding is affected by the background color of the element.

The top, right, bottom, and left padding can be changed independently using separate properties. A shorthand padding property can also be used, to change all paddings at once. Continue reading ‘CSS Padding Properties’ »