html - 使用 css 在链接中定位图像

标签 html css hyperlink positioning css-transforms

我在定位包含在链接中的图像时遇到问题。

这是 html:

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Albums</title
        <link rel="stylesheet" type="text/css" href="../../css/BackButton.css" />
        <link rel="stylesheet" type="text/css" href="MotusStyles.css" />
    </head>
    <body>
        <article>
            <div id="container">

                <div id="albumSky" class="albums">
                    <img src="../Images_Albums/PortadaMotus.jpg">
                </div>

                <div id="songs">

                    <p>01 song</p>

                    <p>02 song</p>

                    <p>03 song</p>

                    <p>04 song</p>

                    <p>05 song</p>

                    <p>06 song</p>

                    <p>07 song</p>

                    <p>08 song</p>

                    <p>09 song</p>

                    <p>10 song</p>

        </div>

                <div id="order">
                    <a href="https://itunes.apple.com/gb/album/motus-et-bouche-cousue/id595359048?app=music&ign-mpt=uo%3D4"><img id="icon" src="apple.svg"></a>
                </div>

            </div>

            <div id="credits">
                <p>someone, voc, piano / someone, bss</p>
            </div>

        </article>

        <div id="info">
            <a href="../index.html"><p class="backContact">[back]</p></a>
        </div>
    </body>
</html>

CSS

@font-face {font-family: QuaestorSans;
          src:  url("../fonts/QuaestorSans-Rg.otf") format("opentype"),
                url("../fonts/QuaestorSans.ttf") format("opentype");
}

html, body {
    height: 100%;
    margin:0;
    padding:0;
}

body {
    background: url(../Images_Albums/FondBack.jpg) no-repeat;
    background-size: 100%;
/*  background-color: red;*/
}

article {
    position: absolute;
    width: 32%;
    height: 100%;
    left: 50%;
    transform: translate(-50%, 0);
    background: url(../Images_Albums/FondFront.jpg) no-repeat;
    background-size: 100%;
}

#container {
    margin-top: 9%;
    position: absolute;
    width: 50%;
    left: 50%;
    transform: translate(-50%, 0);
  background-color: green;

}

img {
    width: 100%;
    display: block;
    margin-bottom: 15%;
}


a {
    text-decoration: none;
}

#songs {
    position: relative;
    height: 185px;
    overflow: scroll;
    overflow-x:hidden;
    width:80%;
    left: 50%;
    transform: translate(-50%, 0);
}


#songs p {
  margin: 0;
  margin-bottom: 7%;
  color: white;
  font-family: QuaestorSans;
  font-size: 1em;
  line-height: 1.3;
  width: 100%;
}


/* SCROLLBAR */

#songs::-webkit-scrollbar {
    width: 7px;
}


/* Track */
#songs::-webkit-scrollbar-track {
    background: #8fdcf6;
    border: 3px solid transparent;
    background-clip: content-box;
}


/* Handle */
#songs::-webkit-scrollbar-thumb {
    background: #c7edfa;
    border-radius:10px;
}


#songs::-webkit-scrollbar-thumb:hover{
    background-color:#c7edfa;
    border:1px solid #333333;
}


#songs::-webkit-scrollbar-thumb:active{
    background-color:#c7edfa;
    border:1px solid #333333;
}


#order {
    margin-top: 20%;
    position: relative;
    font-family: QuaestorSans;
    font-size: 1.2em;
    text-align: center;
    width: 100%;
    height: 50px;
    background-color: red;
}

#icon {
    width: 60%;
}

/*#order a {
  display:block;
  left: 50%;
  overflow:hidden;
  background: url(apple.svg) no-repeat;
  background-color: red;
  background-position: center;
  width:132px;
  height:48px;
  background-size:contain;

}*/


#credits  {
    margin-top: 135%;
    width: 65%;
    position: absolute;
    font-family: QuaestorSans;
    font-size: 1em;
    line-height: 1.3;
    margin-bottom: 1%;
    left: 50%;
    transform: translate(-50%, 0);
}


#credits  p{
    margin: 0;
    line-height: 1.5;
    color: #6ec7e9;
}


.backContact {
    color: #639cad;
}


.backContact:hover {

    color: #c7ecff;
}

那是行不通的。图像拒绝放置在中心,只是保持在左侧(参见图像:我设置了背景颜色以确保元素跨越父元素宽度的 100%)。

我也试过:

#order a {left:50%;
transform: translate(-50%, 0);
}

图片:

enter image description here

我想要中间的 iTunes 标志。

最佳答案

只需在您的 css 规则下方删除即可。

img{display:block;}

@font-face {font-family: QuaestorSans;
          src:  url("../fonts/QuaestorSans-Rg.otf") format("opentype"),
                url("../fonts/QuaestorSans.ttf") format("opentype");
}

html, body {
    height: 100%;
    margin:0;
    padding:0;
}

body {
    background: url(../Images_Albums/FondBack.jpg) no-repeat;
    background-size: 100%;
/*  background-color: red;*/
}

article {
    position: absolute;
    width: 32%;
    height: 100%;
    left: 50%;
    transform: translate(-50%, 0);
    background: url(../Images_Albums/FondFront.jpg) no-repeat;
    background-size: 100%;
}

#container {
    margin-top: 9%;
    position: absolute;
    width: 50%;
    left: 50%;
    transform: translate(-50%, 0);
  background-color: green;

}

img {
    width: 100%;
    margin-bottom: 15%;
}


a {
    text-decoration: none;
}

#songs {
    position: relative;
    height: 185px;
    overflow: scroll;
    overflow-x:hidden;
    width:80%;
    left: 50%;
    transform: translate(-50%, 0);
}


#songs p {
  margin: 0;
  margin-bottom: 7%;
  color: white;
  font-family: QuaestorSans;
  font-size: 1em;
  line-height: 1.3;
  width: 100%;
}


/* SCROLLBAR */

#songs::-webkit-scrollbar {
    width: 7px;
}


/* Track */
#songs::-webkit-scrollbar-track {
    background: #8fdcf6;
    border: 3px solid transparent;
    background-clip: content-box;
}


/* Handle */
#songs::-webkit-scrollbar-thumb {
    background: #c7edfa;
    border-radius:10px;
}


#songs::-webkit-scrollbar-thumb:hover{
    background-color:#c7edfa;
    border:1px solid #333333;
}


#songs::-webkit-scrollbar-thumb:active{
    background-color:#c7edfa;
    border:1px solid #333333;
}


#order {
    margin-top: 20%;
    position: relative;
    font-family: QuaestorSans;
    font-size: 1.2em;
    text-align: center;
    width: 100%;
    height: 50px;
    background-color: red;
}

#icon {
    width: 60%;
}

/*#order a {
  display:block;
  left: 50%;
  overflow:hidden;
  background: url(apple.svg) no-repeat;
  background-color: red;
  background-position: center;
  width:132px;
  height:48px;
  background-size:contain;

}*/


#credits  {
    margin-top: 135%;
    width: 65%;
    position: absolute;
    font-family: QuaestorSans;
    font-size: 1em;
    line-height: 1.3;
    margin-bottom: 1%;
    left: 50%;
    transform: translate(-50%, 0);
}


#credits  p{
    margin: 0;
    line-height: 1.5;
    color: #6ec7e9;
}


.backContact {
    color: #639cad;
}


.backContact:hover {

    color: #c7ecff;
}

#order img {
  margin: 0 auto;
}
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Albums</title
        <link rel="stylesheet" type="text/css" href="../../css/BackButton.css" />
        <link rel="stylesheet" type="text/css" href="MotusStyles.css" />
    </head>
    <body>
        <article>
            <div id="container">

                <div id="albumSky" class="albums">
                    <img src="../Images_Albums/PortadaMotus.jpg">
                </div>

                <div id="songs">

                    <p>01 song</p>

                    <p>02 song</p>

                    <p>03 song</p>

                    <p>04 song</p>

                    <p>05 song</p>

                    <p>06 song</p>

                    <p>07 song</p>

                    <p>08 song</p>

                    <p>09 song</p>

                    <p>10 song</p>

        </div>

                <div id="order">
                    <a href="https://itunes.apple.com/gb/album/motus-et-bouche-cousue/id595359048?app=music&ign-mpt=uo%3D4"><img id="icon" src="http://placehold.it/100x40"></a>
                </div>

            </div>

            <div id="credits">
                <p>someone, voc, piano / someone, bss</p>
            </div>

        </article>

        <div id="info">
            <a href="../index.html"><p class="backContact">[back]</p></a>
        </div>
    </body>
</html>

关于html - 使用 css 在链接中定位图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41302035/

相关文章:

mysql - 内连接 - 单独的列

javascript - 无法在 Javascript 中将用户输入作为电子邮件链接返回

html - 父对齐内容 :flex-start; while having one child element flex-end?

html - 标签内的子标签错误换行

html - 偏移固定标题的 anchor 部分

css - 背景颜色 : white in IE7 appears transparent

javascript - 如何在 Quill(富文本编辑器)中检测和 trim 前导/尾随空格?

javascript - FabricJS - 锁定高度并仅调整宽度?

javascript - 鼠标悬停时获取对象的标签、id、类

链接旁边的 CSS 图像 - 更具体?