CSS:在图像上放置按钮

huangapple go评论136阅读模式
英文:

CSS: Placing a button over an Image

问题

以下是代码的部分翻译:

.HomepageBannerContainer {
}
.HomepageBannerImage1 {
  position: relative;
  height: 100%;
  width: 100%;
}
.buttonOnImage {
  position: absolute;
  bottom: 0px;
  right: 15px;
  border-color: Goldenrod;
  border-style: solid;
  background-color: transparent;
  padding: 15px 32px;
  text-align: center;
  color: goldenrod;
  font-size: 16px;
  cursor: pointer;
  -webkit-clip-path: polygon(0 0, 0 100%, 100% 100%, 100% 30%, 75% 0);
  clip-path: polygon(0 0, 0 100%, 100% 100%, 100% 30%, 75% 0);
}
.buttonOnImage:hover {
  background-color: ;
  color: white;
}
<div class="HomepageBannerContainer">
   <img src="https://mvdataappstorageuscaprod.blob.core.windows.net/medialibrary-77aaba81e0484f88ba36c3c3b1e9c663-r/885635f1713f4b9ea1ceb61b3aba783f/885635f1713f4b9ea1ceb61b3aba783f/Large/4000D_RGB_AF_WHITE_RENDER_24.png?sv=2017-04-17&amp;sr=b&amp;si=201911192214&amp;sig=5TpJjopZRU%2FP5fwW4FBdL1jW12h8hx2PgtfyINKMkmM%3D&amp;st=1404-09-08T23%3A38%3A03Z&amp;se=2033-03-20T00%3A26%3A35Z" alt="" class="HomepageBannerImage1">
   <button class="buttonOnImage" type="button"> Corsair Configuration
   </button>
</div>
英文:

I am trying to make a button class that I can repeat across the website and several different images but I am unable to get this to overlap the image in the place where I would like, example bottom right. It is sitting in obscure areas that aren't relevant to the container?

I am aware that using an actual size (i.e px) for

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

.HomepageBannerContainer {
}
.HomepageBannerImage1 {
  position: relative;
  height: 100%;
  width: 100%;
}
.buttonOnImage {
  position: absolute;
  bottom: 0px;
  right: 15px;
  border-color: Goldenrod;
  border-style: solid;
  background-color: transparent;
  padding: 15px 32px;
  text-align: center;
  color: goldenrod;
  font-size: 16px;
  cursor: pointer;
  -webkit-clip-path: polygon(0 0, 0 100%, 100% 100%, 100% 30%, 75% 0);
  clip-path: polygon(0 0, 0 100%, 100% 100%, 100% 30%, 75% 0);
}
.buttonOnImage:hover {
  background-color: ;
  color: white;
}

<!-- language: lang-html -->

  &lt;div class=&quot;HomepageBannerContainer&quot;&gt; 
     &lt;img src=&quot;https://mvdataappstorageuscaprod.blob.core.windows.net/medialibrary-77aaba81e0484f88ba36c3c3b1e9c663-r/885635f1713f4b9ea1ceb61b3aba783f/885635f1713f4b9ea1ceb61b3aba783f/Large/4000D_RGB_AF_WHITE_RENDER_24.png?sv=2017-04-17&amp;sr=b&amp;si=201911192214&amp;sig=5TpJjopZRU%2FP5fwW4FBdL1jW12h8hx2PgtfyINKMkmM%3D&amp;st=1404-09-08T23%3A38%3A03Z&amp;se=2033-03-20T00%3A26%3A35Z&quot; alt=&quot;&quot; class=&quot;HomepageBannerImage1&quot;&gt;
&lt;button class=&quot;buttonOnImage&quot; type=&quot;button&quot;&gt; Corsair Configuration
    &lt;/button&gt;
  &lt;/div&gt;

<!-- end snippet -->

答案1

得分: 1

以下是CSS代码的中文翻译部分:

.HomepageBannerContainer {
  position: relative;
}

.HomepageBannerImage1 {
  height: 100%;
  width: 100%;
}

.buttonOnImage {
  position: absolute;
  /* 这将使它相对于其容器定位 */
  top: 50%;
  /* 接下来的三行将使它位于图像中间 */
  left: 50%;
  transform: translate(-50%, -50%);
  border-color: Goldenrod;
  border-style: solid;
  background-color: transparent;
  padding: 15px 32px;
  text-align: center;
  color: goldenrod;
  font-size: 16px;
  cursor: pointer;
  -webkit-clip-path: polygon(0 0, 0 100%, 100% 100%, 100% 30%, 75% 0);
  clip-path: polygon(0 0, 0 100%, 100% 100%, 100% 30%, 75% 0);
}

.buttonOnImage:hover {
  background-color: ;
  color: white;
}

请注意,最后一个background-color属性的值似乎缺失。

英文:

Try this (only the CSS was edited) :

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

.HomepageBannerContainer {
  position: relative;
}

.HomepageBannerImage1 {
  height: 100%;
  width: 100%;
}

.buttonOnImage {
  position: absolute;
  /* this will position it relative to its container */
  top: 50%;
  /* these next three lines will position it in the middle of the image */
  left: 50%;
  transform: translate(-50%, -50%);
  border-color: Goldenrod;
  border-style: solid;
  background-color: transparent;
  padding: 15px 32px;
  text-align: center;
  color: goldenrod;
  font-size: 16px;
  cursor: pointer;
  -webkit-clip-path: polygon(0 0, 0 100%, 100% 100%, 100% 30%, 75% 0);
  clip-path: polygon(0 0, 0 100%, 100% 100%, 100% 30%, 75% 0);
}

.buttonOnImage:hover {
  background-color: ;
  color: white;
}

<!-- language: lang-html -->

&lt;div class=&quot;HomepageBannerContainer&quot;&gt;
  &lt;img src=&quot;https://mvdataappstorageuscaprod.blob.core.windows.net/medialibrary-77aaba81e0484f88ba36c3c3b1e9c663-r/885635f1713f4b9ea1ceb61b3aba783f/885635f1713f4b9ea1ceb61b3aba783f/Large/4000D_RGB_AF_WHITE_RENDER_24.png?sv=2017-04-17&amp;sr=b&amp;si=201911192214&amp;sig=5TpJjopZRU%2FP5fwW4FBdL1jW12h8hx2PgtfyINKMkmM%3D&amp;st=1404-09-08T23%3A38%3A03Z&amp;se=2033-03-20T00%3A26%3A35Z&quot;
    alt=&quot;&quot; class=&quot;HomepageBannerImage1&quot;&gt;
  &lt;button class=&quot;buttonOnImage&quot; type=&quot;button&quot;&gt; Corsair Configuration
    &lt;/button&gt;
&lt;/div&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年3月20日 23:49:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/75792466.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定