Thread: Stacked boxes
View Single Post
Old 11-12-2021, 12:11 PM   #3
RbnJrg
Wizard
RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.
 
Posts: 1,913
Karma: 9553087
Join Date: Mar 2013
Location: Rosario - Santa Fe - Argentina
Device: Kindle 4 NT
Quote:
Originally Posted by RbnJrg View Post
There are easier ways to do what you want But before giving you a "solution", I need to know if you are working on epub2 or epub3?
Well, here you have a solution for epub2 (with epub3 the code is simpler yet). you can get the layout you are looking for with the following code:

1. In your .xhtml sheet, write this:

Code:
  <div class="center">
    <p class="greyBox">99</p>
  </div>

  <h1 class="👻">C* H* A* P* T* E* R</h1>

  <h2>ZOE ALAKIS</h2>
2. In your .css stylesheet write:

Code:
h1 {
   text-align: center;
   color: white;
   background: black;
   font-family: sans-serif;
   font-size: 1.1em;
   margin: -7em 0 0;
}

h2 {
   text-align: center;   
   font-size: 1.4em;
   margin: 0;
}

.center {
   position: relative;
   z-index: -1;
   height: 8.4em;
   text-align: center;
}

.greyBox {
   display: inline-block;
   width: 2.4em;
   height: 100%;
   line-height: 2.4em; 
   margin-top: 0;
   color: white;
   background: #999;
   font-size: 3.5em;
   font-weight: bold;
   font-family: sans-serif;
   text-align: center;
}

.👻 { /* Don't change the name of this class */
   margin-bottom: 5.6em; /* 7 - 1.4 = 5.6 */
}
To center the chapter number vertically, use the property "line-height". Its value must be equal to the height of the square. And since I employed as height 8.4em and the font-size is 3.5em, then the line-height is 8.4/3.5=2.4.
Don't change the name of the class ".👻" (it's a hack for ADE 2). Epubcheck will give you an error message but don't pay attention.
Here you can watch how it looks under ADE and webkit:

Click image for larger version

Name:	Image1.png
Views:	156
Size:	160.9 KB
ID:	190165 Click image for larger version

Name:	Image2.png
Views:	164
Size:	116.2 KB
ID:	190166 Click image for larger version

Name:	Image3.png
Views:	161
Size:	75.3 KB
ID:	190167 Click image for larger version

Name:	Image4.png
Views:	160
Size:	50.1 KB
ID:	190168 Click image for larger version

Name:	Image5.png
Views:	162
Size:	52.6 KB
ID:	190169 Click image for larger version

Name:	Image6.png
Views:	159
Size:	58.8 KB
ID:	190170

Below you can check the respective epub.

Regards.
Attached Files
File Type: epub Box Heading.epub (2.8 KB, 151 views)

Last edited by RbnJrg; 11-12-2021 at 12:20 PM.
RbnJrg is offline   Reply With Quote