html - css 如何讓文字標題顯示在邊框上?
問題描述
如圖,如何讓文字標題顯示在邊框上?
問題解答
回答1:<fieldset> <legend>【使用方法】</legend> </fieldset>回答2:
如果需要更精確的擴展,fieldset的效果不好,還自己實現一個吧,如下:
<style> .box{position:relative;border:1px solid red; } .box::before{content:attr(title);position:absolute;left:50%;transform:translateX(-50%);-webkit-transform:translate(-50%,-50%);padding:0 10px;background-color:#fff; }</style><p > <ol><li>這是啥</li><li>干啥</li> </ol></p>回答3:
<!DOCTYPE html><html lang='en'><head> <meta charset='UTF-8'> <title>Title</title></head><body><fieldset> <legend style='text-align: center'>【使用方法】</legend></fieldset></body></html>回答4:
提供一種hacked方法:
style:
p { width: 400px; height: 200px; border: 1px solid #ccc; } p h1 { height: 20px; margin: -10px auto 0; font-size: 14px; padding: 0 10px; text-align: center; width: 50px; }
html:
<p> <h1>嘿嘿嘿</h1> </p>回答5:
隨便想了一下,湊合著用吧http://codepen.io/colahan/pen...
不太建議使用fieldset,一般都會被reset的
回答6:絕對定位加文字定寬高
回答7:很明顯是絕對定位呀
回答8:<style> h2:before, h2:after {content: '';display: inline-block;vertical-align:middle;width: 100px;border-top: 1px solid #123456; }</style><h2>線標題</h2>
相關文章:
1. html5 - 如何實現帶陰影的不規則容器?2. html5 - 只用CSS如何實現input框的寬度隨框里輸入的內容長短自動適應?3. javascript - 三目運算符的一些問題4. python - uwsgi+django的搭建問題5. css - 移動端字體設置問題6. javascript - ueditor引入報錯問題7. c++ - win7在不刪除管理員密碼的前提下(密碼不為空),如何設置開機不需要密碼?8. html5 - H5 video 問題9. javascript - 移動端上不能實現拖拽布局嗎?10. javascript - 循環嵌套多個promise應該如何實現?
