Steps for positioning a play button at the center of all images

index.html - here is the index.html file code containing all the necessary html code

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Streaming</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.14.0/css/all.min.css" />
    <link rel="stylesheet" href="style.css" />
    <script src="script.js" defer></script>
</head>
<body>
    <nav>
        <div class="logo"><i class="fas fa-play"></i></div>
        <div class="stream">
            <ul>
                <li><a href="#">View All</a></li>
                <li>
                    <h1>Net Steam</h1>
                </li>
                <li><a href="#">Subscribe</a></li>
            </ul>
        </div>
    </nav>
    <div class="container">
        <div class="row">
            <div class="col">
                <div class="img-container"><img src="./img-1.jpg" alt="img-1"></div>
                <div class="centered"><i class="fas fa-play"></i></div>
                <div class="text">
                    <h1>Take Mantrix</h1>
                    <p>Take the Yellow Pill to get into the zone</p>
                    <a href="#">Watch Now</a>
                </div>
            </div>
            <div class="col">
                <div class="img-container"><img src="./img-2.jpg" alt="img-2"></div>
                <div class="centered"><i class="fas fa-play"></i></div>
                <div class="text">
                    <h1>2 Fast 2 Soon</h1>
                    <p>Take the Yellow Pill to get into the zone</p>
                    <a href="#">Watch Now</a>
                </div>
            </div>
            <div class="col">
                <div class="img-container"><img src="./img-3.jpg" alt="img-3"></div>
                <div class="centered"><i class="fas fa-play"></i></div>
                <div class="text">
                    <h1>Take Outback</h1>
                    <p>Take the Yellow Pill to get into the zone</p>
                    <a href="#">Watch Now</a>
                </div>
            </div>
        </div>
    </div>
</body>
</html>

style.css - following is the CSS code from style.css that includes all the necessary styling

@import url("https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;700;900&display=swap");
* {
    box-sizing: border-box;
}
body {
    font-family: "Roboto", sans-serif;
    margin: 0;
    background-color : #000;
    color : #fff;
    padding : 1rem 4rem;
}
nav {
    display : flex;
    flex-direction : column;
    align-items: center;
    border-bottom : 2px solid #fff;
    margin : 0;
    padding : 0;
}
.stream{
    max-width : 1000px;
    width : 100%;
}
.fa-play {
    font-size : 3rem;
}
ul {
    list-style-type: none;
    display : flex;
    justify-content: space-around;
    align-items: center;
    margin : 0;
    padding : 0;
}
li h1{
    font-size : 3rem;
}
a{
    color : black;
    text-decoration: none;
    padding : 1rem 2rem;
    background-color : white;
}
.row {
    display : flex;
}
.col {
    padding : 1rem;
    flex : 1;
}
.col img{
    max-width : 100%;
}
.img-container {
    position : relative;
}
.centered {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}
.text {
    display : flex;
    flex-direction : column;
    align-items: center;
}

I am trying to center the play icon on all three images using CSS but currently I can only achieve it for the center image. How can I center the play icon on all three images simultaneously? I intend to position the play font-awesome icon in the center of each image.

Answer №1

Check this out.

@import url("https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;700;900&display=swap");
* {
    box-sizing: border-box;
}
body {
    font-family: "Roboto", sans-serif;
    margin: 0;
    background-color : #000;
    color : #fff;
    padding : 4rem 4rem;
}
nav {
    display : flex;
    flex-direction : column;
    align-items: center;
    border-bottom : 2px solid #fff;
    margin : 0;
    padding : 0;
}


.stream{
    max-width : 1000px;
    width : 100%;
}
.fa-play {
    font-size : 3rem;
    position:absolute;
    text-align:center;
    color:red;
    bottom:30px;

    
}
ul {
    list-style-type: none;
    display : flex;
    justify-content: space-around;
    align-items: center;
    margin : 0;
    padding : 0;
}
li h1{
    font-size : 3rem;
}
a{
    color : black;
    text-decoration: none;
    padding : 1rem 2rem;
    background-color : white;
}
.row {
    display : flex;
}
.col {
    padding : 1rem;
    flex : 1;
    justify-content:center;
}
.col img{
    max-width : 100%;
}
.img-container {
    position : relative;
    display:flex;
    justify-content:center;

}
.centered {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}
.text {
    display : flex;
    flex-direction : column;
    align-items: center;
}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Streaming</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.14.0/css/all.min.css" />
    <link rel="stylesheet" href="style.css" />
    <script src="script.js" defer></script>
</head>
<body>
    <nav>
        <div class="logo"><i class="fas fa-play" style="position:relative"></i></div>
        <div class="stream">
            <ul>
                <li><a href="#">View All</a></li>
                <li>
                    <h1>Net Stream</h1>
                </li>
                <li><a href="#">Subscribe</a></li>
            </ul>
        </div>
    </nav>
    <div class="container">
        <div class="row">
            <div class="col">
                <div class="img-container"><i class="fas fa-play" ></i><img src="https://dictionary.cambridge.org/images/thumb/circle_noun_001_02738.jpg" alt="img-1"></div>
               
                <div class="text">
                    <h1>Take Mantrix</h1>
                    <p>Take the Yellow Pill to get into the zone</p>
                    <a href="#">Watch Now</a>
                </div>
            </div>
            <div class="col">
                <div class="img-container"><i class="fas fa-play" ></i><img src="https://dictionary.cambridge.org/images/thumb/circle_noun_001_02738.jpg" alt="img-2"></div>
                
                <div class="text">
                    <h1>2 Fast 2 Soon</h1>
                    <p>Take the Yellow Pill to get into the zone</p>
                    <a href="#">Watch Now</a>
                </div>
            </div>
            <div class="col">
                <div class="img-container"><i class="fas fa-play" ></i><img src="https://dictionary.cambridge.org/images/thumb/circle_noun_001_02738.jpg" alt="img-3"></div>
                
                <div class="text">
                    <h1>Take Outback</h1>
                    <p>Take the Yellow Pill to get into the zone</p>
                    <a href="#">Watch Now</a>
                </div>
            </div>
        </div>
    </div>
</body>
</html>

Answer №2

To achieve the desired layout, utilize the flexbox property within your .centered and .img-container classes. See the example below for implementation:

img {
    width: 200px;
    height: 200px;
}
.img-container {
    display: flex;
    justify-content: center;
    align-items: center;
}
.centered {
    position: absolute;
    top: 30%;
    left: 50%;
    z-index: 1111;
    transform: translate(-50%, -50%);
    display: flex;
    justify-content: center;
    align-items: center;
}

Full Working Snippet: - (Replace placeholder images with your own image paths)

@import url("https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;700;900&display=swap");
* {
  box-sizing: border-box;
}

body {
  font-family: "Roboto", sans-serif;
  margin: 0;
  background-color: #000;
  color: #fff;
  padding: 1rem 4rem;
}

nav {
  display: flex;
  flex-direction: column;
  align-items: center;
  border-bottom: 2px solid #fff;
  margin: 0;
  padding: 0;
}

.stream {
  max-width: 1000px;
  width: 100%;
}

.fa-play {
  font-size: 3rem;
}

ul {
  list-style-type: none;
  display: flex;
  justify-content: space-around;
  align-items: center;
  margin: 0;
  padding: 0;
}

li h1 {
  font-size: 3rem;
}

a {
  color: black;
  text-decoration: none;
  padding: 1rem 2rem;
  background-color: white;
}

.row {
  display: flex;
}

.col {
  position: relative;
  padding: 1rem;
  flex: 1;
}

.col img {
  max-width: 100%;
}

img {
  width: 200px;
  height: 200px;
}

.img-container {
  display: flex;
  justify-content: center;
  align-items: center;
}

.centered {
  position: absolute;
  top: 30%;
  left: 50%;
  z-index: 1111;
  transform: translate(-50%, -50%);
  display: flex;
  justify-content: center;
  align-items: center;
}

.text {
  display: flex;
  flex-direction: column;
  align-items: center;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.14.0/css/all.min.css" rel="stylesheet"/>
<nav>
  <div class="logo"><i class="fas fa-play"></i></div>
  <div class="stream">
    <ul>
      <li><a href="#">View All</a></li>
      <li>
        <h1>Net Steam</h1>
      </li>
      <li><a href="#">Subscribe</a></li>
    </ul>
  </div>
</nav>
<div class="container">
  <div class="row">
    <div class="col">
      <div class="img-container"><img src="https://c.tenor.com/Lvhj4QVL8-4AAAAM/server-is-for-javascript.gif" alt="img-1"></div>
      <div class="centered"><i class="fas fa-play"></i></div>
      <div class="text">
        <h1>Take Mantrix</h1>
        <p>Take the Yellow Pill to get into the zone</p>
        <a href="#">Watch Now</a>
      </div>
    </div>
    <div class="col">
      <div class="img-container"><img src="https://c.tenor.com/Lvhj4QVL8-4AAAAM/server-is-for-javascript.gif" alt="img-2"></div>
      <div class="centered"><i class="fas fa-play"></i></div>
      <div class="text">
        <h1>2 Fast 2 Soon</h1>
        <p>Take the Yellow Pill to get into the zone</p>
        <a href="#">Watch Now</a>
      </div>
    </div>
    <div class="col">
      <div class="img-container"><img src="https://c.tenor.com/Lvhj4QVL8-4AAAAM/server-is-for-javascript.gif" alt="img-3"></div>
      <div class="centered"><i class="fas fa-play"></i></div>
      <div class="text">
        <h1>Take Outback</h1>
        <p>Take the Yellow Pill to get into the zone</p>
        <a href="#">Watch Now</a>
      </div>
    </div>
  </div>
</div>

This setup should help achieve the desired visual look.

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

Develop a DIV element that remains constant throughout different web pages without having to reload

How can I create a non-reloading div at the top of my website that contains an MP3 player which plays continuously while users browse through the site? I am working with Joomla and would like to avoid using Iframes for search engine optimization purposes ...

Transform your image using the Bootstrap framework

I am attempting to create a similar banner using bootstrap. You can view the demo of the banner here. https://i.stack.imgur.com/JXLNY.png I'm struggling to understand how to achieve this in bootstrap 3 and where to begin. Should I use rows and colum ...

Alignment of text varies between canvas and HTML

How can I ensure that the labels in both canvas and HTML display overlap exactly, regardless of font family and size? The current code fails to center text inside an area when switching between canvas and HTML view. let canvas = document.getElementById( ...

HTML Canvas resizing challenge

My goal is to resize the canvas to fit inside its parent div within a Bootstrap grid, but I'm running into an issue where the canvas keeps expanding to 2000px x 2000px. Despite successfully resizing based on console.log outputs showing the same dimens ...

Issue with 'backface-visibility' CSS3 property not functioning on any versions of Internet Explorer

I'm looking to implement a specific animation in Internet Explorer. The goal is to rotate an image like a coin, displaying a different image on the other side. I suspect that the issue lies with Backface-visibility in IE, but I'm not entirely sur ...

Issue with Selenium: Unable to select the WebElement

I am a beginner with selenium and I have encountered a problem while trying to click on a specific element using the following locators. Unfortunately, none of them seem to work as expected and my scripts just skip over that particular line without any err ...

Condense a lineup of names into only two rows

I have a challenge where I need to showcase a list of names separated by commas, pulled from an array in my React component. The HTML output should appear as follows: <div> <span>Liza</span>, <span>Eric</span>, <span>Mic ...

Tips for sending multiple values in a data object using jQuery AJAX

I am currently working on a form that contains two input fields, with the possibility of more being added later. The first input is a text field and the second is a checkbox. I want to be able to send these inputs using $.ajax. To accomplish this, I have ...

Linking the User Interface to the Controller and Database

My UI requires a text field where users can input the streamId (e.g. 1, 2, 3) and then click 'ok' to display a table on the screen from the database based on the streamId value. ...

Combining 2 blocks to form a unified element

I receive a lot of HTML output like this: <div> <h4>This</h4><p>Value 9.6 m.</p> <h4>That</h4><p>Value 9.6 m.</p> <h4>The other</h4><p>Another 7.69 m.</p> <h4>And yet< ...

When submitting an Asp net mvc Form, some fields may not be posted as expected

I'm facing an issue with my ASP.NET MVC application form. Some fields that should be posted are missing, and I can't figure out why. <form id="FormRegistroUsuario" action="/Account/AdminSecurityUserAccountAdd"> <fieldset> ...

When using BeautifulSoup, there may be instances where the table element is not always detected, resulting in a 'NoneType' error being returned on occasion

Hello everyone, I am trying to retrieve accurate daily temperatures from www.wunderground.com and encountering the 'NoneType' error occasionally. For instance, the code below attempts to fetch the temperature data from March 1 to March 5, 2020. S ...

Tips for changing the style ID depending on the variable value

Currently, I am exploring the possibility of switching CSS styles using jQuery through a simple if condition. Is there an easy method to switch styles based on IDs? In my case, I have two CSS blocks each with different IDs. Here is an example: <style ...

The border is not displaying for the Child Div element

I am struggling with a webpage that has two nested divs. Despite trying all the suggestions I have found, I still cannot get the inner div to display its border. On the other hand, I have noticed that the parent div's border shows up without any issu ...

How do I insert a variable into my email content using PHP?

Hey there, I have a form that captures Name, Email, Subject, Telephone Number, Message, and a checkbox. Unfortunately, I'm not very proficient in PHP. I've just started learning the basics and could use some guidance from you :) The Form < ...

Exclusive Functionality: Bootstrap Drop Down Navigation in ASP.NET Only Functions on Main Pages

I am in the process of developing an internal application with ASP.NET 4.0 using the Yeti Bootstrap Theme. One issue I am encountering is with the navbar dropdown navigation. Pages that are located in the website's root can utilize the dropdown featu ...

How to Implement Transition Effect for Height Changes on v-if in Vuejs

I have a code snippet that effectively animates a v-if element by reducing its height to 0px. The animation is working well, but the issue arises when I need to specify the initial height of the element in CSS. While this is fine for a single element, I ...

Maintain the horizontal alignment of CSS floats

What causes the div on the right to float higher than the two divs on the left? How can I ensure they are all aligned at the top? HTML <header> <div class="nav" style="width:100%;border:#900 thin solid;"> <ul id='nav-left' ...

jQuery and CSS animation implemented on website performs flawlessly on all browsers, with the exception

I have recently started learning jQuery and I am facing an issue with the website linked below. It works perfectly in Firefox, Chrome, and Opera but not in Safari. <head> <meta charset="UTF-8"> <meta name="viewport" content="width=devic ...

"Challenges Arising in Deciphering a Basic JSON Array

After countless attempts, I am still struggling to solve this issue. My PHP code is functioning properly, as it returns the expected data when "Grove Bow" is selected from the dropdown menu: [{"wtype":"Grove Bow","was":"1.55","wcc":"5","wbdmin":"12","wbdm ...