ホバーして画像の上に説明を表示する方法

ジョアン熟考

8つの画像があり、それぞれに説明があります。画像内の各ボタンにカーソルを合わせると、その上に説明が表示されます。正直なところ、私はすでにこれらの問題に何日も費やし、自分でそれを解決しようとしましたが、それでもそれを理解することができませんでした。どんな助けでもいただければ幸いです。

PS:デザインが終わっていないので、ここにはボタンが2つしかありません。また、画像の繰り返しの説明と混同しないでください。

.section-feature {

    padding-top: 0;
}
.feature-showcase {
    list-style: none;
    width: 100%;
}
.feature-showcase li {
    display: block;
    float: left;
    width: 25%;
}
.features-photo {
    width: 100%;
    margin:0;
    overflow: hidden;
    background-color: #000;

}
.features-photo img {
	position: relative;
	opacity:0.7;
    width: 100%;
    height: auto;
    transform: scale(1.15);
    transition: transform 0.5s,  opacity 0.5s;
    
}
.features-photo img:hover {
    opacity: 1;
    transform: scale(1.04)
}
.btn,
.btn1{
    position: absolute;
    top: 40%;
    left: 8%;
    transform: translate(200%,3200%);
    background-color: rgba(0, 0, 0, 0.33);
    color: #ffffff;
    z-index: 1;
    font-size: 16px;
    padding: 12px 24px ;
	outline: none;
    border: none;
    cursor: pointer;
    border-radius: 15px;
    text-align: center;
}
.btn1 {
    position: absolute;
    top: 27%;
    left: 16.5%;
	transform: translate(500%, 3400%);

}


 .btn:hover {
    background-color: black;
	opacity: 1;
}
 .btn1:hover {
    background-color: black;
	
}


 .long-copy {
	 z-index: 1;
	 display: none;
	background-color: rgba(186, 168, 172, 0.21); 
	color: #fcf5f5;
	 letter-spacing: 1px;
	line-height: 145%;
	 float: left;

}
  .btn:hover ~ figcaption{
		display: block;  

            
}
    <section class="section-feature">
	
		<button class="btn">Info</button>
		
    <ul class="feature-showcase">
        <li>
        <figure class="features-photo">
            <img src="resources/images/Real%20Time%2001.jpg" alt="real-time">
					<figcaption class="long-copy">Our Telematics applied to motor vehicles can allow remote, real-time (or retrospective) monitoring of a vehicle's locations and movements by the vehicle owner or other parties. Vehicle telematics units today can not only provide accurate, continuous vehicle speed and location data but also straight-line acceleration, angular acceleration and deceleration data. This enables a far more complete understanding of vehicle usage which can provide many benefits; not only to the vehicle owner but also to other road users.</figcaption>  
            </figure>
        </li>

				
 <li>
		
<figure class="features-photo">
			
<button class="btn1">Info</button>
				
<img src="resources/images/Overspeeding.jpg" alt="Overspeeding">
			     <figcaption class="long-copy">Our Telematics applied to motor vehicles can allow remote, real-time (or retrospective) monitoring of a vehicle's locations and movements by the vehicle owner or other parties. Vehicle telematics units today can not only provide accurate, continuous vehicle speed and location data but also straight-line acceleration, angular acceleration and deceleration data. This enables a far more complete understanding of vehicle usage which can provide many benefits; not only to the vehicle owner but also to other road users.</figcaption>
            </figure>      
        </li>
        
        
 <li>
 <figure class="features-photo">
 <img src="resources/images/Driver%20Identification%2001.jpg" alt="Driver Identification">
			   <figcaption class="long-copy">Our Telematics applied to motor vehicles can allow remote, real-time (or retrospective) monitoring of a vehicle's locations and movements by the vehicle owner or other parties. Vehicle telematics units today can not only provide accurate, continuous vehicle speed and location data but also straight-line acceleration, angular acceleration and deceleration data. This enables a far more complete understanding of vehicle usage which can provide many benefits; not only to the vehicle owner but also to other road users.</figcaption>
       </figure>         
        </li>
        
        
 <li>
<figure class="features-photo">
 <img src="resources/images/Fuel%20Management.jpg" alt="Fuel Management">
			          <figcaption class="long-copy">Our Telematics applied to motor vehicles can allow remote, real-time (or retrospective) monitoring of a vehicle's locations and movements by the vehicle owner or other parties. Vehicle telematics units today can not only provide accurate, continuous vehicle speed and location data but also straight-line acceleration, angular acceleration and deceleration data. This enables a far more complete understanding of vehicle usage which can provide many benefits; not only to the vehicle owner but also to other road users.</figcaption>
            </figure>
        </li>
  
  <li>
 <figure class="features-photo">
   <img src="resources/images/Maintenance.jpg" alt="Maintenance">
			      <figcaption class="long-copy">Our Telematics applied to motor vehicles can allow remote, real-time (or retrospective) monitoring of a vehicle's locations and movements by the vehicle owner or other parties. Vehicle telematics units today can not only provide accurate, continuous vehicle speed and location data but also straight-line acceleration, angular acceleration and deceleration data. This enables a far more complete understanding of vehicle usage which can provide many benefits; not only to the vehicle owner but also to other road users.</figcaption>
            </figure>        
        </li>
        
  <li>
  <figure class="features-photo">
  <img src="resources/images/Accident%20Data.jpg" alt="Accident">
			                  <figcaption class="long-copy">Our Telematics applied to motor vehicles can allow remote, real-time (or retrospective) monitoring of a vehicle's locations and movements by the vehicle owner or other parties. Vehicle telematics units today can not only provide accurate, continuous vehicle speed and location data but also straight-line acceleration, angular acceleration and deceleration data. This enables a far more complete understanding of vehicle usage which can provide many benefits; not only to the vehicle owner but also to other road users.</figcaption>
            </figure>  
        </li>
                 
<li>
<figure class="features-photo">
<img src="resources/images/Geofencing%20.jpg" alt="Geofencing">
			 <figcaption class="long-copy">Our Telematics applied to motor vehicles can allow remote, real-time (or retrospective) monitoring of a vehicle's locations and movements by the vehicle owner or other parties. Vehicle telematics units today can not only provide accurate, continuous vehicle speed and location data but also straight-line acceleration, angular acceleration and deceleration data. This enables a far more complete understanding of vehicle usage which can provide many benefits; not only to the vehicle owner but also to other road users.</figcaption>
            </figure>
        </li>
                 
                 
  <li>
  <figure class="features-photo">
 <img src="resources/images/Journey%20Management.jpg" alt="Journey Management">
			      <figcaption class="long-copy">Our Telematics applied to motor vehicles can allow remote, real-time (or retrospective) monitoring of a vehicle's locations and movements by the vehicle owner or other parties. Vehicle telematics units today can not only provide accurate, continuous vehicle speed and location data but also straight-line acceleration, angular acceleration and deceleration data. This enables a far more complete understanding of vehicle usage which can provide many benefits; not only to the vehicle owner but also to other road users.</figcaption>
            </figure>           
        </li>
        </ul>
    
    </section>

Artem Solovev

私はあなたのコードで何かをしようとしましたが、最初から作ることにしました。

次に2つの例を示します。

  • 純粋なCSSとHTML(ただし、大きな説明には適していません)
  • JSによる(ソリューションとしてモーダルポップアップを使用)

CSSとHTML

* {
  font-size: 0;
}

.container {
  display: inline-block;
  position: relative;
  width: 25%;
}

.image {
  display: inline-block;
  width: 100%;
  height: auto;
}

.btn {
  position: absolute;
  bottom: 5%;
  left: 20%;
  transform: translate(-50%, -50%);
  background-color: #4CAF50;
  color: white;
  font-size: 16px;
  padding: 8px 16px;
  z-index: 100;
}

.btn:hover {
  background-color: #3e8e41;
  box-shadow: 1px 1px 1px #d3d3d3;
}

.btn:hover+.description {
  opacity: 1;
}

.description {
  opacity: 0;
  color: black;
  font-size: 15px;
  position: absolute;
  top: 20%;
  left: 50%;
  -webkit-transform: translate(-50%, -50%);
  -ms-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
  text-align: center;
}
<div class="container">
  <img src="https://cdn.sstatic.net/Sites/stackoverflow/img/404.svg" alt="Avatar" class="image">
  <div class="btn">info</div>
  <div class="description">Some description</div>
</div>
<div class="container">
  <img src="https://cdn.sstatic.net/Sites/stackoverflow/img/404.svg" alt="Avatar" class="image">
  <div class="btn">info</div>
  <div class="description">Some description</div>
</div>
<div class="container">
  <img src="https://cdn.sstatic.net/Sites/stackoverflow/img/404.svg" alt="Avatar" class="image">
  <div class="btn">info</div>
  <div class="description">Some description</div>
</div>
<div class="container">
  <img src="https://cdn.sstatic.net/Sites/stackoverflow/img/404.svg" alt="Avatar" class="image">
  <div class="btn">info</div>
  <div class="description">Some description</div>
</div>
<div class="container">
  <img src="https://cdn.sstatic.net/Sites/stackoverflow/img/404.svg" alt="Avatar" class="image">
  <div class="btn">info</div>
  <div class="description">Some description</div>
</div>
<div class="container">
  <img src="https://cdn.sstatic.net/Sites/stackoverflow/img/404.svg" alt="Avatar" class="image">
  <div class="btn">info</div>
  <div class="description">Some description</div>
</div>
<div class="container">
  <img src="https://cdn.sstatic.net/Sites/stackoverflow/img/404.svg" alt="Avatar" class="image">
  <div class="btn">info</div>
  <div class="description">Some description</div>
</div>
<div class="container">
  <img src="https://cdn.sstatic.net/Sites/stackoverflow/img/404.svg" alt="Avatar" class="image">
  <div class="btn">info</div>
  <div class="description">Some description</div>
</div>


JSソリューション(モーダルポップアップ付き)

好きなだけカードをレンダリングする方が便利だと思います。コードを変更する必要があるのは1か所だけで、どこでも変更されます。もちろん、Reactではより強力になりますが、この方法も純粋なCSSやHTMLソリューションほど悪くはありません

var data = [{
    id: "1",
    src: "https://cdn.sstatic.net/Sites/stackoverflow/img/404.svg",
    description: "Relevant information and data that can be provided from these GPS systems include the location of the trailer or truck at various times. Depending on how often the information is captured (15 minutes, 30 seconds or 1 second intervals, for example), it can also tell the speed a vehicle was going at a certain point in time. The White Light OPAL iVMS tracks data every second, which can help immensely with second by second accident reconstruction, to know the location and speed of the vehicle."
  },
  {
    id: "2",
    src: "https://cdn.sstatic.net/Sites/stackoverflow/img/404.svg",
    description: "Relevant information and data that can be provided from these GPS systems include the location of the trailer or truck at various times. Depending on how often the information is captured (15 minutes, 30 seconds or 1 second intervals, for example), it can also tell the speed a vehicle was going at a certain point in time. The White Light OPAL iVMS tracks data every second, which can help immensely with second by second accident reconstruction, to know the location and speed of the vehicle."
  },
  {
    id: "3",
    src: "https://cdn.sstatic.net/Sites/stackoverflow/img/404.svg",
    description: "Relevant information and data that can be provided from these GPS systems include the location of the trailer or truck at various times. Depending on how often the information is captured (15 minutes, 30 seconds or 1 second intervals, for example), it can also tell the speed a vehicle was going at a certain point in time. The White Light OPAL iVMS tracks data every second, which can help immensely with second by second accident reconstruction, to know the location and speed of the vehicle."
  },
  {
    id: "4",
    src: "https://cdn.sstatic.net/Sites/stackoverflow/img/404.svg",
    description: "Relevant information and data that can be provided from these GPS systems include the location of the trailer or truck at various times. Depending on how often the information is captured (15 minutes, 30 seconds or 1 second intervals, for example), it can also tell the speed a vehicle was going at a certain point in time. The White Light OPAL iVMS tracks data every second, which can help immensely with second by second accident reconstruction, to know the location and speed of the vehicle."
  },
  {
    id: "5",
    src: "https://cdn.sstatic.net/Sites/stackoverflow/img/404.svg",
    description: "Relevant information and data that can be provided from these GPS systems include the location of the trailer or truck at various times. Depending on how often the information is captured (15 minutes, 30 seconds or 1 second intervals, for example), it can also tell the speed a vehicle was going at a certain point in time. The White Light OPAL iVMS tracks data every second, which can help immensely with second by second accident reconstruction, to know the location and speed of the vehicle."
  },
  {
    id: "6",
    src: "https://cdn.sstatic.net/Sites/stackoverflow/img/404.svg",
    description: "Relevant information and data that can be provided from these GPS systems include the location of the trailer or truck at various times. Depending on how often the information is captured (15 minutes, 30 seconds or 1 second intervals, for example), it can also tell the speed a vehicle was going at a certain point in time. The White Light OPAL iVMS tracks data every second, which can help immensely with second by second accident reconstruction, to know the location and speed of the vehicle."
  },
  {
    id: "7",
    src: "https://cdn.sstatic.net/Sites/stackoverflow/img/404.svg",
    description: "Relevant information and data that can be provided from these GPS systems include the location of the trailer or truck at various times. Depending on how often the information is captured (15 minutes, 30 seconds or 1 second intervals, for example), it can also tell the speed a vehicle was going at a certain point in time. The White Light OPAL iVMS tracks data every second, which can help immensely with second by second accident reconstruction, to know the location and speed of the vehicle."
  },
  {
    id: "8",
    src: "https://cdn.sstatic.net/Sites/stackoverflow/img/404.svg",
    description: "Relevant information and data that can be provided from these GPS systems include the location of the trailer or truck at various times. Depending on how often the information is captured (15 minutes, 30 seconds or 1 second intervals, for example), it can also tell the speed a vehicle was going at a certain point in time. The White Light OPAL iVMS tracks data every second, which can help immensely with second by second accident reconstruction, to know the location and speed of the vehicle."
  }
];

// Making image card
function createCard(src, description, id) {
  // Container
  var container = document.createElement("div");
  container.classList.add("container");
  container.setAttribute("id", id);

  // Image
  var image = document.createElement("img");
  image.classList.add("image");
  image.setAttribute("alt", "Avatar");
  image.setAttribute("src", src);

  // button
  var btn = document.createElement("div");
  btn.classList.add("btn");
  var btnText = document.createTextNode("info");
  btn.appendChild(btnText);

  // Description
  var descr = document.createElement("div");
  descr.classList.add("description");
  var descriptionText = document.createTextNode(description);
  descr.appendChild(descriptionText);

  container.appendChild(image);
  container.appendChild(btn);
  container.appendChild(descr);

  return container;
}

window.onload = function() {
  var app = document.getElementById("app");

  // Fill the app with cards based on your data
  data.map(function(item) {
    app.appendChild(createCard(item.src, item.description, item.id));
  });

  var btns = document.body.querySelectorAll(".btn");

  btns.forEach(function(btn, index) {
    btn.addEventListener("click", function(e) {
      var description = event.target.nextSibling.innerText;
      document.getElementById("description").innerText = description;

      document.getElementById("description").style.fontSize = "10px";

      // Get the modal
      var modal = document.getElementById("myModal");

      modal.style.display = "block";

      // Get the <span> element that closes the modal
      var closeModal = document.getElementsByClassName("close")[0];
      closeModal.onclick = function() {
        modal.style.display = "none";
      };

      // When the user clicks anywhere outside of the modal, close it
      window.onclick = function(event) {
        if (event.target == modal) {
          modal.style.display = "none";
        }
      };
    });
  });
};
* {
  font-size: 0;
}

.container {
  display: inline-block;
  position: relative;
  width: 25%;
}

.image {
  display: inline-block;
  width: 100%;
  height: auto;
}

.btn {
  position: absolute;
  bottom: 5%;
  left: 20%;
  transform: translate(-50%, -50%);
  background-color: #4CAF50;
  color: white;
  font-size: 16px;
  padding: 8px 16px;
}

.btn:hover+.description {
  opacity: 1;
}

.btn:hover {
  background-color: #3e8e41;
  box-shadow: 0 5px #666;
}

.description {
  text-align: center;
  height: auto;
  //opacity: 0;
  color: black;
  position: absolute;
  top: 20%;
  left: 50%;
  -webkit-transform: translate(-50%, -50%);
  -ms-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
  text-align: center;
}


/* The Modal (background) */

.modal {
  display: none;
  /* Hidden by default */
  position: fixed;
  /* Stay in place */
  z-index: 1;
  /* Sit on top */
  padding-top: 100px;
  /* Location of the box */
  left: 0;
  top: 0;
  width: 100%;
  /* Full width */
  height: 100%;
  /* Full height */
  overflow: auto;
  /* Enable scroll if needed */
  background-color: rgb(0, 0, 0);
  /* Fallback color */
  background-color: rgba(0, 0, 0, 0.4);
  /* Black w/ opacity */
}


/* Modal Content */

.modal-content {
  background-color: #fefefe;
  margin: auto;
  padding: 20px;
  border: 1px solid #888;
  width: 80%;
}


/* The Close Button */

.close {
  color: #aaaaaa;
  float: right;
  font-size: 28px;
  font-weight: bold;
}

.close:hover,
.close:focus {
  color: #000;
  text-decoration: none;
  cursor: pointer;
}
<div id="app"></div>

<!-- Card looks like this -->
<!--div class="container">
  <img src="#" alt="Avatar" class="image">
  <div class="btn">info</div>
  <div class="description"></div>
</div-->

<!-- The Modal -->
<div id="myModal" class="modal">

  <!-- Modal content -->
  <div class="modal-content">
    <span class="close">&times;</span>
    <p id="description">Some text in the Modal..</p>
  </div>

</div>

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

ホバー時に画像の上に画像を表示する方法

分類Dev

ホバー時に画像の上に画像を表示する方法

分類Dev

WooCommerceの商品説明にすべての画像を表示する方法

分類Dev

CSSを使用してホバーした画像の上に表示される画像

分類Dev

レトロフィット 2.0 を使用して画像と説明をサーバーに送信する方法

分類Dev

Swagger UIでサーバーの説明を非表示にする方法は?

分類Dev

jQueryのホバー関数を使用して画像にdivを表示する

分類Dev

ホバー時に画像の明るさを変更する

分類Dev

画像にカーソルを合わせて説明を表示する

分類Dev

ホバー時に画像の上にクリック可能なテキストボックスを表示する方法

分類Dev

:ホバーして.SVGに画像を表示

分類Dev

2行の上にオーバーレイとして画像を表示する

分類Dev

説明のjquery画像ホバー効果

分類Dev

画像上でホバーしてdivを表示し、マウスでdivを非表示にします

分類Dev

ホバーした画像を非表示にして、CSSのみを使用して別の画像を表示することはできますか?

分類Dev

attr()を使用して画像ホバーにタイトルを表示する

分類Dev

実際にホバーされた要素についてのみ、ホバーに画像を表示する

分類Dev

Jqueryをホバーして別のdivを非表示にする

分類Dev

jsを使用して画像形式でdivタグの説明をダウンロードする方法

分類Dev

jQueryホバー-divをホバーに表示してから表示したままにする方法

分類Dev

リンクホバーに画像を表示する方法

分類Dev

CSSを使用して別の画像の上に画像(透明)を表示する方法

分類Dev

Google EditTextを設計して、Googleの説明に従ってエラーメッセージを表示する

分類Dev

ホバー時に要素の横に画像を表示しますか?

分類Dev

Yii:希望のページにデータを説明順に表示する方法

分類Dev

jQueryを使用してホバー時に特定のdivを表示/非表示にする方法は?

分類Dev

ブートストラップ-メソッドの最後にアラートを表示して却下する方法を説明しますか?

分類Dev

Squarespace-ホバー時にインデックスサムネイルに説明/カスタムテキストを表示する方法

分類Dev

jQuery-ホバーに説明を表示-動的コンテンツ

Related 関連記事

  1. 1

    ホバー時に画像の上に画像を表示する方法

  2. 2

    ホバー時に画像の上に画像を表示する方法

  3. 3

    WooCommerceの商品説明にすべての画像を表示する方法

  4. 4

    CSSを使用してホバーした画像の上に表示される画像

  5. 5

    レトロフィット 2.0 を使用して画像と説明をサーバーに送信する方法

  6. 6

    Swagger UIでサーバーの説明を非表示にする方法は?

  7. 7

    jQueryのホバー関数を使用して画像にdivを表示する

  8. 8

    ホバー時に画像の明るさを変更する

  9. 9

    画像にカーソルを合わせて説明を表示する

  10. 10

    ホバー時に画像の上にクリック可能なテキストボックスを表示する方法

  11. 11

    :ホバーして.SVGに画像を表示

  12. 12

    2行の上にオーバーレイとして画像を表示する

  13. 13

    説明のjquery画像ホバー効果

  14. 14

    画像上でホバーしてdivを表示し、マウスでdivを非表示にします

  15. 15

    ホバーした画像を非表示にして、CSSのみを使用して別の画像を表示することはできますか?

  16. 16

    attr()を使用して画像ホバーにタイトルを表示する

  17. 17

    実際にホバーされた要素についてのみ、ホバーに画像を表示する

  18. 18

    Jqueryをホバーして別のdivを非表示にする

  19. 19

    jsを使用して画像形式でdivタグの説明をダウンロードする方法

  20. 20

    jQueryホバー-divをホバーに表示してから表示したままにする方法

  21. 21

    リンクホバーに画像を表示する方法

  22. 22

    CSSを使用して別の画像の上に画像(透明)を表示する方法

  23. 23

    Google EditTextを設計して、Googleの説明に従ってエラーメッセージを表示する

  24. 24

    ホバー時に要素の横に画像を表示しますか?

  25. 25

    Yii:希望のページにデータを説明順に表示する方法

  26. 26

    jQueryを使用してホバー時に特定のdivを表示/非表示にする方法は?

  27. 27

    ブートストラップ-メソッドの最後にアラートを表示して却下する方法を説明しますか?

  28. 28

    Squarespace-ホバー時にインデックスサムネイルに説明/カスタムテキストを表示する方法

  29. 29

    jQuery-ホバーに説明を表示-動的コンテンツ

ホットタグ

アーカイブ