我试图将标题与图像对齐,但是它与图像卡在一起,即使元素中具有单独的ID,我也无法更改其功能。 id ='img-caption'似乎并不影响'caption'元素。
HTML
<main id='main'>
<h1>Agha Hassan Abedi</h1>
<h2 id='title'>
A tribute to Agha Sahib</h2>
<div id='img-div'><img id='img' src='https://www.pakpedia.pk/files/Image/jpg/2c6ccb0373586eefb0f441936770a47a.jpg'></img><caption id='img-caption'>Picture of Agha Hassan Abedi</caption>
</div>
<h3 id'tribute-info'>Agha Hasan Abedi, was a Pakistani banker and philanthropist. Abedi founded Bank of Credit and Commerce International in 1972. Abedi underwent a heart transplant operation in 1988, and died of a heart attack on 5 August 1995 in Karachi.</h3>
<a id-'tribute-link' target='_blank' href='https://en.wikipedia.org/wiki/Agha_Hasan_Abedi'>More Info</a>
</main>
CSS
#main {
background-color: #eee;
}
#title {
background-color: lightgray;
text-align: center;
width: 100%;
}
#img-div {
background-color: lightblue;
text-align:left;
}
#img-caption {
background-color: gray;
}
#img {
align: center;
max-width: 100%;
height: auto;
#position: absolute;
#center: 0px;
}
h1 {
color: gray;
font-family: Times New Roman;
text-align: center;
}
答案 0 :(得分:1)
caption element用于表内。如果要与图像一起使用,建议将图像包装在图形元素中并添加figcaption元素。 就您而言,不可能是这样:
#main {
background-color: #eee;
font: calibri;
}
#title {
background-color: lightgray;
text-align: center;
width: 100%;
}
#img-div {
background-color: lightblue;
text-align:left;
}
#img-caption {
background-color: gray;
}
#img {
align: center;
max-width: 100%;
height: auto;
#position: absolute;
#center: 0px;
}
h1 {
color: gray;
font-family: Times New Roman;
text-align: center;
}
<main id='main'>
<h1>Agha Hassan Abedi</h1>
<h2 id='title'>
A tribute to Agha Sahib</h2>
<figure id='img-div'><img id='img' src='https://www.pakpedia.pk/files/Image/jpg/2c6ccb0373586eefb0f441936770a47a.jpg'><figcaption id='img-caption'>Picture of Agha Hassan Abedi</figcaption>
</figure>
<h3 id'tribute-info'>Agha Hasan Abedi, was a Pakistani banker and philanthropist. Abedi founded Bank of Credit and Commerce International in 1972. Abedi underwent a heart transplant operation in 1988, and died of a heart attack on 5 August 1995 in Karachi.</h3>
<a id-'tribute-link' target='_blank' href='https://en.wikipedia.org/wiki/Agha_Hasan_Abedi'>More Info</a>
</main>