css 邊框上如何寫入文字?


方法一:

1、首先,打開html編輯器,新建html文件,例如:index.html。

2、在index.html中的<body>標簽中,輸入html代碼:。

<div style="margin-top: 30px;width: 200px;height:80px;border: 1px solid blue;">

<div style="position: absolute;left: 30px;top: 15px;">文字</div>

</div>

3、瀏覽器運行index.html頁面,此時實現了邊框角落開口顯示文字。

 

 

 

 

方法二:

這個可以通過相對定位使某元素恰好處在div的邊框上的方式來實現

1
position : relative ;

下面舉例說明

  1. 創建Html元素

    1
    2
    3
    4
    < div >
         < span  class = "title" >我是邊框上的文字</ span >
         < span >我是邊框內的文字</ span >
    </ div >
  2. 設置css樣式

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    div{
         width : 200px ;
         height : 100px ;
         padding : 5px  30px ;
         margin : 50px ;
         border : 4px  solid  #ebcbbe ;
    }
    span.title{
         display : block ;
         width : 150px ;
         height : 30px ;
         position : relative ;
         top : -15px ;
         text-align center ;
         background white ;
    }
  3. 觀察顯示效果

 

方法三:

<fieldset>
<legend>文字內容</legend>
<p>kkkk</p>
</fieldset>
這樣就行

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM