3

I am working on website index page and my code is working fine on my pc. But on 25% inner div moving down . Here is snapshot:

First

and on 25% screen:

25% screen

want it on the center and even i use position: fixed but nothing works. However i change structure but nothing work.

.txg{
     position: absolute;
        top: 40%;
        left: 50%;
        -moz-transform: translateX(-50%) translateY(-50%);
        -webkit-transform: translateX(-50%) translateY(-50%);
        transform: translateX(-50%) translateY(-50%);
    }
    .homelogo {
     text-align: center;
     line-height: 1em;
     font-family: helvetica, arial, sans-serif;
     font-weight: bold;
     background: linear-gradient(to right, #7db9e8 50%,#1e5799 50%);
     -webkit-background-clip: text;
     -webkit-text-fill-color: transparent;
     font-size: 50px;
    }
    .teg{
     position: absolute;
        top: 50%;
        left: 48%;
        -moz-transform: translateX(-50%) translateY(-48%);
        -webkit-transform: translateX(-50%) translateY(-48%);
        transform: translateX(-50%) translateY(-48%);
    }
    .teg ul{
     list-style: none;
    }
    .teg li{
     display: inline-block;
     background-color: #07ABD8;
     padding:15px;
     border-radius: 8px;
     font-size: 15px;
     text-transform: uppercase;
     font-family: helvetica, arial, sans-serif;
    }
    .teg li a{
     text-decoration: none;
     color: white;
    }
<div class="txg">
        <a class="homelogo logo" href="#">WebSiteName</a>
       </div>
       <div class="teg">
        <ul>
         <li><a href="#">New</a></li>
         <li><a href="#">Top</a></li>
         <li><a href="#">Hd</a></li>
         <li><a href="#">Upcoming</a></li>
        </ul>
       </div> 

Full Code

Racil Hilan
  • 24,690
  • 13
  • 50
  • 55
Dom
  • 343
  • 1
  • 2
  • 12

2 Answers2

3

You're having problems because of absolute positioning. I changed the following styles

    .txg{
display: inline-block;
text-align: center;
width:100%;
margin-top:10%;
    }

    .teg{
display: inline-block;
text-align: center;
width:100%
    }

By setting width:100% and text-align: center your elements will center at multiple sizes. Zoomed in to 25% and tested on chrome.

Working fiddle here

By the way, you might consider setting width:50% on innerbody as well to improve your site's responsiveness.

Jonathan Chaplin
  • 2,442
  • 1
  • 18
  • 21
1

You can do it with the Flexbox:

* {padding: 0; box-sizing: border-box}
body {height: 100vh; margin: 0} /* notice "height: 100vh" (i.e. 100% of the viewport height) */

body { /* or any other parent element of both divs */
  display: flex; /* displays flex-items (children) inline */
  flex-direction: column; /* stacks them vertically */
  justify-content: center; /* vertical alignment / it's horizontal by default, but since the flex-direction is changed, so is this */
  align-items: center; /* horizontal alignment / same here, it's vertical by default */
}

/* not necessary
.txg {
  position: absolute;
  top: 40%;
  left: 50%;
  -moz-transform: translateX(-50%) translateY(-50%);
  -webkit-transform: translateX(-50%) translateY(-50%);
  transform: translateX(-50%) translateY(-50%);
}
*/

.txg {
  margin-bottom: 10px; /* a little bit of vertical gap */
}

.homelogo {
  /*text-align: center; not necessary since it's already centered */
  line-height: 1em;
  font-family: helvetica, arial, sans-serif;
  font-weight: bold;
  background: linear-gradient(to right, #7db9e8 50%,#1e5799 50%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  font-size: 50px;
}

/* not necessary
.teg {
  position: absolute;
  top: 50%;
  left: 48%;
  -moz-transform: translateX(-50%) translateY(-48%);
  -webkit-transform: translateX(-50%) translateY(-48%);
  transform: translateX(-50%) translateY(-48%);
}
*/

.teg ul {
  display: flex; /* added */
  list-style: none;
}

.teg ul li a { /* added anchor tag to increase clickable area, recommended */
  /*display: inline-block;*/
  margin: 0 5px; /* added */
  background-color: #07ABD8;
  padding: 15px;
  border-radius: 8px;
  font-size: 15px;
  text-transform: uppercase;
  font-family: helvetica, arial, sans-serif;
  text-decoration: none;
  color: white;
}
<div class="txg">
  <a class="homelogo logo" href="#">WebSiteName</a>
</div>
<div class="teg">
  <ul>
    <li><a href="#">New</a></li>
    <li><a href="#">Top</a></li>
    <li><a href="#">Hd</a></li>
    <li><a href="#">Upcoming</a></li>
  </ul>
</div>
VXp
  • 11,598
  • 6
  • 31
  • 46