Jump to content
  • 0

газетная (журнальная) верстка


sc@r@bey
 Share

Question

8 answers to this question

Recommended Posts

  • 0

Как сделать это стилями я не знаю. Вероятнее всего никак. Я бв разбил текст с пожощью JS на несколько кусков определённой длины и распихал по блокам.

http://www.w3schools.com/jsref/jsref_slice_array.asp

Link to comment
Share on other sites

  • 0

Примерно так, В общем:

<style>
DIV {float: left; margin: 10px; padding: 10px; width: 150px; text-align: justify; border: solid 1px #000}
</style>

<div id='colonL'>sdf</div>
<div id='colonR'> sdf</div>

<script>
var myText = 'The patterns used in RegExp can be very simple, or very complicated, depending on what you~re trying to accomplish. To match a simple string like "Hello World!" is no harder then actually writing the string, but if you want to match an e-mail address or html tag, you might end up with a very complicated pattern that will use most of the syntax presented in the table below.';

var parts = Array( myText.slice(0, myText.length/2), myText.slice( myText.length/2,myText.length) );


document.getElementById('colonL').innerHTML = parts[0];
document.getElementById('colonR').innerHTML = parts[1];
</script>

Если требуется разбиение на значительное количество кусков. Скажем >3, то надо ввести цикл с инкрементированием точки начала слайса и проверкой длины строки.

Edited by XAOPT
Link to comment
Share on other sites

  • 0

Преобразовал в функцию (не проверял):

css:

.colum {
width:49%;
float:left;
}

html:

<div id="simpleText">The patterns used in RegExp can be very simple, or very complicated, depending on what you~re trying to accomplish. To match a simple string like "Hello World!" is no harder then actually writing the string, but if you want to match an e-mail address or html tag, you might end up with a very complicated pattern that will use most of the syntax presented in the table below.</div>

js:

function make2colums( id ){

elem = document.getElementById(id);

var parts = Array( elem.innerHTML.slice(0, elem.innerHTML.length/2), elem.innerHTML.slice( elem.innerHTML.length/2, elem.innerHTML.length) );

elem.innerHTML = '<div class="colum">' +parts[0]+ '</div><div class="colum">'+parts[1]+'</div>';

elem.style.overflow = 'hidden';

}

make2colums('simpleText');

Edited by Ялекс
Link to comment
Share on other sites

  • 0

В своём коде нашёл глюк в функциональности: слова разбиваются ничуть не по пробелу, а где попало. Поэтому преобразовал в:

<style>
DIV {float: left; margin: 10px; padding: 10px; width: 150px; text-align: justify; border: solid 1px #000}
</style>

<div id='colonL'>sdf</div>
<div id='colonR'> sdf</div>

<script>
var myText = 'The patterns used in RegExp can be very simple, or very complicated, depending on what you~re trying to accomplish. To match a simple string like "Hello World!" is no harder then actually writing the string, but if you want to match an e-mail address or html tag, you might end up with a very complicated pattern that will use most of the syntax presented in the table below.';

var reg = new RegExp("^(.){" + parseInt(myText.length/2) + "}(.*?)(\s+?)");
var result = reg.exec(myText);
var breaker = result[0].length - 1;

var parts = Array( myText.slice(0, breaker), myText.slice( breaker ,myText.length) );

document.getElementById('colonL').innerHTML = parts[0];
document.getElementById('colonR').innerHTML = parts[1];

</script>

2 Ялекс:

расширять dom-модель через свойство innerHTML допустимо, но считается крайне дурным тоном. Да и не всегда панацея. Например вот такая шутка не прокатит:

el.innerHTML= "<tabler><tr><td></td></tr>";
el.innerHTML += "<tr><td></td></tr></table>";

имхо лучше сразу привыкать пользоваться предусмотренными для этого функциями работы с деревом элементов.

Edited by XAOPT
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. See more about our Guidelines and Privacy Policy