2016-04-27 52 views
1

我正在建立一個模板,其中90%的文字是相同的,只是項目標題和描述是不同的。我不想混淆或編輯每個文本中相同的文本,但在某些時候它在標題中的引用是不同的。動態插入以前只用HTML/CSS使用的文本?

反正在短短HTML5或CSS3,我可以拉以前用來動態填寫內容出題?幾乎就好像它是一個變量?

如...

標題下面總是(再次使用)

獨特的描述在這裏

內容那是相同的

您正在尋找標題這裏等等等等等等

無Javascript或其他語言,請 - 在如果不能與CSS3或HTML5在最壞的情況最基本的JavaScript可用哈克的方式來完成,但大多的JavaScript被阻止我編碼在網站上。

如果我們用非常簡單的Javascript這裏做到這一點是從項目的示例代碼...

<div class="content-inner block4 s-text" style="margin-top:-25px"> 
<h3>Title of Item.</h3> 
<p style="text-align: justify;">This is all about the item etc etc etc</p> 

<div id="WhatsIncludedBlock"> 
<div class="content-inner block4 s-text"> 

<h3>What's Included?</h3> 
<p class="para"> 
<ul><a style="text-decoration: none; cursor: default;"><img style="padding-right: 7px; vertical-align:-1%;" src="http://images.com/bullet2.png" width="10px" height="10px" float="left" alt="bullet point" class="hover"></a>Brand new "Title of Item" direct from supplier.</ul> 

凡在第二塊「條目的標題」應自動從H3標籤拉(這是唯一的,不是所有的H3標籤將是明顯的一樣,我們可能需要的任何變量標籤在這裏,使其複製以後需要時添加)

+2

你要設置動態標記之間的文本?不可能與html/css。你也許可以用':before'或':after'做些事情,然後把這個類應用到resp。元素,但不是你想要的。 – Chris

+0

*「主要是javascript在我編碼的網站上被阻止。」* - 易趣? –

+0

事實上@Paulie_D –

回答

1

正如其他人所說,不可能用HTML5或CSS3不幸的是,所以我結束了使用有限的JavaScript應該通過。

<script language="javascript"> 
var title1 
title1 = 'Title of Item'; 
</script> 

調用與

<p><script>document.write (title1);</script></p> 

需要的地方。

0

在現代瀏覽器就可以了。但是會有缺點:不可能選擇或複製替代文本。見browser support of css variable on caniuse。目前支持FF 31+,Chrome 49+,Safari 9.1 +/9.3 +。在IE,Edge 13和Opera 12中沒有任何支持。

無論如何,我看不出有什麼理由拒絕使用像doT這樣的模板引擎。

h3::after { 
 
    content: var(--title); 
 
}
<section style="--title: 'First title'"> 
 
    <!-- This following content is equal for all sections --> 
 
    <h3></h3> 
 
    <p>Anything here</p> 
 
</section> 
 

 
<section style="--title: 'The second one'"> 
 
    <!-- This following content is equal for all sections --> 
 
    <h3></h3> 
 
    <p>Anything here</p> 
 
</section> 
 

 
<section style="--title: 'And the last'"> 
 
    <!-- This following content is equal for all sections --> 
 
    <h3></h3> 
 
    <p>Anything here</p> 
 
</section>