2

I am creating a webpage and want to embed a GitHub Gist in the webpage. I want to align it in the center. I am using flex. But even though everthing else in the page is aligning itself the GitHub Gist object is not aligning itself.

Minimum Reproducible Code:

<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">

<head>
    <meta charset="utf-8" />
    <meta content="width=device-width, initial-scale=1" name="viewport">
    <title>Sample</title>
    <link href="css/StyleSheet2.css" rel="stylesheet" />
</head>


<body class="Top-Head">
    <h1 class="Topper">This line gets centered</h1>
    <script src="https://gist.github.com/anirbansaha96/6a515384c62191b367b4489ea538481e.js"></script></body>

</html>

And the CSS file:

body {
    margin: 0;
}

.Top-Head {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: baseline;
}
.end-github-gist {
    align-self: center;
}

.Topper {
    align-self:center;
}

Sample:

Please find the sample here.

Expected Output: Every Item being center aligned, mainly the GitHub Gist being center aligned.

Yousaf
  • 27,861
  • 6
  • 44
  • 69

2 Answers2

1

Wrap the script in a container element, set the desired width on the container element and then set margin-right and margin-left to auto on the container element to center gist container.

You can adjust the width of the container element, in the following code snippet, i have set it to 70%.

body {
  text-align: center;
}

.gistContainer {
  width: 70%;
  margin: 0 auto;
}
<h1 class="Topper">This line gets centered</h1>
<div class="gistContainer">
  <script src="https://gist.github.com/anirbansaha96/6a515384c62191b367b4489ea538481e.js"></script>
</div>
Yousaf
  • 27,861
  • 6
  • 44
  • 69
0

Add this line to you CSS:

.gist {
    margin: 0 auto;
}
Carlos Daniel
  • 449
  • 4
  • 14