iT邦幫忙

0

如何將圖文周圍加上背景?

請問各位,要如何將圖文周圍加上背景?
類似這樣(不過我要的不是邊框):
https://ithelp.ithome.com.tw/upload/images/20210813/20140542TFQ7fVfRdV.png
HTML程式碼(body內):

 <nav class="nav"> 
              <a class="bar_a" id="bar_a1" aria-current="page" target='_self' href="index.html">部落格</a>
              <a class="bar_a" id="bar_a2" aria-current="page" target='_self' href="">服務</a>
              <a class="bar_a" id="bar_a3" aria-current="page" target='_self' href="">關於Inspi.</a>
        </nav>

img src="https://i0.zi.org.tw/kocpc/2021/07/1625708401-00890058e5109063effb7c201d1c1345.jpg" id="img20210813" class="all20210813">
          <span id="word20210813" class="all20210813">MIUI</span>

CSS程式碼:

.bar_a{
    text-decoration: none;
    color: white;
    cursor: pointer;
    font-family: Arial, Helvetica, sans-serif;
    letter-spacing: 0.4px;
    font-size: 33px;
    border: solid 8px rgba(113, 150, 97, 0);
    border-radius: 19px;

}
nav{
    background-color: rgb(106, 141, 90);
    height: 12.7%;
    position: fixed;
    top: 0;
    right: 0;
    left: 0;
    user-select: none;
    letter-spacing: 50px;
    display: inline-flex;
    align-items: center;
    z-index: 1;
} 
.bar_a:hover{ 
    font-size: 37px;
    color: #f8fff6;
    border: solid 8px rgb(113, 150, 97);
    border-radius: 19px;
    transition: 0.13s;
}
#bar_a1{
    position: fixed;
    left: 9.4%;
}
#bar_a2{
    position: fixed;
    left: 22.22%;
}
#bar_a3{
    position: fixed;
    left: 32%;
}

/***部落格***/
/***2021 08 13***/
#img20210813{
    width: 300px;
    height: 200px;
    border-radius: 10px;
    position: fixed;
    top: 160px;
    left: 60px;
    vertical-align: text-top;
}
#word20210813{
    position: fixed;
    bottom: 500px;
    left: 450px;
}

1 個回答

1
shijung
iT邦新手 4 級 ‧ 2021-08-13 19:28:06
最佳解答

希望你之後開發時記得先寫一段reset css 在上面再開始~
我沒有看你詳細的css
你參考看看這個有沒有像你說的 字體在圖上面~

 <nav class="nav"> 
              <a class="bar_a" id="bar_a1" aria-current="page" target='_self' href="index.html">部落格</a>
              <a class="bar_a" id="bar_a2" aria-current="page" target='_self' href="">服務</a>
              <a class="bar_a" id="bar_a3" aria-current="page" target='_self' href="">關於Inspi.</a>
        </nav>
<body>
<div class="board">
  <img id="img_board" src="https://i0.zi.org.tw/kocpc/2021/07/1625708401-00890058e5109063effb7c201d1c1345.jpg" id="img20210813" class="all20210813"/>
  <div id="word20210813" class="all20210813">    
      G??gle 宣布2021年8月起新app 將從APK轉為使用Android App Bundle (AAB)格式</div>
  ASDSDAVSGB
  你好今天天氣不錯,適合去麥X登吃早餐,我習慣吃黑豬蛋吐司不醬搭一杯紅茶,早上不喝茶葉,我會一直打瞌睡到中午XDD
    
 </div>

<body>
/* http://meyerweb.com/eric/tools/css/reset/ 
   v2.0 | 20110126
   License: none (public domain)
*/

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed, 
figure, figcaption, footer, header, hgroup, 
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
	margin: 0;
	padding: 0;
	border: 0;
	font-size: 100%;
	font: inherit;
	vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure, 
footer, header, hgroup, menu, nav, section {
	display: block;
}
body {
	line-height: 1;
}
ol, ul {
	list-style: none;
}
blockquote, q {
	quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
	content: '';
	content: none;
}
table {
	border-collapse: collapse;
	border-spacing: 0;
}

.bar_a{
    text-decoration: none;
    color: white;
    cursor: pointer;
    font-family: Arial, Helvetica, sans-serif;
    letter-spacing: 0.4px;
    font-size: 33px;
    border: solid 8px rgba(113, 150, 97, 0);
    border-radius: 19px;

}
nav{
  
    background-color: rgb(106, 141, 90);
    height: 12.7%;
    position: fixed;
    top: 0;
    right: 0;
    left: 0;
    user-select: none;
    letter-spacing: 50px;
    display: inline-flex;
    align-items: center;
    z-index: 1;
  background-image:url("https://i0.zi.org.tw/kocpc/2021/07/1625708401-00890058e5109063effb7c201d1c1345.jpg");
} 
.bar_a:hover{ 
    font-size: 37px;
    color: #f8fff6;
    border: solid 8px rgb(113, 150, 97);
    border-radius: 19px;
    transition: 0.13s;
}
#bar_a1{
    position: fixed;
    left: 9.4%;
}
#bar_a2{
    position: fixed;
    left: 22.22%;
}
#bar_a3{
    position: fixed;
    left: 32%;
}

/***部落格***/
/***2021 08 13***/
#img20210813{
    width: 300px;
    height: 200px;
    border-radius: 10px;
    position: fixed;
    vertical-align: text-top;
}
#word20210813{
    width:100%;
    position: absolute;
    top: 0; 
    left: 0;
    z-index:2;
    color: #000;
    font-family:,"Microsoft JhengHei";
    padding:2px 10px;
    font-size:16px;
    font-weight: bold;
    background-color:rgba(255,255,255,0.2);
  border-radius:10px;
}
#img_board{
  
  max-height:200px;
  width:100%;
}
.board{    
  position: relative; 
  margin-top:150px;
  height:300px;
  width:400px;
  background-color:#eee;  
  line-height:20px;  
}


看更多先前的回應...收起先前的回應...

我在網路上查了,reset css是為了實現RWD嗎?

frank575 iT邦新手 4 級 ‧ 2021-08-14 14:27:08 檢舉

不是,是為了清除 html 預設的樣式,如 ul li 前面的點點

frank575 iT邦新手 4 級 ‧ 2021-08-14 14:27:59 檢舉

所以建議都掛上去,除非你的網站只打算跟原生樣式保持一致

所以只要套上套上這段CSS,之後就可以不用再設置、把html預設刪掉?

frank575 iT邦新手 4 級 ‧ 2021-08-14 16:43:29 檢舉

是的

了解了,謝謝~!!

shijung iT邦新手 4 級 ‧ 2021-08-15 13:10:58 檢舉

謝謝Frank解答~

我要發表回答

立即登入回答