javascript - Force no line-break on pseudo element (:after) -
http://codepen.io/ethanclevenger91/pen/vnjoyp
edit: codepen showcases variety of proposed solutions
if resize available space in pen, you'll see in top heading, reach point diamond (created via pseudo-element) line-break, last word not, pseudo-element on own line.
i'd fashion solution using pure css behaves second heading, last word breaks if pseudo-element breaks. i've implemented via javascript, content of headings come database.
html:
<div class="container"> <h1 class="alpha">a heading takes entire width</h1> <h1 class="alpha solution1">a solution require javascript</h1> </div>
scss:
$brand-primary:lightblue; $brand-secondary:darken(lightblue, 40%); @mixin hidpi($ratio) { @media (-webkit-min-device-pixel-ratio: $ratio), (min-resolution: #{round($ratio*96)}dpi) { @content; } } body { position:relative; height:100vh; background:$brand-primary; width:100%; } .container { top:50%; transform:translatey(-50%); position:relative; } .alpha { text-align:center; color:$brand-secondary; &:not(.solution1) { &:after { content:''; @extend %diamond; margin-left:11px; } } &.solution1 { .diamond { @extend %diamond; margin-left:11px; } } } %diamond { width:13px; height:14px; display:inline-block; transform:rotate(-45deg); border:1px solid $brand-secondary; vertical-align:middle; @include hidpi(2) { height:13px; } }
js:
jquery(document).ready(function($) { var content = $('.solution1').html(); var lastchar = content.slice(-1); $('.solution1').html(content.slice(0, -1)+'<span style="white-space:nowrap">'+lastchar+'<span class="diamond"></span></span>'); });
you can go using standard diamond utf8: ◇
.
if let :after
display: inline
not break because you're not adding space between last word , it.
.alpha.solution3:after { display: inline; content: "◇"; font-weight: normal; font-size: 1.2em; }
<h1 class="alpha solution3">a solution not require javascript neither span</h1>
if character bold you, can make own font, use font-face
, go it.
http://codepen.io/anon/pen/boxjzo
this work on browsers not support transform
.
Comments
Post a Comment