Home > Software design >  how to place a play button in the middle of all the images
how to place a play button in the middle of all the images

Time:03-16

index.html - below is the index.html file code where I have written all the 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 ><i ></i></div>
        <div >
            <ul>
                <li><a href="#">View All</a></li>
                <li>
                    <h1>Net Steam</h1>
                </li>
                <li><a href="#">Subscribe</a></li>
            </ul>
        </div>
    </nav>
    <div >
        <div >
            <div >
                <div ><img src="./img-1.jpg" alt="img-1"></div>
                <div ><i ></i></div>
                <div >
                    <h1>Take Mantrix</h1>
                    <p>Take the Yellow Pill to get into the zone</p>
                    <a href="#">Watch Now</a>
                </div>
            </div>
            <div >
                <div ><img src="./img-2.jpg" alt="img-2"></div>
                <div ><i ></i></div>
                <div >
                    <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 >
                <div ><img src="./img-3.jpg" alt="img-3"></div>
                <div ><i ></i></div>
                <div >
                    <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 - below is the style.css file code here I have written all my CSS code

@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 want to place the play icon in the center of all the three images with CSS but I am getting the play icon only for the center image. How to get the play icon in the center of all three images. I want to place the play font-awesome icon in the center of the image

CodePudding user response:

You can use the flexbox property for your .centered and .img-container classes. Something as shown below:

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: - (I've used random gifs as images just for this answer, you can replace them your images path)

@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 ><i ></i></div>
  <div >
    <ul>
      <li><a href="#">View All</a></li>
      <li>
        <h1>Net Steam</h1>
      </li>
      <li><a href="#">Subscribe</a></li>
    </ul>
  </div>
</nav>
<div >
  <div >
    <div >
      <div ><img src="https://c.tenor.com/Lvhj4QVL8-4AAAAM/server-is-for-javascript.gif" alt="img-1"></div>
      <div ><i ></i></div>
      <div >
        <h1>Take Mantrix</h1>
        <p>Take the Yellow Pill to get into the zone</p>
        <a href="#">Watch Now</a>
      </div>
    </div>
    <div >
      <div ><img src="https://c.tenor.com/Lvhj4QVL8-4AAAAM/server-is-for-javascript.gif" alt="img-2"></div>
      <div ><i ></i></div>
      <div >
        <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 >
      <div ><img src="https://c.tenor.com/Lvhj4QVL8-4AAAAM/server-is-for-javascript.gif" alt="img-3"></div>
      <div ><i ></i></div>
      <div >
        <h1>Take Outback</h1>
        <p>Take the Yellow Pill to get into the zone</p>
        <a href="#">Watch Now</a>
      </div>
    </div>
  </div>
</div>

Hope that's how you wanted it to look

CodePudding user response:

Try this.

@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 ><i  style="position:relative"></i></div>
        <div >
            <ul>
                <li><a href="#">View All</a></li>
                <li>
                    <h1>Net Steam</h1>
                </li>
                <li><a href="#">Subscribe</a></li>
            </ul>
        </div>
    </nav>
    <div >
        <div >
            <div >
                <div ><i  ></i><img src="https://dictionary.cambridge.org/images/thumb/circle_noun_001_02738.jpg" alt="img-1"></div>
               
                <div >
                    <h1>Take Mantrix</h1>
                    <p>Take the Yellow Pill to get into the zone</p>
                    <a href="#">Watch Now</a>
                </div>
            </div>
            <div >
                <div ><i  ></i><img src="https://dictionary.cambridge.org/images/thumb/circle_noun_001_02738.jpg" alt="img-2"></div>
                
                <div >
                    <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 >
                <div ><i  ></i><img src="https://dictionary.cambridge.org/images/thumb/circle_noun_001_02738.jpg" alt="img-3"></div>
                
                <div >
                    <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>

  • Related