I noticed that float not working in mpdf.
In pure html, code below work fine,
Help be appreciate,
Thanks
<?php
$html = '
<html>
<head>
<style>
.section_left {
float : left;
width: 40%;
}
.section_right {
float : right;
width: 40%;
}
#customers
{
font-family:"Trebuchet MS", Arial, Helvetica, sans-serif;
font-size: '.$font_taille_corps.'pt;
border-collapse:collapse;
border: 2px solid grey;
}
#customers tr {
background-color: #d7dce1;
border-top: 1px solid #fff;
height:30px;
}
</style> </head>
<body>';
$section_left = "<table id='customers' style='page-break-inside: avoid; ' class='section_left' ><tr><td>Hello world</td></tr></table>" ;
$section_right = "<table id='customers' style='page-break-inside: avoid; ' class='section_right' ><tr><td>Some others word</td></tr></table>" ;
//I don't want to put table in div, because MPDF slip data in 2 pages
$html.= $section_left.$section_right;
define('_MPDF_PATH','mpdf/');
include("mpdf/mpdf.php");
$mpdf=new mPDF('c','A4','','',20,15,50,25,10,5);
$mpdf->WriteHTML($html);
$mpdf->Output("test.pdf", "I");
exit;
[enter image description here]
When printing, this is result, not I whant
1
Floating for tables is not supported in mPDF.
For mPDF, I'd recommend using a single table with the two "subtables" as its cells (either as child table elements or as plain row/column combinations).
See https://mpdf.github.io/css-stylesheets/supported-css.html in mPDF documentation.
I have the following css for tabs,
.columbia-browser-blackberry .ui-tabs .ui-tabs-nav li a, .columbia-browser-
chrome .ui-tabs .ui-tabs-nav li a, .columbia-browser-iemobile .ui-tabs .ui-
tabs-nav li a, .columbia-browser-safari .ui-tabs .ui-tabs-nav li a,
.columbia-browser-moz.ui-tabs .ui-tabs-nav li a
{
padding: .5em 1em;
width: 225px;
word-wrap: initial;
height: 25px;
text-align: center;
display: inline;
}
Html
/**
* Page Tabs Control
* #TODO guerrics: overflowing tabs
*
* #param array pages - array of pages (default: map.values(page.subpages))
* #param str tab - name of the selected tab (default: __request.args.tab)
*/
var pages = $pages ?? map.values(page.subpages);
let pages = [ (p is str) ? wiki.getpage(p) : p foreach var p in pages];
var selectedTab = $tab ?? __request.args.tab;
// find the active tab page
var activeTab = [ tabpage foreach var tabpage in pages where tabpage.name ==
selectedTab ][0];
// no selected tab found, use first tab
if (!activeTab) {
let activeTab = pages[0];
}
<div class="mt-tabs ui-tabs ui-widget ui-widget-content ui-corner-all"
id="tabs">
<ul class="ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-
header ui-corner-all">
foreach(var tabpage in pages) {
<li id=('tab-'..tabpage.name) class=('ui-state-default ui-
corner-top'..(tabpage.name == activeTab.name ? " ui-tabs-selected ui-state-
active " : ""))>
<a href=(page.uri & {tab: tabpage.name})>
tabpage.title ?? "#" .. (__count + 1)
</a><span></span>
</li>
}
</ul>
<div class=("ui-tabs-panel ui-widget-content ui-corner-bottom"..(#pages
> 0 ? "" : "ui-state-empty"))>
if (activeTab) {
var contents = activeTab.contents;
if (contents) {
contents;
} else {
wiki.page(activeTab.path);
}
}
</div>
</div>
It works for Google chrome, but it doesn't work in Mozilla and Internet Explorer. I am trying to giving the tabs a uniform width of 225px.
Any help would be appreciated?
To apply width, set css property 'display' to either 'block' or 'inline-block'.
block: the element will sit in a single line. In such case you may want to set float so links are in the same line;
inline-block; the element will have height, width, etc, and multiple elements will sit in the same line (block).
try with:
display:inline-block
This is how it worked.
body .ui-tabs .ui-tabs-nav li a
{
padding: .5em 1em;
width:225px;
word-wrap: initial;
height: 25px;
text-align: center;
display: inline-block;
}
I have this code to show my images from a folder, but the problem is that it shows the images vertically (there are 9000 images) so the scrolling is ending.
I would like to know if it's possible to make the images horizontally?
The code I use:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html">
<title>Show images in folder</title>
<style type="text/css">
body {
margin: 0 auto 20px;
padding: 0;
background: #acacac;
text-align: center;
}
td {
padding: 0 0 50px;
text-align: center;
font: 9px sans-serif;
}
table {
width: 100%;
}
img {
display: block;
margin: 20px auto 10px;
max-width: 900px;
outline: none;
}
img:active {
max-width: 100%;
}
a:focus {
outline: none;
}
</style>
</head>
<body>
<?php
$folder = 'album1584/';
$filetype = '*.*';
$files = glob($folder.$filetype);
$count = count($files);
$sortedArray = array();
for ($i=0; $i<count($files); $i++) {
$sortedArray[date ('YmdHis', filemtime($files[$i]))] = $files[$i];
}
krsort($sortedArray);
echo '<table>';
foreach ($sortedArray as &$filename) {
#echo '<br>' . $filename;
echo '<tr><td>';
echo '<a name="'.$filename.'" href="#'.$filename.'"><img src="'.$filename.'" /></a>';
echo substr($filename,strlen($folder),strpos($filename, '.')-strlen($folder));
echo '</td></tr>';
}
echo '</table>';
?>
</body>
</html>
Images are listed vertically because they are contained in individual rows of the table. Also, in your CSS you set them to display as a block.
Remove display: block for images and don't put them in a table.
Also, don't display 9000 images at once. Use pagination.
try changing display: block; to display: inline-block; by styles for img tag.
EDIT:
Ok i think I know where the problem may be. You put each image in a separate table row so try to put more in one row or do not use table for that but simple container with the css change I gave you.
Is there any way to force a font to be monospaced using CSS?
By this I mean, using a non-monospace font, can you force the browser to render each character at a fixed width?
If this is for aligning digits in tables where some fonts (with traditional typography) render them by default with variable width (e.g. Segoe UI on Windows), you should look into CSS properties for:
font-variant-numeric: tabular-nums;
(this disables the proportional-nums default value for the numeric-spacing variant supported at least by OpenType fonts, and possibly by other font formats supported by the text renderer of your web browser for your particular platform)
No JavaScript needed! It is the cleanest way to disable the variable-width glyphs in these fonts and force them to use tabular digits (this generally uses in the same glyphs in the same font, but their leading and trailing gap is increased so the 10 digits from 0 to 9 will render at the same width; however some font may avoid the visual variable interdigit spacing and will slightly widden some digits, or could add bottom serifs to the foot of digit 1.
Note that this does not disable the variable height observed with Segoe UI (such as some digits will be x-height only like lowercase letters, others will have ascenders or descenders). These traditional digit forms may be disabled with CSS too, using
font-variant-numeric: lining-nums;
(this disables the default oldstyle-nums value for the numeric-figure variant supported at least by OpenType fonts, and by possibly other font formats supported by the text renderer of your web browser for your particular platform)
You can combine both:
font-variant-numeric: tabular-nums lining-nums;
--
The snippet below demonstrates this using a single proportional font (not monospaced!) featuring shape variants for digits, such as 'Segoe UI' on Windows and shows the different horizontal and vertical alignments produced.
Note that this style does not prohibit digits to change width if different styles like bold or italic is applied instead of medium roman as shown below because these will use different fonts with their own distinct metrics (this is not warrantied as well with all monospace fonts).
html { font-family: 'Segoe UI'; /* proportional with digit variants */ }
table { margin: 0; padding: 0; border: 1px solid #AAA; border-collapse: collapse; }
th, td { vertical-align:top; text-align:right; }
.unset { font-variant-numeric: unset; }
.traditional { font-variant-numeric: proportional-nums oldstyle-nums; }
.lining { font-variant-numeric: proportional-nums lining-nums; }
.tabular-old { font-variant-numeric: tabular-nums oldstyle-nums; }
.tabular-new { font-variant-numeric: tabular-nums lining-nums; }
.normal { font-variant-numeric: normal; }
<table>
<tr><th>unset<td><table width="100%" class="unset">
<tr><td>Rs12,34,56,789.00/Gal<td><i>Difference Rs86,41,97,532.11/Gal
<tr><td>Rs98,76,54,321.11/Gal<td><b>Total Rs1,11,11,11,110.11/Gal
</table>
<tr><th>traditional<td><table width="100%" class="traditional">
<tr><td>Rs12,34,56,789.00/Gal<td><i>Difference Rs86,41,97,532.11/Gal
<tr><td>Rs98,76,54,321.11/Gal<td><b>Total Rs1,11,11,11,110.11/Gal
</table>
<tr><th>lining<td><table width="100%" class="lining">
<tr><td>Rs12,34,56,789.00/Gal<td><i>Difference Rs86,41,97,532.11/Gal
<tr><td>Rs98,76,54,321.11/Gal<td><b>Total Rs1,11,11,11,110.11/Gal
</table>
<tr><th>tabular-old<td><table width="100%" class="tabular-old">
<tr><td>Rs12,34,56,789.00/Gal<td><i>Difference Rs86,41,97,532.11/Gal
<tr><td>Rs98,76,54,321.11/Gal<td><b>Total Rs1,11,11,11,110.11/Gal
</table>
<tr><th>tabular-new<td><table width="100%" class="tabular-new">
<tr><td>Rs12,34,56,789.00/Gal<td><i>Difference Rs86,41,97,532.11/Gal
<tr><td>Rs98,76,54,321.11/Gal<td><b>Total Rs1,11,11,11,110.11/Gal
</table>
<tr><th>normal<td><table width="100%" class="normal">
<tr><td>Rs12,34,56,789.00/Gal<td><i>Difference Rs86,41,97,532.11/Gal
<tr><td>Rs98,76,54,321.11/Gal<td><b>Total Rs1,11,11,11,110.11/Gal
</table>
</table>
Reference: https://developer.mozilla.org/docs/Web/CSS/font-variant-numeric
Why not think outside the box and inside a table for this:
<table cellpadding="0" cellspacing="0">
<tr><td>T</td><td>h</td><td>e</td><td></td><td>r</td><td>a</td><td>i</td><td>n</td><td></td><td>i</td><td>n</td><td></td><td>S</td><td>p</td><td>a</td><td>i</td><td>n</td><td></td><td>s</td><td>t</td><td>a</td><td>y</td><td>s</td></tr>
<tr><td>m</td><td>a</td><td>i</td><td>n</td><td>l</td><td>y</td><td></td><td>i</td><td>n</td><td></td><td>t</td><td>h</td><td>e</td><td></td><td>p</td><td>l</td><td>a</td><td>i</td><td>n</td><td>s</td><td>.</td></tr>
</table>
You can't do this with CSS. Even if you could, the result will look horrible:
If you really do need to do this, you could use JavaScript to wrap each individual character in an element (or just do it by hand):
function wrap_letters($element) {
for (var i = 0; i < $element.childNodes.length; i++) {
var $child = $element.childNodes[i];
if ($child.nodeType === Node.TEXT_NODE) {
var $wrapper = document.createDocumentFragment();
for (var i = 0; i < $child.nodeValue.length; i++) {
var $char = document.createElement('span');
$char.className = 'char';
$char.textContent = $child.nodeValue.charAt(i);
$wrapper.appendChild($char);
}
$element.replaceChild($wrapper, $child);
} else if ($child.nodeType === Node.ELEMENT_NODE) {
wrap_letters($child);
}
}
}
wrap_letters(document.querySelectorAll('.boxes')[0]);
wrap_letters(document.querySelectorAll('.boxes')[1]);
.char {
outline: 1px solid rgba(255, 0, 0, 0.5);
}
.monospace .char {
display: inline-block;
width: 15px;
text-align: center;
}
<h2 class="boxes">This is a title</h2>
<h2 class="boxes monospace">This is a title</h2>
I've just found the text-transform: full-width; experimental keyword, which:
[...] forces the writing of a character [...] inside a square [...]
text-transform | MDN
Combined with negative letter-spacing, you can get not-so-horrible results:
<style>
pre {
font-family: sans-serif;
text-transform: full-width;
letter-spacing: -.2em;
}
</style>
<!-- Fixed-width sans-serif -->
<pre>
. i I 1 | This is gonna be awesome.
ASDFGHJK | This is gonna be awesome.
</pre>
<!-- Default font -->
. i I 1 | This is gonna be awesome.
<br>
ASDFGHJK | This is gonna be awesome.
Well, you didn't say using only CSS. It is possible to do this with just a little bit of Javascript to wrap each letter in a span. The rest is in CSS...
window.onload = function() {
const secondP = document.getElementById('fixed');
const text = secondP.innerText;
const newText = text.split('').map(c => {
const span = `<span>${c}</span>`;
return span;
}).join('');
secondP.innerHTML = newText;
}
p {
position: relative;
border: 1px solid black;
border-radius: 1em;
padding: 1em;
margin: 3em 1em;
}
p::after {
content: attr(name);
display: block;
background-color: white;
color: green;
padding: 0 0.5em;
position: absolute;
top: -0.6em;
left: 0.5em;
}
#fixed span {
display: inline-block;
width: 1em;
text-align: center;
}
<p id="variable" name="Variable Width">It might not look nice, but with a little Javascript, I can force a variable width font to act like a fixed-width font.</p>
<p id="fixed" name="Fixed Width">It might not look nice, but with a little Javascript, I can force a variable width font to act like a fixed-width font.</p>
In a paragraph with regular text, it looks terrible, but There are instances when this makes sense. Icon fonts and Unicode symbols could both make use of this technique.
I found this question while trying to find a solution for Unicode symbols that were shifting regular text to the right when they were replaced with other Unicode symbols.
I've done a verry pretty thing sometimes for countdowns:
HTML:
<div class="counter">
<span class="counter-digit counter-digit-0">2</span>
<span class="counter-digit counter-digit-1">4</span>
<span class="counter-digit counter-digit-divider">/</span>
<span class="counter-digit counter-digit-2">5</span>
<span class="counter-digit counter-digit-3">7</span>
</div>
SCSS:
$digit-width: 18px;
.counter {
text-align: center;
font-size: $digit-width;
position: relative;
width : $digit-width * 4.5;
margin: 0 auto;
height: 48px;
}
.counter-digit {
position: absolute;
top: 0;
width: $digit-width;
height: 48px;
line-height: 48px;
padding: 0 1px;
&:nth-child(1) { left: 0; text-align: right; }
&:nth-child(2) { left: $digit-width * 1; text-align: left;}
&:nth-child(3) { left: $digit-width * 2; text-align: center; width: $digit-width / 2} // the divider (/)
&:nth-child(4) { left: $digit-width * 2.5; text-align: right;}
&:nth-child(5) { left: $digit-width * 3.5; text-align: left;}
}
You can wrap the seconds digits in a span and style it like...
.time-seconds {display: inline-block;width: .52em;text-align: center;}
See Snippet.
function padlength(what) {
var output = (what.toString().length == 1) ? "0" + what : what;
return output;
}
function displaytime() {
var serverdate = new Date();
var dd = "am";
var hh = serverdate.getHours();
var h = hh;
if (h >= 12) {
h = hh - 12;
dd = "pm";
}
if (h == 0) {
h = 12;
}
h = parseInt(h);
var sec = String(padlength(serverdate.getSeconds()));
var timeFixed = h + ':' + padlength(serverdate.getMinutes()) + ':<span class="time-seconds">' + sec.charAt(0) + '</span><span class="time-seconds">' + sec.charAt(1) + '</span> ' + dd;
timeVariable = h + ':' + padlength(serverdate.getMinutes()) + ':' + sec + ' ' + dd;
document.getElementById("servertime-fixed").innerHTML = timeFixed;
document.getElementById("servertime-variable").innerHTML = timeVariable;
}
window.onload = function() {
displaytime();
setInterval("displaytime()", 1000);
};
center {
font-size: 3em;
font-family: Cursive;
}
.time-seconds {
display: inline-block;
width: .52em;
text-align: center;
}
<html>
<body>
<center id="servertime-fixed">H:MM:SS mm</center>
<center id="servertime-variable">H:MM:<span class="time-seconds">S</span><span class="time-seconds">S</span> mm</center>
</body>
</html>
i just had the same problem. my font didn't support font-variant-numeric: tabular-nums (which i knew about) and the other solutions didn't suit me, so i came up with this one - in my case i just had to expand letter spacing and then squash the (gigantic) zeros to make it look acceptable:
CSS:
.squashzeros { letter-spacing:.2em; }
.squashzeros span { display:inline-block; margin:0 -.09em; }
JS:
document.querySelectorAll('.squashzeros').forEach((o)=>{
o.innerHTML = o.innerText.replaceAll(/0/g,'<span>0</span>');
});
unfortunately i found no css-only solution.
No, not unless it's an actual mono-spaced font.
A mix of answers from Márton Tamás and nïkö:
document.querySelectorAll('pre').forEach( o => {
o.innerHTML = o.innerText.replace(/(.)/g, '<i>$1</i>');
});
pre i {
font-style: normal;
font-family: serif;
display: inline-block;
width: 0.65em;
text-align: center;
}
<!-- Fixed-width serif -->
<pre>
. i I 1 | This is gonna be awesome. 12:10
ASDFGHJK | This is gonna be awesome. 08:51
</pre>
<!-- Default font -->
. i I 1 | This is gonna be awesome. 12:10
<br>
ASDFGHJK | This is gonna be awesome. 08:51
No, there is no way to force anything in CSS. And there isn’t even a way to suggest that a non-monospace font be rendered as a monospace font.
I want to create a menu that looks like:
HOME | FOO | BAR | ABOUT | CONTACT
How might I go about doing this?
Here is what I have tried:
<lift:Menu.builder ul:class="menu" li_item:class="current" />
and
ul.menu li {
display: inline;
list-style-type: none;
text-transform: uppercase;
border-right: 1px solid white;
padding-right: 5px;
}
li.current span {
background: white;
color: black;
padding: 5px 5px 3px 5px;
font-size: 11px;
}
li.current a, a:visited, a:link {
color: white;
padding: 5px 5px 3px 5px;
font-size: 11px;
}
This gets close, but it doesn't look quite right. Also you end up with an extra line at the end. I want the lines to be the same height as the text.
http://lh5.ggpht.com/_5DxlOp9F12k/S2aFQHfupzI/AAAAAAAAJiY/Ds0IpEyu78I/s800/menu.png
There might be a cleaner way to do this. Once you've declared the urls in your sitemap, you can pretty much use them as regular links in your template. You would write them as pure html.
In Boot.scala:
val menus = List(
Menu(Loc("home", List("index"), "Home")),
Menu(Loc("foo", List("foo"), "Foo")),
Menu(Loc("bar", List("bar"), "Bar")),
Menu(Loc("about", List("about"), "About")),
Menu(Loc("contact", List("contact"), "Contact"))
)
LiftRules.setSiteMap(SiteMap(menus: _*))
In your template, e.g. index.html:
<div id="menu">
Home |
Foo |
Bar |
About |
Contact
</div>
Or as said Debilski, you can also call each menu item by their name. It would be more Lift-iesc.
<div id="menu">
<lift:Menu.item name="home"/>
<lift:Menu.item name="foo"/>
<lift:Menu.item name="bar"/>
<lift:Menu.item name="about"/>
<lift:Menu.item name="contact"/>
</div>
You can then add any style you want in an external stylesheet file or inside the page.
To get rid of the last line, you could use the :last-child pseudo-class:
ul.menu li:last-child {
border: none;
}
You might want to try to make the <li> elements have an inline-block display.
ul.menu li {
display: inline-block;
*display: inline; zoom: 1; /* inline-block under IE */
vertical-align: middle;
}
This way, they will behave much more like block elements and might sync with the links. Also, you can try playing with the line-height property instead of adding vertical padding, since the line-height will center the text vertically in a more precise manner.
Having found the other answers unsatisfactory I discovered my own solution...
(Note that I am new to Lift and believe menus are too difficult to code manually)
Solution
Partially use MenuWidget (from lift-widgets) to do the plumbing of enabling superfish menus
Don't use MenuWidget to render the menus as it doesn't do it properly
Use the standard Menu.build to render the menus
Add extra stuff to properly terminate the 'floating' effects of the menu
Add extra stuff to enable centered menus
Full solution is available at:
http://subversion.assembla.com/svn/freshcode_public/learn_scala/lift/src/main/scala/code/snippet/CustomMenu.scala
package code.snippet
import net.liftweb.widgets.menu.MenuWidget
import xml.{Text, NodeSeq}
object CustomMenu {
private def styleElem = {
<style type="text/css">
{Text(
".float-center-item {\n" +
" left: 50%;\n" +
" position: relative;\n" +
"}\n\n" +
".float-center-wrapper {\n" +
" float: right;\n" +
" position: relative;\n" +
" left: -50%;\n" +
"}\n\n" +
".float-clear {\n" +
" clear:both;\n" +
"}\n" +
"/* Margin fix for FireFox */\n" +
"ul.sf-menu {\n" +
" margin-bottom: 0\n" +
"}\n"
)}
</style>
}
def render(in: NodeSeq) = {
// Need to get MenuWidget to provide the plumbing
// We render menu ourselves because MenuWidget doesn't seem to do it properly.
MenuWidget(List("No Group")) ++
<head>
{styleElem}
</head> ++
<div class="float-center-wrapper">
<lift:Menu.builder top:class="sf-menu float-center-item" linkToSelf="true" expandAll="true"/>
</div> ++
// This div terminates the floating effects properly.
<div class="float-clear"></div>
}
}
Usage:
<div class="lift:CustomMenu">nothing</div>