Skip to content

Instantly share code, notes, and snippets.

@elmimmo
Last active October 27, 2017 11:09
Show Gist options
  • Save elmimmo/00b5a2bc8e58287f8078 to your computer and use it in GitHub Desktop.
Save elmimmo/00b5a2bc8e58287f8078 to your computer and use it in GitHub Desktop.
Center images in ebooks
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8"/>
<title>Centering images in ebooks</title>
<!-- <link rel="stylesheet" type="text/css" href="style.css"/> -->
<style type="text/css">
.center-image {
margin: 1em auto;
text-align: center;
}
.center-image .image {
display: inline-block;
margin-left: auto;
margin-right: auto;
}
.image img {
display: block;
width: 100%;
height: auto;
margin: 0 auto;
}
.width-100 {
width: 100%;
}
.width-66 {
width: 66%;
}
.width-40px {
width: 40px;
padding: 0 10px 10px 10px;
box-sizing: content-box;
}
</style>
<!-- <link rel="stylesheet" type="text/css" href="responsive.css"/> -->
<style type="text/css">
/* Instead of embedding this CSS in here, it should reside in an external stylesheet (as commented out right above) so that other styles survive in ADE */
@media only screen and (max-width: 100ex) {
.width-66 {
width: 90%;
}
}
</style>
</head>
<body>
<p>100% wide image:</p>
<div class="center-image">
<div class="image width-100">
<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs=" alt=""/>
</div>
</div>
<p>66% wide image for standard viewports; 90% wide for small ones:</p>
<div class="center-image">
<div class="image width-66">
<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs=" alt=""/>
</div>
</div>
<p>Centered group of inline images:</p>
<div class="center-image">
<div class="image width-40px">
<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs=" alt=""/>
</div>
<div class="image width-40px">
<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs=" alt=""/>
</div>
<div class="image width-40px">
<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs=" alt=""/>
</div>
<div class="image width-40px">
<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs=" alt=""/>
</div>
</div>
</body>
</html>
@elmimmo
Copy link
Author

elmimmo commented Feb 16, 2015

Found defect in Google Play Books for web (2015-02), so I updated the compatibility notes in the comment above.

@elmimmo
Copy link
Author

elmimmo commented Feb 16, 2015

Noticed that Kindle Fire HDX has the same issue as Google Play Books for Android, incorrectly mapping CSS pixels to hardware pixels, so I updated the compatibility notes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment