を使用してPDFに変換される請求書のHTML / CSSテンプレートに取り組んでいますwkhtmltopdf
。デザインの一部は、次のように見える要素です。
要素内のテキストは可変長にすることができます。要素の背後にあるロジックは非常に単純です。改行が存在する場合は常に、行の終わりをくさびで飾ります。css-tricks.comでMatthew Pennell's Triple Element Method
紹介されているように、各行にパディングを追加しました。必要に応じて調整しました。
.padded-multiline {
line-height: 1.4;
padding: 0.005in 0;
border-left: 0.16in solid #E7E7E9;
}
.padded-multiline p {
background-color: #E7E7E9;
padding: 0.02in 0;
display: inline;
margin: 0;
}
.padded-multiline p span {
position: relative;
left: -0.08in;
}
問題は、くさびで線を飾る方法がわからないことです。CSSソリューションが欲しいのですが、これが実際に実現できるかどうかはわかりません。テキストが1行だった場合、要素の後に灰色のCSS三角形をかなり簡単に追加できました。または、同じ効果を実現する白い背景上の三角形で構成される背景画像を追加することもできます。しかし、要素が複数行であるため、アイデアが不足しています。
background-repeat: repeat-y
ネストされた要素での使用は、最後の行に背景を追加するだけなので、私が期待するようには機能しないようです。::first-line
疑似セレクターがあることは知っていますが、私が理解していることから::nth-line
、同じタイプの数量詞はないか、他にありません。
現時点では、JavaScriptを使用してテキストを個々の要素に分割し、それらを複数行の要素ではなく複数の単一行の要素として扱うことが唯一の実行可能な解決策であると思います。しかし、JavaScriptの使用は避けたかったのです。それは、PDF生成にオーバーヘッドが増え、私にとってはちょっとハックな感じがするからです。
何か案は?
注意:
wkhtmltopdfおよびwkhtmltoimageは、Qt WebKitレンダリングエンジンを使用してHTMLをPDFおよびさまざまな画像形式にレンダリングするためのオープンソース(LGPLv3)コマンドラインツールです。
手動で改行を挿入しないという事実を考慮すると、最後の行だけが最後まで埋められず、前のすべての行が埋められます。次に、最後のエッジだけを検討し、他のエッジを一緒に検討することができます。
ここにアイデアがあります:
p {
line-height:20px;
padding:0 30px;
background:
linear-gradient(to top left,#fff 49%,transparent 50%) top right/20px 20px repeat-y,
grey;
overflow:hidden;
}
span {
position:relative;
display:inline-block;
vertical-align:bottom;
}
span:before {
content:"";
position:absolute;
left:30px; /*equal to padding*/
bottom:0px;
height:20px; /*equal to line-height*/
background:
linear-gradient(to top left,#fff 49%,grey 50%) top left/20px 20px no-repeat,
#fff;
right:-100vw;
}
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec tellus ipsum, posuere a tincidunt non, consectetur et mi. Sed congue ornare lorem, et placerat velit tempus nec. Phasellus fringilla eleifend vestibulum. Nunc lobortis ipsum a nisi dignissim sollicitudin. Ut elit leo, ultrices mollis metus non,<span></span> </p>
改行が必要な場合は<br>
、使用せずに多くのp
タグを使用してください。
p {
line-height:20px;
padding:0 30px;
background:
linear-gradient(to top left,#fff 49%,transparent 50%) top right/20px 20px repeat-y,
grey;
overflow:hidden;
margin:0;
}
span {
position:relative;
display:inline-block;
vertical-align:bottom;
}
span:before {
content:"";
position:absolute;
left:30px; /*equal to padding*/
bottom:0px;
height:20px; /*equal to line-height*/
background:
linear-gradient(to top left,#fff 49%,grey 50%) top left/20px 20px no-repeat,
#fff;
right:-100vw;
}
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec tellus ipsum, posuere a tincidunt non, Ut elit leo, ultrices mollis metus non,<span></span> </p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec tellus ipsum, posuere a tincidunt non, consectetur et mi. Sed congue ornare lorem, et placerat velit tempus nec. Ut elit leo, ultrices mollis metus non,<span></span> </p>
更新
グラデーションの代わりに、単純な画像またはSVGを使用できます。
p {
line-height: 20px;
padding: 0 30px;
background: url('data:image/svg+xml;utf8,<svg viewBox="0 0 20 20" width="20" height="20" xmlns="http://www.w3.org/2000/svg"><polygon points="20 20,0 20, 20 0" fill="white" /></svg>') top right/20px 20px repeat-y;
background-color: grey;
overflow: hidden;
margin: 0;
}
span {
position: relative;
display: inline-block;
vertical-align: bottom;
}
span:before {
content: "";
position: absolute;
left: 30px; /*equal to padding*/
bottom: 0px;
height: 20px; /*equal to line-height*/
background: url('data:image/svg+xml;utf8,<svg viewBox="0 0 20 20" width="20" height="20" xmlns="http://www.w3.org/2000/svg"><polygon points="0 0,0 20, 20 0" fill="grey" /></svg>') top left/20px 20px no-repeat;
background-color: #fff;
right: -100vw;
}
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec tellus ipsum, posuere a tincidunt non, Ut elit leo, ultrices mollis metus non,<span></span> </p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec tellus ipsum, posuere a tincidunt non, consectetur et mi. Sed congue ornare lorem, et placerat velit tempus nec. Ut elit leo, ultrices mollis metus non,<span></span> </p>
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加