Text in 'stairs' layout by CSS or Javascript?

◇◆丶佛笑我妖孽 提交于 2021-01-28 18:20:48

问题


I'm trying to achieve with kind of layout inhtml/css/jquery (see attach file)

Does anybody have any idea how this can be done ? I tried to put a css shape or svg for the line - which is fine, but how to make the text going this format ? Any highlight would be incredible, From my research I can't find any information like that ! thank you foe your time :)

EDIT: what about this format ?


回答1:


Here's one possibility in JS. It basically amounts to inserting floated divs of increasing widths, each one line-height high (I colored the divs red to make it more obvious). You could do this straight in the HTML if you wanted too.

var stairsHeight = 500;
var lineHeight = 20;
for (var y = lineHeight; y <= stairsHeight; y+=lineHeight) {
	$(".stairs").prepend('<div style="height:' + lineHeight + 'px; width:' + y + 'px; float:right; clear:right; background:red;"></div>');
}
.stairs {width:500px; height:500px; line-height:20px;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="stairs">
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem.
</div>



回答2:


There is a nice tutorial: https://sarasoueidan.com/blog/css-shapes/ . With such non-standard shape key is polygon() for either shape-inside or shape-outside . They really did nice illustration so it's easy to understand and apply to your own ideas.




回答3:


Css shapes

What you are looking for is called the shape-outside css property.

Currently only chrome supports this feature.

MDN link

And if you are wondering on how to use it:

.element {
  float: left;
  box-sizing: border-box;
  shape-outside: polygon(0 0, 0 100px, 100px 100px);
  -webkit-clip-path: polygon(0 0, 0 100px, 100px 100px);
  width: 100px;
  height: 100px;
  background-color: firebrick;
}
span {
  vertical-align: top;
}
<div class="element">

</div>
<p>Lorem ipsum dolar si amet Lorem ipsum
  <br>dolar si amet Lorem ipsum
  <br>dolar si amet Lorem ipsum dolar si amet Lorem ipsum dolar si amet Lorem ipsum dolar si amet Lorem ipsum dolar si amet</p>

Css shapes tutorial




回答4:


This might be a png but most definitely it's a canvas, you can draw any shapes using canvas with lineTo x, y coordinates, it uses javascript but even if you are not good with javascript there are really good sources around You can try it here: http://www.w3schools.com/html/tryit.asp?filename=tryhtml5_canvas_tut_path



来源:https://stackoverflow.com/questions/35490161/text-in-stairs-layout-by-css-or-javascript

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!