css - Dynamic & Responsive Trapezoid Text Div -
this question has answer here:
- shape slanted side (responsive) 2 answers
i'm stuck on special design, need effect, keeping in mind text changed (since it's wordpress website) on 1 or many lines. http://postimg.org/image/ibqntp9t1/ achieved effect using pseudo elements , here code : css:
.box { background-color: #000; } .box:before { content:''; border-top: 100px solid transparent; border-right: 28px solid #000; width: 0px; height: 0px; position: absolute; top:0px; left: -13px; } the problem when content changes (example: 1 line of text), height of "before" thing not change ... ? thanks
edit: solution provided below isn't working (not working on firefox)
if values in em pseudo-element border triangle react changes in font size.
.box { background-color: #000; color: white; display: inline-block; position: relative; line-height: 2em; padding: 0 1em; margin: 0 2em; vertical-align: top; } .box:before { content: ''; border: 1em solid transparent; border-right-color: #000; border-bottom-color: #000; width: 0px; height: 0px; position: absolute; right: 100%; top: 0; } .larger { font-size: 24px; } <div class="box">standard</div> <div class="box larger">i'm larger</div> building on excellent answer @stewartside, clip path can applied pseudo-element.
.box { background-color: #000; color: white; display: inline-block; max-width: 250px; position: relative; line-height: 2em; padding: 0 1em; margin: 0 2em; vertical-align: top; } .larger { font-size: 24px; } .box:before { content: ''; background: inherit; width: 2em; height: 100%; -webkit-clip-path: polygon(50% 0%, 100% 0, 100% 100%, 0% 100%); clip-path: polygon(50% 0%, 100% 0, 100% 100%, 0% 100%); position: absolute; right: 100%; top: 0; margin-right:-1px; /* tweak due antialias issue ? */ } <div class="box">lorem</div> <div class="box larger">lorem ipsum dolor sit amet.</div>
Comments
Post a Comment