The task is to put a text inside of a created icon. This post will go over some of the different ways in which you can put a text inside/over of a created icon/image(s). All of the discussed solutions follow a different presentation based on the same base idea i.e, to write/put the text over the image/icon make the image/icon an background image/icon using division, and then write the text.
- Solution 1:
<!DOCTYPE html><html><head> </head><body><!--Add HTML:--><divclass="container"><imgsrc=alt="GFG"style="width: 100%;"/><divclass="text-block"><h4>Programming</h4><p>Geeks For Geeks</p></div></div><style>//Add CSS:* {box-sizing: border-box;}/* Container holding the image and the text */.container {position: relative;}/* Bottom right text */.text-block {position: absolute;bottom: 0px;right: 20px;background-color: black;color: white;padding-left: 20px;padding-right: 20px;}</style></body></html>chevron_rightfilter_noneOutput:

Explanation: Using the .container division we make the image an background image and then using the styling .text-block division we make a box with text in it and placing it in absolute position (this value tells the browser that whatever is going to be positioned should be removed from the normal flow of the document and instead placed in an exact location on the page) with preferred styling using CSS.
- Solution 2:
<!DOCTYPE html><html><head> </head><body><!-- Write HTML code here --><divclass="container"><imgsrc=alt="GFG"style="width: 100%;"/><divclass="content"><h1>Heading</h1><p>Geeks For Geeks</p></div></div><style>// CSS Code* {box-sizing: border-box;}.container {position: relative;max-width: 800px; /* Maximum width */margin: 0 auto; /* Center it */}.container .content {/* Position the background text */position: absolute;/* At the bottom. Use top:0 to append it to the top */bottom: 0px;/* Black background with 0.5 opacity */background: rgba(0, 0, 0, 0.3);color: #f1f1f1; /* Grey text */width: 100%; /* Full width */padding: 20px; /* Some padding */}</style></body></html>chevron_rightfilter_noneOutput:

Explanation: Using the same approach as above but instead of creating a text box we overlay the content on the image/icon in this approach but simply adjusting the width property of the division using CSS i.e., setting “width: 100%;” make the text overlay on the full width of the image/icon.
- Solution 3: Hover the mouse over the Image
<!DOCTYPE html><html><head> </head><body><!-- Write HTML code here --><divclass="container"><imgsrc=alt="GFG"style="width: 100%;"/><divclass="overlay">Geeks For Geeks</div></div><style>* {box-sizing: border-box;}/* Container needed to positionthe overlay. Adjust the width as needed */.container {position: relative;}/* Make the image to responsive */.image {display: block;width: 100%;height: auto;}/* The overlay effect - lays on top ofthe container and over the image */.overlay {position: absolute;bottom: 0;/* Black see-through */background: rgba(0, 0, 0, 0.5);color: #f1f1f1;width: 100%;transition: 0.5s ease;opacity: 0;color: white;font-size: 20px;padding: 20px;text-align: center;}/* When you mouse over thecontainer, fade in the overlay title */.container:hover .overlay {opacity: 1;}</style></body></html>chevron_rightfilter_noneOutput:
Original:

On Hover:
Explanation: In this solution we make the image/icon an background image/icon and overlay the text on the image as an above solution but make the text/content disappear using the “opacity : 0;” styling in .overlay division and when the user hovers over the image we again set the opacity visible using “opacity: 1;”.
Recommended Posts:
- Where is an object stored if it is created inside a block in C++?
- CSS to put icon inside an input element in a form
- How to display icon next to show/hide text on button?
- How to vertically align text inside a flexbox using CSS?
- How to count text lines inside of DOM element ?
- How to replace dropdown-toggle icon with another default icon in Bootstrap ?
- How to put a responsive clear button inside HTML input text field ?
- Why does SASS cache folder is created ?
- How to handle events in dynamically created elements in jQuery ?
- How to select all text in HTML text input when clicked using JavaScript?
- Bulma | Icon
- Semantic-UI | Icon
- How to use mat-icon in angular?
- Text Animation with changing the color of the text using HTML & CSS
- How to count number of notification on an icon?
- Reduce the size of an icon during the animation
- How to translate an image or icon by hovering over it?
- How to add icon logo in title bar using HTML ?
- How to use font awesome icon as a cursor ?
- How to style icon color, size, and shadow by using CSS ?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


