html - 中心谷歌登录按钮

标签 html css image centering google-signin

我知道这听起来很简单而且可能是这样,但我一直在尝试使用 margin: auto、text-align: center 和其他方法使按钮居中,但都没有奏效。我知道您可以自定义按钮,但我对这个按钮没意见,只是想让它居中。 JSFiddle Code

   <html lang="en">

<head>
  <meta name="google-signin-scope" content="profile email">
  <meta name="google-signin-client_id" content="*******************.apps.googleusercontent.com">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
  <script src="https://apis.google.com/js/platform.js" async defer></script>
  <link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Roboto:100,100i,400">
  <style>
    body {
      background-color: #37474f;
    }
    h1{
      color: white;
      font-family: "Roboto", sans-serif;
      font-weight: 500;

    }
    h3{
      color: white;
      font-family: "Roboto", sans-serif;
      font-weight: 100;

    }
    .center{
      margin-top: 10%;
      text-align:center;
    }
  </style>
</head>

<body>
<div class='center'>
  <img src="https://www.nssc.org/images/design/register-icon.png" alt="Logo" style="max-width:100px; max-height:100px;">
  <h1>Email Database</h1>
  <h3>Lorem Ipsum Dolor.</h3>
  <br><br><br>
  <div class="g-signin2" data-onsuccess="onSignIn" data-theme="light" data-width="300" data-height="50" data-longtitle="true"></div>
  <!--<a href="#" onclick="signOut();">Sign out</a>-->
  <div>
  <script>
    function onSignIn(googleUser) {
      // Useful data for your client-side scripts:
      var profile = googleUser.getBasicProfile();
      console.log("ID: " + profile.getId()); // Don't send this directly to your server!
      console.log('Full Name: ' + profile.getName());
      console.log('Given Name: ' + profile.getGivenName());
      console.log('Family Name: ' + profile.getFamilyName());
      console.log("Image URL: " + profile.getImageUrl());
      console.log("Email: " + profile.getEmail());

      // The ID token you need to pass to your backend:
      var id_token = googleUser.getAuthResponse().id_token;
      $.ajax({
        type: 'POST',
        data: {
          id_token: id_token
        },
        url: 'login_process.php',
        success: function(data) {
          //alert(data);
        }

      });
      //console.log("ID Token: " + id_token);
    }

    function signOut() {
      var auth2 = gapi.auth2.getAuthInstance();
      auth2.signOut().then(function() {
        console.log('User signed out.');
      });
    }
  </script>
</body>

</html>

最佳答案

将一些文本放入您的按钮中,就可以了!用于居中的 text-align 技巧将发挥作用。

即使您在此处放置按钮图片,它也能正常工作!

参见 fiddle

  <div class="g-signin2" data-onsuccess="onSignIn" 
      -theme="light" data-width="300" data-height="50"
      data-longtitle="true">button</div>

不知道这里的问题是什么。

编辑:

解决了!

使用this

.g-signin2{
  width: 100%;
}

.g-signin2 > div{
  margin: 0 auto;
}

关于html - 中心谷歌登录按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38805236/

相关文章:

html - 使元素与相邻元素的动态定义高度相同

html - 如何让按钮与文本垂直对齐?

html - 我的网站菜单在 IE 上无法正确显示

python - 使用 pygame 在 python 中使图像背景透明的问题

php - 带有 wpdb 的 wordpress 图像 slider

php - 我的排序方法有什么问题(AJAX、PHP MySQL)

html - Nowrap/不要在输入后换行

javascript - 在 famo.us 中,调整表面文本元素大小的最佳方法是什么?

javascript - JQuery 在附加的 div 上显示删除按钮

asp.net-mvc - Entity Framework /MVC。如何防止在不选择新图像的情况下更新当前记录时删除保存在数据库中的图像 blob