simple css stylish printing woes - css

I am trying to "engineer" a cover page in html+css that shows appropriately in browsers, fits exactly on the (A4) page, and prints it with background colors. no javascript---it has to go to epub2. I am enclosing my first attempt at a prototype. (the actual cover page will of course be more complex.)
the bad news is that it's already not working. the worse news is that it's not working differently in firefox and chromium under linux---and I have not even tried safari, IE, OSX, iOS, Android, and Windows yet.
I am not averse to starting over, as long as I can remain in the html+css paradigm (i.e., I don't want to have to create a png bit image in TeX if it can be avoided.).
can this be done? or is it time to go back to TeX? advice appreciated.
regards,
/iaw
<?xml version='1.0' encoding='utf-8'?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<style type="text/css">
body {
color: #EEFFEE;
font-weight: bold;
page-break-inside: avoid;
margin: 0;
padding: 0;
}
* {
box-sizing: border-box;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
}
.page {
width: 21cm;
min-height: 29.7cm;
background-color: yellow !important;
color:black;
}
#page {
size: A4;
margin: 0;
}
#media print {
.page {
margin: 0;
page-break-after: always;
}
}
<!-- breaks color: -webkit-print-color-adjust: exact; -->
div.mytitle {
color:red;
background-color: blue;
text-align:center;
}
</style>
</head>
<body>
<div class="page">
<div class="mytitle">
<div style="margin:auto;font-size:100px;">Title</div>
subtitle
</div>
text
</div>
</body>
</html>

So in tinkering with your code if you move the -webkit-print-color-adjust: exact; to end of style it works for me in chrome ie and firefox. You can throw the code in http://www.onlinehtmleditor.net/ will see that it works as long as the line sits underneath your other rules. Hope it helps.
Will

Related

Why hyphens don't work with inner <span>?

I'm trying to get hyphens working on text that has <span> elements inside for highlighting. This seems to break the hyphen algorithm. Is there any way to fix the behaviour so that hyphens are placed the same as without <span> elements?
I'm not asking about a workaround like ­
The Code (sandbox: https://codepen.io/anon/pen/ayzxpM):
.limit {
max-width: 50px;
hyphens: auto;
font-size: 20px;
background-color: #eee;
}
span {
color: red;
}
<div class="limit">
<p>
Appletreefruitthing
</p>
<p>
Apple<span>tree</span>fruitthing
</p>
</div>
Using the lang attribute
Adding the lang attribute as Vadim Ovchinnikov suggested (<div class="limit" lang="en">) can lead better results on some platform/browser combinations. On Firefox 54, Windows 10 this is the result:
But even that seems buggy. The hyphen should be black in my opinon and the hyphen algorithm seems to miss the chance to make a line break between "fruit" and "tree", also completly ignoring the max-width that is set for the container.
Actually, it does work with spans, in a number of browsers. You just used a word that is not recognized. Here's an example with a normal English word, that works in IE (should also work in Edge) and FF on Win7:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=yes, initial-scale=1">
<title>Demo</title>
<style>
div {
max-width: 50px;
-webkit-hyphens: auto;
-moz-hyphens: auto;
-ms-hyphens: auto;
hyphens: auto;
font-size: 20px;
background-color: #eee;
}
span {
color: red;
}
</style>
</head>
<body>
<div>
<p>Incomprehensibilities</p>
<p>Incom<span>pre</span>hensibilities</p>
</div>
</body>
</html>
It does not work in Chrome on Win, because that currently (June 2018) still does not support hyphens at all. It also does not work in any iOS browser. So you will have to use soft hyphens after all. But as you stated that you were curious about the mechanism, I thought it worthwhile to still post this answer.
Chrome has only partial support for hyphens property (only Mac and Android platforms), so you can't make it work on Windows.
I don't see any difference between span presence and absence in Firefox, IE and Edge (all on Windows) for this code.
To make it work there you'll need set lang for container and add vendor prefixes (for -ms-hyphens IE/Edge and -webkit-hyphens for Safari). Demo:
.limit {
max-width: 50px;
font-size: 20px;
/* Safari */
-webkit-hyphens: auto;
/* IE, Edge */
-ms-hyphens: auto;
hyphens: auto;
background-color: #eee;
}
span {
color: red;
}
<div class="limit" lang="en">
<p>
Appletreefruitthing
</p>
<p>
Apple<span>tree</span>fruitthing
</p>
</div>
To work in all browsers you may shouldn't use CSS hyphens property, just insert ­ manually where you want hyphens.
.limit {
max-width: 50px;
font-size: 20px;
background-color: #eee;
}
span {
color: red;
}
<div class="limit">
<p>
Apple­tree­fruitthing
</p>
<p>
Apple­<span>tree</span>­fruitthing
</p>
</div>
hyphens: manual
togteher with
­
might work
see documentation here
https://css-tricks.com/almanac/properties/h/hyphenate/
this code on codepen seems to work
<div class="limit">
<p>
Appletreefruitthing
</p>
<p>
Apple­<span>tree</span>­fruit­thing
</p>
</div>
CSS
.limit {
hyphens: manual;
}

How to Write CSS Code for Mozilla Firefox Browser

i am using following css code for displaying flash text in my website. Flash Text Displaying in Chrome Browser nicely but not in Mozilla Firefox Browser. if i add this code width:650px; position: absolute; in css, displaying flash text in mozilla firebos nicely but not in chrome browser again. what should i do ??
.flash_text { padding-left: 50px; margin-left: 50px; }
Chrome Browser
Flash News : Training Programme on Personality Development
Mozilla Browser
Flash News :
Training Programme on Personality Development
how to make it proper display in both browser
the following css code working nicely for chrome browser
.flash_text { padding-left: 50px; margin-left: 50px; }
but not to Mozilla Browser
if i add this coding width:650px; position: absolute; displaying nicely but again chrome browser not displaying properly
what to do??
<html>
<head>
<style type="text/css">
#-moz-document url-prefix() {
h1 {
color: red;
}
}
</style>
</head>
<body>
<h1>This should be red in FF</h1>
</body>
</html>
All 3 browsers
<style type='text/css'>
/*This will work for chrome */
#categoryBackNextButtons
{
width:490px;
}
/*This will work for firefox*/
#-moz-document url-prefix() {
#categoryBackNextButtons{
width:486px;
}
}
</style>
<!--[if IE]>
<style type='text/css'>
/*This will work for IE*/
#categoryBackNextButtons
{
width:486px;
}
</style>
<![endif]-->

Why the page displays differently in IE8 and in chm (CSS "display: inline-block" issue)

On a Windows 7 with IE8, I find display: inline-block works quite well. However, after I compile the html file into chm, the page inside chm does not display well, as if inline-block does not take any effect.
Is there a way to have chm display the same as in IE8? Thank you.
My html source is:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>title to fill</title>
<meta charset="utf-8">
<style type="text/css">
#topcanvas {
z-index: 0;
top: 0;
left:0;
width:100%;
}
#chjnavi {
font-size: 10pt;
background-color: #eee;
padding: 0em 1em;
list-style-type: none;
position: relative;
z-index: 0;
}
#chjnavi ul {
margin: 0;
padding: 0;
}
#chjnavi li {
margin: 0;
padding: 8px;
display: inline-block;
/* !!! */
cursor: pointer;
}
</style>
</head>
<div id="topcanvas">
<div id="chjnavi">
<ul id="navibar_topul">
<li id="gentoc-t">item 1</li>
<li id="codecolor-t">item 2</li>
<li id="linenum-t">item 3</li>
</ul>
</div>
</div>
<p> My text. </p>
</body>
</html>
I find the answer finally. A post at west-wind.com tells me that I need to do a registry hack to have CHM reader(hh.exe) use IE8 rendering mode, otherwise, hh.exe uses at most IE7.
The registry hack is: Save the following code to a .reg file, then double click to import into registry.
REGEDIT4
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION]
"hh.exe"=dword:00001f40
OK. At least there is a solution for IE8 M$ system.
This question is related to Will the IE9 WebBrowser Control Support all of IE9's features, including SVG?
Instead of Inline-block you with have to use float:left; for IE8 as it doesn't support the property of Inline-block;
So this is what you will have to add to your code.
#chjnavi li {
margin: 0;
padding: 8px;
display: inline-block;
cursor: pointer;
float:left\9; /* This works for IE8 and below so apply this to your code*/
}

::selection from CSS affects layout

UPDATED:
I have found out this : margin: 0 auto; in the body {} block of the style sheet makes the header move. If I remove it, the banner header picture moves to the right. So that piece of line is the culprit. Does anybody know why?
As I have progressed (somewhat in the mystery) the question goes the other way.
I have this header file:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head profile="http://gmpg.org/xfn/11">
<link rel="stylesheet" href= "<?php echo base_url() ?>css/main_style.css" />
<link rel="stylesheet" href= "<?php echo base_url() ?>css/webform.css" />
</head>
<div id="header" class = "header"><h1 class="header">Real Estate Worldwide</h1> </div>
<body>
Which connects to this View file (I am on MVC)
The code in the view has nothing to do with the issue, I asked so we'll skip it.
Then I have this Style sheet.
<style type = "text/css">
::selection{ background-color: #E13300; color: white; }
::-moz-selection {background-color: #E13300; color: white; }
::webkit-selection{ background-color: #E13300; color: white; }
body {
background:url('../assets/uploads/miweb/gradient2.png');
background-repeat:repeat-x;
margin: 40px;
font: 13px/20px normal Helvetica, Arial, sans-serif;
color: #4F5155;
width:600px;
height:500px;
margin: 0 auto;
}
#header {
float:center;
background: url("../jq185/css/start/images/ui-bg_gloss-wave_75_2191c0_500x100.png") repeat-x scroll 50% 50% #2191C0;
font-family: 'trebuchet ms',geneva,arial,tahoma,sans-serif;
font-size: 10px;
margin: 0 auto;
margin-top: 2px;
padding: 0;
width: 1050px;
h2 {color:#ffffff;}
}
.header {
color:#ffffff;
}
ISSUE:
If I remove the 3 selection ::selection lines from the style sheet, the gradient effect, from the background body disappears.
If I leave it there, then the gradient effect works but then the #header jpg file that you see down the style sheet changes its position from the centered marging: 0 auto; to the right.
You have the full code there. I am puzzled as hell, because I cannot understand why something like ::selection would have a radical effect on the code snippet that refers to body {} where the call to the gradient picture is and also affects the font style within that body {}
II UPDATE
Here is the Controller
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Home_c extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->model('home_model');
}
public function index ()
{
$this->load->view('header');
$this->load->view('home');
}
public function load()
{ $this->load->view('header');
$data['paises'] = $this->home_model->devolverPaises();
$data['ofertas'] = $this->home_model->devolverOfertas();
I wouldn't be surprised if the strange effects you're seeing are tied to not having proper markup.
EDITED: As I made comments, I realized the may not have been clear enough for OP.
Your HTML structure needs to be valid, to start with:
<!DOCTYPE html >
<html>
<head>
<!-- title, meta, styles, etc go here -->
</head>
<body>
<!-- all your other content goes here -->
</body>
</html>
Make sure that when your page renders in the browser, when you look at View Source, you see those container elements in their proper places, nested as such. Better yet, run your page through a validation service. (http://validator.w3.org/ for example)
You have invalid CSS:
#header {
float:center; /* no such attribute... only left, right, none, or inherit */
h2 {color:#ffffff;} /* you can't nest tags inside other specs, except with the use of pre-processors like SASS or LESS */
}

replace image through css

I'm writing code in Stylish, a firefox plugin, to change the image that is showing up.
The image property doesn't have a div tag, so I have to use this:
img[src*="s_dschjungelplanet"]{
##########
}
So this will replace "s_dschjungelplanet" anywhere in the page, in a img src.
So my main problem is that I'm not sure HOW to tell it to replace the src="xxx".
Ta for replies
There is no easy way. I think you'd be better of with greasemonkey scripts, as with a simple such script you can change the url.
As far as I know, you can not change the url with css only. This was the closest I was able to come with css only:
img[src*="s_dschjungelplanet"]{
width:0;
height:70px;
padding-right:250px;
background:transparent url(http://i.stackoverflow.com/Content/Img/stackoverflow-logo-250.png) top left no-repeat;
}
You can try this:
img[src*="s_dschjungelplanet"]{
content: url("myfavorite.png");
}
Works in Chrome, not in Firefox...
img[src*="http://url-of-image-to-be-replaced.jpg"]{
background-image: url("https://url-of-image-you-want-to-display.jpg");
width:38px;
display:inline-block;
padding:38px 0 0 0;
height: 0px}
Change the width and padding to your specs. It's worked for me.
replace the img src
.image-replacement {
display: block;
-moz-box-sizing: border-box;
box-sizing: border-box;
background: url(https://www.whatsappimages.in/wp-content/uploads/2021/07/Top-HD-sad-quotes-for-whatsapp-status-in-hindi-Pics-Images-Download-Free.gif)
no-repeat;
width: 180px;
height: 236px;
padding-left: 180px;
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<h2>Image replaced with Image</h2>
<img class="image-replacement" src="https://images.unsplash.com/photo-1503023345310-bd7c1de61c7d?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxzZWFyY2h8MXx8aHVtYW58ZW58MHx8MHx8&w=1000&q=80" />
</body>
</html>

Resources