Numerous divs positioned above a myriad of images

Is there a way to create multiple images with a tag name overlaying each one as a link? I've been able to add a tag name on top of one image, but not on others. Every time I try to duplicate the div containing the image and tag, the tags do not show up on the other images.

I have experimented with using position: relative for the parent div, position: absolute for the tag (child div), and using float: left for the image. Additionally, I have attempted to ensure the child div stays with its parent and have added separate div and class for each element: image, image container, tag, and link.

.container {
  position: relative;
  width: 400px;
  height: 400px;
}

.container img {
  width: 100%;
  /*Tried with pixel values, no change*/
  float: left;
  /*Also tried using a class for the img with position: absolute*/
}

.nameTag {
  width: 100%;
  height: 50px;
  position: absolute;
  background-color: gray;
}

.nameText {
  color: white;
}
<div class="container">
  <img src="assets/images/img1.png" />
  <div class="nameTag"><a href="" class="nameText">Mobile App</a></div>
</div>
<div class="container">
  <img src="assets/images/img2.png" />
  <div class="nameTag"><a href="" class="nameText">Mobile App</a></div>
</div>
<div class="container">
  <img src="assets/images/img3.png" />
  <div class="nameTag"><a href="" class="nameText">Mobile App</a></div>
</div>

Answer №1

Perhaps this isn't precisely what you had in mind, but here are the modifications I made to your CSS:

.container {
    position: relative;
    display: inline-block; //images are now allowed to float
    width: 400px;
    height: 400px;
}

.nameTag {
    width: 100%;
    height: 50px;
    position: absolute;
    background-color: gray;
    top: 100px; //placed in the middle of the image
    text-align: center; //centered the link text
}

Take a look at the CodePen link to see the changes. Feel free to share your thoughts!

Answer №2

Consider changing the float to "none" or simply insert this code snippet into your html/css documents.

Hopefully, this solution proves to be helpful.

.container {
  position: relative;
  width: 400px;
  height: 400px;
}

.container img {
  width: 100%;
  /*Experimented with px, but no difference*/
  float: none;
  /*Tried applying a class for img and position: absolute*/
}


/* ^^^ Alter float to "none"...appears to work in this instance */

.nameTag {
  width: 100%;
  height: 50px;
  position: relative;
  background-color: gray;
}

.nameText {
  color: white;
}
<div class="container">
  <div class="nameTag"><a href="" class="nameText">Mobile App</a></div>
  <img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRlUiyrmhTXFppqk4aYzqTOU9nimCQsYibukwAV8rstsDkAVQT-mA" />
</div>

<div class="container">
  <div class="nameTag"><a href="" class="nameText">Mobile App</a></div>
  <img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRlUiyrmhTXFppqk4aYzqTOU9nimCQsYibukwAV8rstsDkAVQT-mA" />

</div>

<div class="container">
  <div class="nameTag"><a href="" class="nameText">Mobile App</a></div>
  <img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRlUiyrmhTXFppqk4aYzqTOU9nimCQsYibukwAV8rstsDkAVQT-mA" />
</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Discover the URLs that are connected to my iframe/widget

I've crafted a widget.html page that includes a "Powered by Example.com" box or widget. Additionally, I've implemented an HTML iframe that points to this specific page (widget.html) on my website. <iframe src="http://example.com/widget.html"& ...

Tips for showcasing model data dynamically on a webpage using HTML

My model is constantly updating within a function, and I need a way to dynamically display this updated data without the need to refresh the page. How can I achieve this? models.py class MyLongProcess(models.Model): active_uuid = models.UUIDField(&apo ...

Enabling users to create custom layouts by writing CSS that is stored in the database

I am currently in the process of developing a web application using Ruby on Rails that allows users to customize their personal blog pages. I am seeking advice on the most effective ways to achieve this. While I believe Liquid for templating is a good opt ...

Refreshing a web page in Internet Explorer can cause the HTTP Header content to be altered

As I monitor my dashboard retrieving continuous data from an SAP server, I stumbled upon a solution to fetch the current server date. This approach allows me to display when the dashboard was last updated, and this date is displayed in the DOM. //Method f ...

Pressing the button results in no action

I am currently developing a program that randomly selects 5 words from a database and inserts them into an array. Although the page loads correctly initially, nothing happens when the button is clicked. None of the alerts are triggered, suggesting that the ...

What is the best way to create a taskbar using HTML or Javascript?

I'm currently developing an innovative online operating system and I am in need of a functional taskbar for user convenience. The ideal taskbar would resemble the Windows taskbar, located at the bottom of the screen with various applications easily ac ...

Exploring methods to modify the style attribute of a div tag in .NET

Using .NET, we need to access the CSS style of a div and input certain values in the code behind on page load. Since the div is located on the master page and this is another separate page, we are unable to add RUNAT="SERVER" to the div. ...

The system encountered an error stating that the class 'Database' could not be found

Whenever I try to establish a connection to my SQL database using my pdo_object.php file, I encounter the following error in my model.php: Fatal error: Class 'Db' not found in /path/model.php on line 8 I have double-checked that all permissions ...

Avoiding the use of "echo" in PHP can prevent unintended characters, especially the one created by the "¯

How can I prevent an issue where the '&macr' in a URL variable string creates the ¯ characters when echoed? echo "direct=1&closeBrowser=1&savelog=log.txt&storage=xfile&macrfile=klanta\test.html"; ...

Focusing on the combination of Phonegap, Angular JS, and Onsen for app development

We are working on developing an app using PhoneGap, Angular JS, and Onsen. One issue we are facing is that we are unable to center the header in a modal. The code snippet is provided below: <ons-modal var="modalVariable"> <ons-navigator var"de ...

Creating a responsive Select tag

Currently developing a responsive webpage using HTML5 and CSS3. Within the HTML is a form with a table that collapses as the page size decreases. However, encountering an issue where the select tag does not collapse alongside other elements in the form. Be ...

The issue I'm facing is that the style loader is failing to load the CSS within the <head

I am currently facing an issue with importing my CSS into my webpack bundle for our Angular 1 application. Initially, everything was working fine as we bundled our application using Webpack. The HTML included the bundle and vendor scripts, additional Java ...

Is there a way in CSS to set a label's width equal to the width of its content?

I am facing an issue where I need the question mark div to be positioned right next to the top row of text in the label it is associated with. Can someone suggest some styles that can be applied to the label to adjust the width and spacing so that it match ...

Is a webpage's sluggishness in Internet Explorer due to its lengthy page structure causing issues while loading quickly on other browsers?

My application has a page that is particularly long, around 8Mb of source HTML mainly comprised of tables. I am aware that this indicates poor architecture, but unfortunately, I am unable to make immediate changes due to certain constraints. In most brows ...

Delete a designated section from a URL with the power of jQuery

I have a URL like http://myurleg.com/ar/Message.html and I need to change ar to en in it when clicked on. For example, if my current URL is: http://myurleg.com/ar/Message.html After clicking, it should become: http://myurleg.com/en/Message.html I attemp ...

What is the best way to responsively center an after pseudo-element above its parent?

Looking to create a dynamic tooltip without any fixed widths or constraints on the parent element. The process seems simple enough, but I'm facing an issue with centering the after element due to an existing transform attribute of transform: translat ...

Determining the height of a Bootstrap column in relation to another element

Utilizing the grid layout from bootstrap, I have the following structure: <div id="prof_cont_enclose"> <div class="row"> <div class="prof_cont_row"> <div class="col-xs-12 col-sm-4 col-md-2 col-lg-2 prof_elem"&g ...

Struggling to show the AJAX response text in the HTML console

I am troubleshooting an issue with my ajax response text, but it keeps coming back as undefined. Here is the code I am using: $(document).ready(function() { var responseData = $.ajax({ type: "GET", url: "https://raw.githubusercontent.com/Theru ...

Utilizing Inline Placement within Email Templates

Seeking assistance in finding an alternative method to achieve the desired functionality in an email template. Having trouble with inline position styling being removed. table { width: 80%; border-spacing: 0; } table tr td.label-dots { positio ...

Visualize data from ajax call in tabular format

I want to display the results of an SQL query in a table using AJAX. I have written code that executes the query during the AJAX call, but when I try to display these values in a table, it shows null values on the div tag. What could be the reason for this ...