2014-08-29 41 views
0

我試圖獲得在Web2Py中使用對{{=IMG()}}的調用設置CSS <style>的基本語法。我已經試過如下:在IMG中的Web2Py CSS樣式()

<style>img.bottom { vertical-align: text-bottom; } </style> 
<body> 
    {{=IMG(_src=URL('static',args='images/golem.jpg', _style='img.bottom'),_alt="golem"}} 
</body> 

失敗

<body> 
    {{=IMG(_src=URL('static',args='images/golem.jpg', styles={'CODE':'vertical-align: text-bottom;'}), _alt="golem")}} 
<body> 

也未能

<style>img.bottom { vertical-align: text-bottom; } </style> 
<body> 
     {{=IMG(_src=URL('static',args='images/golem.jpg'), _style='bottom',_alt="golem"}} 
</body> 

也未能

<style>img.bottom { vertical-align: text-bottom; } </style> 
<body> 
     {{=IMG(_src=URL('static',args='images/golem.jpg'), _class='bottom',_alt="golem"}} 
</body> 

也未能

我覺得我一定要接近,但我無法在文檔中找到樣式爲IMG()的論據,我似乎無法覆蓋存在的(非)樣式。

Just in case anyone wants to see the Web2Py docs where the answer is not

回答

2

你可以這樣做:

{{=IMG(_src=URL('static', 'images', args='golem.jpg'), _alt='golem', 
     _style='vertical-align: text-bottom')}} 

或:

命名的參數以下劃線開始被解釋爲:

<style>img.bottom {vertical-align: text-bottom;}</style> 
{{=IMG(_src=URL('static', 'images', args='golem.jpg'), _alt='golem', 
     _class='bottom')}} 

,如文檔中提到here HTML標記屬性(沒有下劃線礦石)。

雖然書沒有具體示出使用「_style」或IMG「_class」參數的一個例子,有屬性與其它所用的「_class」參數的許多例子以及其他HTML HTML助手。

+0

你是(像往常一樣)正確。我知道我試過這個。我一定有一個錯字。 – 2014-08-30 20:45:35

+0

Hi.Is有一個選項可以從多個圖像中隨機選擇圖像嗎? – wakamdr 2018-01-10 10:29:08

+0

如果你在詢問'IMG()'helper是否包含這樣一個選項,否(對於簡單的HTML幫助程序來說似乎很罕見),但它只是Python代碼,所以編寫自己的代碼應該很簡單選擇一個隨機圖像。 – Anthony 2018-01-10 15:41:45

0

雖然這確實的工作,我不喜歡它。這很醜,我不接受它作爲答案。只是想提供一種解決方法,以防其他人在明年發現此問題(未答覆)。

<style> img.bottom { vertical-align: text-bottom; } </style> 
<body> 
    <img src={{=URL('static','images',args='golem.jpg')}} alt="golem"class=bottom> 
</body>