XML technologies / ePUB / ePub für (In)Designer / Images, boxes and other design elements / Completing boxes and colored highlights / Boxes in HTML and CSS design

(Excerpt from “ePub für (In)Designer — Mit InDesign Schritt für Schritt zum E-Book” by Sascha Heck & Yves Apel)

Keep the file open or open it in an editor. With correct preparation, its end contains a div class named after your InDesign object style.

div.Kasten {
}

Now add the correct code. CSS offers many box-design options; we explain the most common, starting with spacing.

The CSS box model

CSS box model

Figure: The CSS box model.

Content: Element content, such as text or an image.

padding: Space between content and border, adopting the content’s background color.

border: Element border.

margin: Transparent outer spacing, or adopting the surrounding element’s background, such as body or div.

Think of div.Kasten as a virtual, initially invisible area between text sections. Its distances to text and page edges, corresponding to InDesign wrapping, are specified by (A) margin: [Abstand oben] [Abstand rechts] [Abstand unten] [Abstand links];. Other combinations are possible: (B) margin: [Abstand alle Seiten]; | (C) margin: [Abstand oben/unten] [Abstand links/rechts]; | (D) margin: [Abstand oben] [Abstand links/rechts] [Abstand unten];. Combinations are not restricted to margin.

CSS padding settings

Figure: CSS padding settings.

div.Kasten {
  margin: 1em 2em 1em 2em;
}

The internal spacing is controlled by padding: [Abstand oben] [Abstand rechts] [Abstand unten] [Abstand links];.

div.Kasten {
  padding: 1em;
}

With inner and outer spacing defined, assign a background color to make the box visible using background-color: #991614;.

div.Kasten {
  background-color: #991614;
}

Finally, define the border, comprising width, color and style.

div.Kasten {
   border-width: 2px; /*Konturstärke*/
   border-style: solid; /*Konturstil*/
   border-color: black; /*Konturfarbe*/
}

Eight border styles are possible: border-style: solid; | border-style: dotted; | border-style: dashed; | border-style: double; | border-style: groove; | border-style: ridge; | border-style: inset; | border-style: outset;; most devices support only solid, dotted and dashed.

solid box border

Figure: solid box border.

dotted box border

Figure: dotted box border.

dashed box border

Figure: dashed box border.

Six CSS lines define the box:

div.Kasten {
  margin: 1em 2em 1em 2em;
  padding: 1em;
  border-width: 2px; /*Konturstärke*/
  border-style: solid; /*Konturstil*/
  border-color: black; /*Konturfarbe*/
  background-color: #991614;
}

Display of the example box

Figure: Display of the example box.

  

 

 

 

back to top