-1

I'm creating a website using bootstrap framework. I have also used particle.js for the background. There are three rows in the page in which each contain 1 element. The first row contain an image, second row contain some text and the third one contain a button. I want all these to be horizontally in the center of each row. But in the output the right padding is higher than left padding. Here is my code,

    <body  id="particles-js" >
            <div class="container-fluid">
                <div class="row">
                    <div class="col-md-12 text-center">
                        <img src="images/logo2.png" class="img-responsive my-logo">
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-8 text-center col-md-offset-2">
                        <h3 class="head">The Text goes Here !!!</h3>
                    </div>
                </div>
                <div class="row">
                    <div class="text-center col-md-4 col-md-offset-4">
            <myButton>Button Text Here!</myButton>
                    </div>
                </div>
            </div>
      </body>

The style I have given manually is as foloows,

        <style type="text/css">
            #particles-js{
            background: url(images/bg11.jpg) no-repeat center center fixed;
            height:100vh;
            -webkit-background-size: cover;
            -moz-background-size: cover;
            -o-background-size: cover;
            background-size: cover;
            }
            .container-fluid{
            all: initial !important;
            position: absolute !important; 
            top: 0 !important; 
            pointer-events:none !important;
            }
            .head{
            font-family: 'Exo', sans-serif;
            color:#fff;
            font-size: 35px;
            }
            myButton {
            background-color:transparent;
            border:1px solid #ff0044;
            display:inline-block;
            cursor:pointer;
            color:#ffffff;
            font-family:Arial;
            font-size:20px;
            padding:17px 60px;
            text-decoration:none;
            text-shadow:0px 1px 0px #ff0044;
            }
            myButton:hover {
            background-color:#ff0044;
            }
            myButton:active {
            position:relative;
            top:1px;
            }
            .my-logo{
            all: initial!important;
            width: auto!important;
            max-height: 50vh!important;
            pointer-events: none !important;
            }
        </style>

How can i place these contents in the center of each div?

Nidhin Radh
  • 131
  • 2
  • 2
  • 11

3 Answers3

1

Particle.js is a canvas thing, if you assign elements within the block they will either be insivible, positioned with a weird margins, or unclicable/hoverable.

Assign particles to its own div, make it absolute (which is stated in documentation!!!) and then add your own content in another div which may have bigger z-index then your particles.

Dražen
  • 293
  • 2
  • 13
1

Here is the code :

#particles-js{
            background: url(images/bg11.jpg) no-repeat center center fixed;
            height:100vh;
            -webkit-background-size: cover;
            -moz-background-size: cover;
            -o-background-size: cover;
            background-size: cover;
            }
            .head{
            font-family: 'Exo', sans-serif;
            color:#fff;
            font-size: 35px;
            }
            myButton {
            background-color:transparent;
            border:1px solid #ff0044;
            display:inline-block;
            cursor:pointer;
            color:#ffffff;
            font-family:Arial;
            font-size:20px;
            padding:17px 60px;
            text-decoration:none;
            text-shadow:0px 1px 0px #ff0044;
            }
            myButton:hover {
            background-color:#ff0044;
            }
            myButton:active {
            position:relative;
            top:1px;
            }
            .my-logo img{
              max-width:100%;
            }
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">

<body  id="particles-js" >
            <div class="container">
                <div class="row">
                    <div class="col-md-12 text-center">
                        <img src="pexels-photo-290470.jpeg" class="img-responsive my-logo">
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-8 text-center col-md-offset-2">
                        <h3 class="head">The Text goes Here !!!</h3>
                    </div>
                </div>
                <div class="row">
                    <div class="text-center col-md-12">
            <myButton>Button Text Here!</myButton>
                    </div>
                </div>
            </div>
      </body>
Piyali
  • 506
  • 2
  • 11
1

You can achieve this by using css3 flexbox properties.

You have to add the following css to the parent container =>

 display: flex;
 align-items: center;
 justify-content: center;

And to every child of that parent, add the following css =>

 text-align: center;

check it out on jsfiddle.net/siwalik/rfetm352/

siwalikm
  • 1,792
  • 2
  • 16
  • 20