Jump to content
  • 0

Вставка HTML после определенного элемента


MC WEST
 Share

Question

Случилось такое что после каждого заголовка <h3> в правой колонке сайта, нужно вставить HTML код:

<div class="clr"></div>

пробовал через CSS с помощью :after, но текст вставляется как обычный, а не HTML.

Думал реализовать через JavaScript, но к сожалению с ним плохо знаком, подскажите пожалуйста уроком или советом :)

К сожалению ссылку на сайт предоставить не могу, т.к. сайт на локальном сервере.

Link to comment
Share on other sites

24 answers to this question

Recommended Posts

  • 0

Просто заголовок не обычный, он использует св-во float:left;, для правильного отображения фона.

<div class="module">				
<h3>Название модуля</h3>
Сюда надо вставить "<div class="clr"></div>"
<div class="module-content">Контент модуля</div>
</div>

и CSS:

h3 {
font-size: 20px;
font-weight: 900;
float: left;
text-transform: uppercase;
padding: 5px 6px 2px 5px;
color: #fff;
background: #1a1e27;
}

.module {
width: 350px;
display: block;
margin-bottom: 40px;
}

Щас додумался, поидее если задать .module-content ширину 350 пикселей, то все будет нормально?

Link to comment
Share on other sites

  • 0

Лови дружище.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Наибольшая сумма горизонали и вертикали</title>
<style type="text/css">
*{ margin: 0; padding: 0;}
h3 { float: left; margin-right: 10px;}
.clr { clear: both;}


</style>
</head>

<body>
<div id="wrap">
<h3 >Пункт 1</h3>
<h3>Пункт 2</h3>
<h3>Пункт 3</h3>
<h3>Пункт 4</h3>
</div>
<script type="text/javascript">
var wrap = document.getElementById('wrap');
var str = '<div class="clr"></div>';
var re = /(<[hH]3.*?>.+?<\/[hH]3>)/g;
wrap.innerHTML = wrap.innerHTML.replace(re,'$1' + str);

</script>
</body>
</html>

Link to comment
Share on other sites

  • 0

http://178.150.132.179/ - первые два модуля генерируются CMS Joomla, а следующие просто прописаны в index.php

Вот скрипт:

	<script type="text/javascript">
var wrap = document.getElementById('right-col');
var str = '<div class="clr"></div>';
var re = /(<[hH]3.*?>.+?<\/[hH]3>)/g;
wrap.innerHTML = wrap.innerHTML.replace(re,'$1' + str);
</script>

Edited by MC WEST
Link to comment
Share on other sites

  • 0

Значит это ты делаешь что то не так. Вот всё прекрасно работает.

.clr { clear: both;} - В стилях такое прописал?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Наибольшая сумма горизонали и вертикали</title>
<style type="text/css">
*{ margin: 0; padding: 0;}
h3 { float: left; margin-right: 10px;}
.clr { clear: both;}


</style>
</head>

<body>
<div id="right-col">

<div class="moduletable_menu">
<h3><cufon class="cufon cufon-canvas" alt="Категории" style="width: 112px; height: 20px;"><canvas width="129" height="25" style="width: 129px; height: 25px; top: -5px; left: -3px;"></canvas><cufontext>Категории</cufontext></cufon></h3>
<ul class="menu"><li class="active item1" id="current"><a href="http://178.150.132.179/"><span>Главная</span></a></li><li class="item2"><a href="/index.php?option=com_content&view=category&layout=blog&id=1&Itemid=2"><span>Новые шаблоны</span></a></li><li class="item3"><a href="/index.php?option=com_search&view=search&Itemid=3"><span>Поиск</span></a></li></ul> </div>
<div class="moduletable">
<h3><cufon class="cufon cufon-canvas" alt="Опрос" style="width: 67px; height: 20px;"><canvas width="87" height="25" style="width: 87px; height: 25px; top: -5px; left: -3px;"></canvas><cufontext>Опрос</cufontext></cufon></h3>
<form name="form2" method="post" action="index.php">

<table cellspacing="0" cellpadding="1" border="0" align="center" width="95%" class="poll">
<thead>
<tr>
<td style="font-weight: bold;">
Как Вам шаблон? </td>
</tr>
</thead>
<tbody><tr>
<td align="center">
<table cellspacing="0" cellpadding="0" border="0" class="pollstableborder">
<tbody><tr>
<td valign="top" class="sectiontableentry2">
<input type="radio" alt="1" value="1" id="voteid1" name="voteid">
</td>
<td valign="top" class="sectiontableentry2">
<label for="voteid1">
Один из лучших </label>
</td>
</tr>
<tr>
<td valign="top" class="sectiontableentry1">
<input type="radio" alt="2" value="2" id="voteid2" name="voteid">
</td>
<td valign="top" class="sectiontableentry1">
<label for="voteid2">
Хорошо </label>
</td>
</tr>
<tr>
<td valign="top" class="sectiontableentry2">
<input type="radio" alt="3" value="3" id="voteid3" name="voteid">
</td>
<td valign="top" class="sectiontableentry2">
<label for="voteid3">
Нормально </label>
</td>
</tr>
<tr>
<td valign="top" class="sectiontableentry1">
<input type="radio" alt="4" value="4" id="voteid4" name="voteid">
</td>
<td valign="top" class="sectiontableentry1">
<label for="voteid4">
Ужасно </label>
</td>
</tr>
</tbody></table>
</td>
</tr>
<tr>
<td>
<div align="center">
<input type="submit" value="ОК" class="button" name="task_button">
 
<input type="button" onclick="document.location.href='/index.php?option=com_poll&id=1:2010-10-12-13-17-55'" value="Итоги" class="button" name="option">
</div>
</td>
</tr>
</tbody></table>

<input type="hidden" value="com_poll" name="option">
<input type="hidden" value="vote" name="task">
<input type="hidden" value="1" name="id">
<input type="hidden" value="1" name="225dea56e4e7bc4178d4131d653b6524"></form> </div>


<div class="module">
<h3 class="special-h3"><cufon class="cufon cufon-canvas" alt="О " style="width: 19px; height: 20px;"><canvas width="47" height="25" style="width: 47px; height: 25px; top: -5px; left: -3px;"></canvas><cufontext>О </cufontext></cufon><cufon class="cufon cufon-canvas" alt="авторе" style="width: 73px; height: 20px;"><canvas width="94" height="25" style="width: 94px; height: 25px; top: -5px; left: -3px;"></canvas><cufontext>авторе</cufontext></cufon></h3>
<div class="clr"></div>
<div class="module-content">
<img height="99" align="left" width="99" class="about" src="/templates/brilliant/img/author.png">
<span class="name"><cufon class="cufon cufon-canvas" alt="Андрей " style="width: 79px; height: 22px;"><canvas width="106" height="27" style="width: 106px; height: 27px; top: -4px; left: -3px;"></canvas><cufontext>Андрей </cufontext></cufon><cufon class="cufon cufon-canvas" alt="Емельяненко" style="width: 129px; height: 22px;"><canvas width="149" height="27" style="width: 149px; height: 27px; top: -4px; left: -3px;"></canvas><cufontext>Емельяненко</cufontext></cufon></span>
<span class="post"><cufon class="cufon cufon-canvas" alt="Веб-Разарботчик" style="width: 152px; height: 20px;"><canvas width="172" height="24" style="width: 172px; height: 24px; top: -4px; left: -4px;"></canvas><cufontext>Веб-Разарботчик</cufontext></cufon></span>
<br><br>
<p><cufon class="cufon cufon-canvas" alt="Lorem " style="width: 50px; height: 15px;"><canvas width="67" height="18" style="width: 67px; height: 18px; top: -3px; left: -3px;"></canvas><cufontext>Lorem </cufontext></cufon><cufon class="cufon cufon-canvas" alt="Ipsum " style="width: 49px; height: 15px;"><canvas width="67" height="18" style="width: 67px; height: 18px; top: -3px; left: -3px;"></canvas><cufontext>Ipsum </cufontext></cufon><cufon class="cufon cufon-canvas" alt="is " style="width: 17px; height: 15px;"><canvas width="34" height="18" style="width: 34px; height: 18px; top: -3px; left: -3px;"></canvas><cufontext>is </cufontext></cufon><cufon class="cufon cufon-canvas" alt="simply " style="width: 53px; height: 15px;"><canvas width="70" height="18" style="width: 70px; height: 18px; top: -3px; left: -3px;"></canvas><cufontext>simply </cufontext></cufon><cufon class="cufon cufon-canvas" alt="dummy " style="width: 59px; height: 15px;"><canvas width="76" height="18" style="width: 76px; height: 18px; top: -3px; left: -3px;"></canvas><cufontext>dummy </cufontext></cufon><cufon class="cufon cufon-canvas" alt="text " style="width: 34px; height: 15px;"><canvas width="51" height="18" style="width: 51px; height: 18px; top: -3px; left: -3px;"></canvas><cufontext>text </cufontext></cufon><cufon class="cufon cufon-canvas" alt="of " style="width: 20px; height: 15px;"><canvas width="37" height="18" style="width: 37px; height: 18px; top: -3px; left: -3px;"></canvas><cufontext>of </cufontext></cufon><cufon class="cufon cufon-canvas" alt="the " style="width: 29px; height: 15px;"><canvas width="46" height="18" style="width: 46px; height: 18px; top: -3px; left: -3px;"></canvas><cufontext>the </cufontext></cufon><cufon class="cufon cufon-canvas" alt="printing " style="width: 65px; height: 15px;"><canvas width="82" height="18" style="width: 82px; height: 18px; top: -3px; left: -3px;"></canvas><cufontext>printing </cufontext></cufon><cufon class="cufon cufon-canvas" alt="and " style="width: 33px; height: 15px;"><canvas width="50" height="18" style="width: 50px; height: 18px; top: -3px; left: -3px;"></canvas><cufontext>and </cufontext></cufon><cufon class="cufon cufon-canvas" alt="typesetting " style="width: 88px; height: 15px;"><canvas width="106" height="18" style="width: 106px; height: 18px; top: -3px; left: -3px;"></canvas><cufontext>typesetting </cufontext></cufon><cufon class="cufon cufon-canvas" alt="industry. " style="width: 70px; height: 15px;"><canvas width="87" height="18" style="width: 87px; height: 18px; top: -3px; left: -3px;"></canvas><cufontext>industry. </cufontext></cufon><cufon class="cufon cufon-canvas" alt="Lorem " style="width: 50px; height: 15px;"><canvas width="67" height="18" style="width: 67px; height: 18px; top: -3px; left: -3px;"></canvas><cufontext>Lorem </cufontext></cufon><cufon class="cufon cufon-canvas" alt="Ipsum " style="width: 49px; height: 15px;"><canvas width="67" height="18" style="width: 67px; height: 18px; top: -3px; left: -3px;"></canvas><cufontext>Ipsum </cufontext></cufon><cufon class="cufon cufon-canvas" alt="has " style="width: 31px; height: 15px;"><canvas width="48" height="18" style="width: 48px; height: 18px; top: -3px; left: -3px;"></canvas><cufontext>has </cufontext></cufon><cufon class="cufon cufon-canvas" alt="been " style="width: 40px; height: 15px;"><canvas width="58" height="18" style="width: 58px; height: 18px; top: -3px; left: -3px;"></canvas><cufontext>been </cufontext></cufon><cufon class="cufon cufon-canvas" alt="the " style="width: 29px; height: 15px;"><canvas width="46" height="18" style="width: 46px; height: 18px; top: -3px; left: -3px;"></canvas><cufontext>the </cufontext></cufon><cufon class="cufon cufon-canvas" alt="industry's " style="width: 77px; height: 15px;"><canvas width="94" height="18" style="width: 94px; height: 18px; top: -3px; left: -3px;"></canvas><cufontext>industry's </cufontext></cufon><cufon class="cufon cufon-canvas" alt="standard " style="width: 71px; height: 15px;"><canvas width="89" height="18" style="width: 89px; height: 18px; top: -3px; left: -3px;"></canvas><cufontext>standard </cufontext></cufon><cufon class="cufon cufon-canvas" alt="dummy " style="width: 59px; height: 15px;"><canvas width="76" height="18" style="width: 76px; height: 18px; top: -3px; left: -3px;"></canvas><cufontext>dummy </cufontext></cufon><cufon class="cufon cufon-canvas" alt="text " style="width: 34px; height: 15px;"><canvas width="51" height="18" style="width: 51px; height: 18px; top: -3px; left: -3px;"></canvas><cufontext>text </cufontext></cufon><cufon class="cufon cufon-canvas" alt="ever " style="width: 36px; height: 15px;"><canvas width="53" height="18" style="width: 53px; height: 18px; top: -3px; left: -3px;"></canvas><cufontext>ever </cufontext></cufon><cufon class="cufon cufon-canvas" alt="since " style="width: 42px; height: 15px;"><canvas width="60" height="18" style="width: 60px; height: 18px; top: -3px; left: -3px;"></canvas><cufontext>since </cufontext></cufon><cufon class="cufon cufon-canvas" alt="the " style="width: 29px; height: 15px;"><canvas width="46" height="18" style="width: 46px; height: 18px; top: -3px; left: -3px;"></canvas><cufontext>the </cufontext></cufon><cufon class="cufon cufon-canvas" alt="1500s, " style="width: 52px; height: 15px;"><canvas width="69" height="18" style="width: 69px; height: 18px; top: -3px; left: -3px;"></canvas><cufontext>1500s, </cufontext></cufon><cufon class="cufon cufon-canvas" alt="when " style="width: 44px; height: 15px;"><canvas width="62" height="18" style="width: 62px; height: 18px; top: -3px; left: -3px;"></canvas><cufontext>when </cufontext></cufon><cufon class="cufon cufon-canvas" alt="an " style="width: 23px; height: 15px;"><canvas width="41" height="18" style="width: 41px; height: 18px; top: -3px; left: -3px;"></canvas><cufontext>an </cufontext></cufon><cufon class="cufon cufon-canvas" alt="unknown " style="width: 72px; height: 15px;"><canvas width="90" height="18" style="width: 90px; height: 18px; top: -3px; left: -3px;"></canvas><cufontext>unknown </cufontext></cufon><cufon class="cufon cufon-canvas" alt="printer " style="width: 55px; height: 15px;"><canvas width="73" height="18" style="width: 73px; height: 18px; top: -3px; left: -3px;"></canvas><cufontext>printer </cufontext></cufon><cufon class="cufon cufon-canvas" alt="took " style="width: 38px; height: 15px;"><canvas width="55" height="18" style="width: 55px; height: 18px; top: -3px; left: -3px;"></canvas><cufontext>took </cufontext></cufon><cufon class="cufon cufon-canvas" alt="a " style="width: 14px; height: 15px;"><canvas width="32" height="18" style="width: 32px; height: 18px; top: -3px; left: -3px;"></canvas><cufontext>a </cufontext></cufon><cufon class="cufon cufon-canvas" alt="galley " style="width: 50px; height: 15px;"><canvas width="67" height="18" style="width: 67px; height: 18px; top: -3px; left: -3px;"></canvas><cufontext>galley </cufontext></cufon><cufon class="cufon cufon-canvas" alt="of " style="width: 20px; height: 15px;"><canvas width="37" height="18" style="width: 37px; height: 18px; top: -3px; left: -3px;"></canvas><cufontext>of </cufontext></cufon><cufon class="cufon cufon-canvas" alt="type " style="width: 37px; height: 15px;"><canvas width="54" height="18" style="width: 54px; height: 18px; top: -3px; left: -3px;"></canvas><cufontext>type </cufontext></cufon><cufon class="cufon cufon-canvas" alt="and " style="width: 33px; height: 15px;"><canvas width="50" height="18" style="width: 50px; height: 18px; top: -3px; left: -3px;"></canvas><cufontext>and </cufontext></cufon><cufon class="cufon cufon-canvas" alt="scrambled " style="width: 80px; height: 15px;"><canvas width="98" height="18" style="width: 98px; height: 18px; top: -3px; left: -3px;"></canvas><cufontext>scrambled </cufontext></cufon><cufon class="cufon cufon-canvas" alt="it " style="width: 16px; height: 15px;"><canvas width="33" height="18" style="width: 33px; height: 18px; top: -3px; left: -3px;"></canvas><cufontext>it </cufontext></cufon><cufon class="cufon cufon-canvas" alt="to " style="width: 20px; height: 15px;"><canvas width="38" height="18" style="width: 38px; height: 18px; top: -3px; left: -3px;"></canvas><cufontext>to </cufontext></cufon><cufon class="cufon cufon-canvas" alt="make " style="width: 44px; height: 15px;"><canvas width="62" height="18" style="width: 62px; height: 18px; top: -3px; left: -3px;"></canvas><cufontext>make </cufontext></cufon><cufon class="cufon cufon-canvas" alt="a " style="width: 14px; height: 15px;"><canvas width="32" height="18" style="width: 32px; height: 18px; top: -3px; left: -3px;"></canvas><cufontext>a </cufontext></cufon><cufon class="cufon cufon-canvas" alt="type " style="width: 37px; height: 15px;"><canvas width="54" height="18" style="width: 54px; height: 18px; top: -3px; left: -3px;"></canvas><cufontext>type </cufontext></cufon><cufon class="cufon cufon-canvas" alt="specimen " style="width: 74px; height: 15px;"><canvas width="91" height="18" style="width: 91px; height: 18px; top: -3px; left: -3px;"></canvas><cufontext>specimen </cufontext></cufon><cufon class="cufon cufon-canvas" alt="book." style="width: 42px; height: 15px;"><canvas width="59" height="18" style="width: 59px; height: 18px; top: -3px; left: -3px;"></canvas><cufontext>book.</cufontext></cufon></p>
</div>
<div class="clr"></div>
</div>

<div class="module">
<h3 class="special-h3"><cufon class="cufon cufon-canvas" alt="Спонсоры" style="width: 110px; height: 20px;"><canvas width="124" height="25" style="width: 124px; height: 25px; top: -5px; left: -3px;"></canvas><cufontext>Спонсоры</cufontext></cufon></h3>
<div class="clr"></div>
<div class="module-content">
<img height="166" width="166" src="/templates/brilliant/img/advert.jpg">
<img height="166" width="166" src="/templates/brilliant/img/advert.jpg">
</div>
<div class="clr"></div>
</div>

<div class="module">
<h3 class="special-h3"><cufon class="cufon cufon-canvas" alt="Категории" style="width: 112px; height: 20px;"><canvas width="129" height="25" style="width: 129px; height: 25px; top: -5px; left: -3px;"></canvas><cufontext>Категории</cufontext></cufon></h3>
<div class="clr"></div>
<div class="module-content">
<ul id="menu">
<li><a href="#"><cufon class="cufon cufon-canvas" alt="Корпоративные " style="width: 136px; height: 15px;"><canvas width="153" height="19" style="width: 153px; height: 19px; top: -3px; left: -2px;"></canvas><cufontext>Корпоративные </cufontext></cufon><cufon class="cufon cufon-canvas" alt="сайты" style="width: 49px; height: 15px;"><canvas width="59" height="19" style="width: 59px; height: 19px; top: -3px; left: -2px;"></canvas><cufontext>сайты</cufontext></cufon></a></li>
<li><a href="#"><cufon class="cufon cufon-canvas" alt="Сайты-портфолио" style="width: 147px; height: 15px;"><canvas width="159" height="19" style="width: 159px; height: 19px; top: -3px; left: -2px;"></canvas><cufontext>Сайты-портфолио</cufontext></cufon></a></li>
<li><a href="#"><cufon class="cufon cufon-canvas" alt="Сайты-галлереи" style="width: 133px; height: 15px;"><canvas width="144" height="19" style="width: 144px; height: 19px; top: -3px; left: -2px;"></canvas><cufontext>Сайты-галлереи</cufontext></cufon></a></li>
<li><a href="#"><cufon class="cufon cufon-canvas" alt="Блоги" style="width: 48px; height: 15px;"><canvas width="60" height="19" style="width: 60px; height: 19px; top: -3px; left: -2px;"></canvas><cufontext>Блоги</cufontext></cufon></a></li>
<li><a href="#"><cufon class="cufon cufon-canvas" alt="Онлайн-магазины" style="width: 147px; height: 15px;"><canvas width="157" height="19" style="width: 157px; height: 19px; top: -3px; left: -2px;"></canvas><cufontext>Онлайн-магазины</cufontext></cufon></a></li>
<li><a href="#"><cufon class="cufon cufon-canvas" alt="Социальные " style="width: 107px; height: 15px;"><canvas width="124" height="19" style="width: 124px; height: 19px; top: -3px; left: -2px;"></canvas><cufontext>Социальные </cufontext></cufon><cufon class="cufon cufon-canvas" alt="сайты" style="width: 49px; height: 15px;"><canvas width="59" height="19" style="width: 59px; height: 19px; top: -3px; left: -2px;"></canvas><cufontext>сайты</cufontext></cufon></a></li>
</ul>
</div>
<div class="clr"></div>
</div>

<div class="clr"></div>
</div>
<script type="text/javascript">
var wrap = document.getElementById('right-col');
var str = '<div class="clr"></div>';
var re = /(<[hH]3[\s\S]*?>[\s\S]+?<\/[hH]3>)/g;
wrap.innerHTML = wrap.innerHTML.replace(re,'$1' + str);

</script>
</body>
</html>

Link to comment
Share on other sites

  • 0

Все работает) большое спасибо) я просто скрипт вставлял в head, а щас поставил в body, и все заработало. Огромное спасибо!

Я извиняюсь, а зачем float:left заголовку?

Чтобы фон заголовка, не растягивался на всю длину блока, а только на занимаемое словами место.

Link to comment
Share on other sites

  • 0

Первая мысль - самая правильная. Фтопку пустые оформительские дивы, :after - труЪ CSS-путь. Просто надо было найти в CSSнике объявление класса .clr и заменить на .clr, h3:after - ну и для подстраховки добавить туда display:block и content:'.'

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