2017-10-06 27 views
0

私はあきらめて、助けに来ました。 (赤いボーダーがちょうどので、私は...各項目のレイアウトを見ることができます)親部門内のセンター入力

Image

私はこれの内部を揃えるためにしようとしているが、正確な中間にそうthatsのをDIV

body { 
 
    margin: 0; 
 
    padding: 16px; 
 
} 
 

 
@font-face { 
 
\t font-family: "Product Sans"; 
 
\t font-style: normal; 
 
\t font-weight: normal; 
 
\t src: url("ProductSans-Regular.woff") format("woff"); 
 
} 
 

 
.form { 
 
\t background-color: grey; 
 
\t background-color: rgba(66, 66, 66, 0.7); 
 
\t border: 1px solid transparent; 
 
\t border: 1px solid red; 
 
\t border-radius: 25px; 
 
\t color: #FFFFFF; 
 
\t font: 1em "Product Sans"; 
 
\t left: 50%; 
 
\t position: absolute; 
 
\t text-align: center; 
 
\t top: 50%; 
 
\t transform: translateX(-50%) translateY(-50%); 
 
} 
 

 
.textInput { 
 
\t background-color: transparent; 
 
\t border: none; 
 
\t border: 1px solid red; 
 
\t border-bottom: 2px solid transparent; 
 
\t box-sizing: border-box; 
 
\t padding: 16px; 
 
\t -webkit-transition: all 0.5s ease-in-out; 
 
    -moz-transition: all 0.5s ease-in-out; 
 
    -o-transition: all 0.5s ease-in-out; 
 
    transition: all 0.5s ease-in-out; 
 
} 
 

 
.textInput:focus { 
 
\t border-bottom: 2px solid rgba(255, 138, 128, 0.7); 
 
} 
 

 
.textInput:invalid { 
 
\t box-shadow:0 0 0 transparent; 
 
} 
 
.submit { 
 
\t background-color: transparent; 
 
\t border: 2px solid rgba(255, 138, 128, 0.7); 
 
\t border: 1px solid red; 
 
\t box-sizing: border-box; 
 
\t padding: 16px; 
 
\t -webkit-transition: all 0.5s ease-in-out; 
 
    -moz-transition: all 0.5s ease-in-out; 
 
    -o-transition: all 0.5s ease-in-out; 
 
    transition: all 0.5s ease-in-out; 
 
} 
 

 
.submit:hover { 
 
\t background-color: rgba(255, 138, 128, 0.7); 
 
\t border: 2px solid transparent; 
 
}
<!DOCTYPE html> 
 
<html> 
 
\t <head> 
 
\t \t <title>Beautiful login - made with <3, PHP, CSS and HTML</title> 
 
\t \t <meta charset="utf-8" /> 
 
\t \t <link type="text/css" href="StyleSheet.css" rel="stylesheet" /> 
 
\t \t <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> 
 
\t </head> 
 
\t <body> 
 
\t \t <div class="form"> 
 
\t \t \t <form action="/index.php" method="post"> 
 
\t \t \t \t <input type="text" name="userName" class="textInput" title="This area is for your unique username" placeholder="Your username here" required /> 
 
\t \t \t \t <br /> 
 
\t \t \t \t <input type="password" name="passWord" class="textInput" title="This area is for your unique username" placeholder="Your password here" required /> 
 
\t \t \t \t <br /> 
 
\t \t \t \t <button type="submit" name="submit" class="submit" title="Click this button if you are sure your information is right" >Submit</button> 
 
\t \t \t </form> 
 
\t \t </div> 
 
\t \t <script> 
 
\t \t \t var screenWidth = $(window).width(); 
 
\t \t \t var screenHeight = $(window).height(); 
 
\t \t \t $(".form").css("width", screenWidth/3); 
 
\t \t \t $(".form").css("height", screenHeight/3 + 32); 
 
\t \t \t $(".textInput").css("width", screenWidth/4) 
 
\t \t \t $(".submit").css("width", screenWidth/4); 
 
\t \t \t var URL = "https://source.unsplash.com/" + screenWidth + "x" + screenHeight + "/?nature,water"; 
 
\t \t \t $("body").css("background-image", "url(" + URL + ")"); 
 
\t \t </script> 
 
\t </body> 
 
</html>

あなたが見ることができるように、私は角の丸い、大きな、グレーを中心に管理してきました長方形であるが、同じ方法は内容に対しては機能しなかった。あなたが入力されたテキストコンテンツがセンターになりたい場合は

答えて

3

あなたの.formクラスにこれらの3つのプロパティを追加することができます使用します内容量:

display: flex; 
flex-direction: column; 
justify-content: center; 

body { 
 
    margin: 0; 
 
    padding: 16px; 
 
} 
 

 
@font-face { 
 
    font-family: "Product Sans"; 
 
    font-style: normal; 
 
    font-weight: normal; 
 
    src: url("ProductSans-Regular.woff") format("woff"); 
 
} 
 

 
.form { 
 
    background-color: grey; 
 
    background-color: rgba(66, 66, 66, 0.7); 
 
    border: 1px solid transparent; 
 
    border: 1px solid red; 
 
    border-radius: 25px; 
 
    color: #FFFFFF; 
 
    font: 1em "Product Sans"; 
 
    left: 50%; 
 
    position: absolute; 
 
    text-align: center; 
 
    top: 50%; 
 
    transform: translateX(-50%) translateY(-50%); 
 
    display: flex; 
 
    flex-direction: column; 
 
    justify-content: center; 
 
} 
 

 
.textInput { 
 
    background-color: transparent; 
 
    border: none; 
 
    border: 1px solid red; 
 
    border-bottom: 2px solid transparent; 
 
    box-sizing: border-box; 
 
    padding: 16px; 
 
    -webkit-transition: all 0.5s ease-in-out; 
 
    -moz-transition: all 0.5s ease-in-out; 
 
    -o-transition: all 0.5s ease-in-out; 
 
    transition: all 0.5s ease-in-out; 
 
} 
 

 
.textInput:focus { 
 
    border-bottom: 2px solid rgba(255, 138, 128, 0.7); 
 
} 
 

 
.textInput:invalid { 
 
    box-shadow: 0 0 0 transparent; 
 
} 
 

 
.submit { 
 
    background-color: transparent; 
 
    border: 2px solid rgba(255, 138, 128, 0.7); 
 
    border: 1px solid red; 
 
    box-sizing: border-box; 
 
    padding: 16px; 
 
    -webkit-transition: all 0.5s ease-in-out; 
 
    -moz-transition: all 0.5s ease-in-out; 
 
    -o-transition: all 0.5s ease-in-out; 
 
    transition: all 0.5s ease-in-out; 
 
} 
 

 
.submit:hover { 
 
    background-color: rgba(255, 138, 128, 0.7); 
 
    border: 2px solid transparent; 
 
}
<!DOCTYPE html> 
 
<html> 
 

 
<head> 
 
    <title>Beautiful login - made with 
 
    <3, PHP, CSS and HTML</title> 
 
     <meta charset="utf-8" /> 
 
     <link type="text/css" href="StyleSheet.css" rel="stylesheet" /> 
 
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> 
 
</head> 
 

 
<body> 
 
    <div class="form"> 
 
    <form action="/index.php" method="post"> 
 
     <input type="text" name="userName" class="textInput" title="This area is for your unique username" placeholder="Your username here" required /> 
 
     <br /> 
 
     <input type="password" name="passWord" class="textInput" title="This area is for your unique username" placeholder="Your password here" required /> 
 
     <br /> 
 
     <button type="submit" name="submit" class="submit" title="Click this button if you are sure your information is right">Submit</button> 
 
    </form> 
 
    </div> 
 
    <script> 
 
    var screenWidth = $(window).width(); 
 
    var screenHeight = $(window).height(); 
 
    $(".form").css("width", screenWidth/3); 
 
    $(".form").css("height", screenHeight/3 + 32); 
 
    $(".textInput").css("width", screenWidth/4) 
 
    $(".submit").css("width", screenWidth/4); 
 
    var URL = "https://source.unsplash.com/" + screenWidth + "x" + screenHeight + "/?nature,water"; 
 
    $("body").css("background-image", "url(" + URL + ")"); 
 
    </script> 
 
</body> 
 

 
</html>

2

、単に垂直センタリングを達成するために、CSS text-align:center

.textInput { 
    text-align:center 
} 

body { 
 
    margin: 0; 
 
    padding: 16px; 
 
} 
 

 
@font-face { 
 
\t font-family: "Product Sans"; 
 
\t font-style: normal; 
 
\t font-weight: normal; 
 
\t src: url("ProductSans-Regular.woff") format("woff"); 
 
} 
 

 
.form { 
 
\t background-color: grey; 
 
\t background-color: rgba(66, 66, 66, 0.7); 
 
\t border: 1px solid transparent; 
 
\t border: 1px solid red; 
 
\t border-radius: 25px; 
 
\t color: #FFFFFF; 
 
\t font: 1em "Product Sans"; 
 
\t left: 50%; 
 
\t position: absolute; 
 
\t text-align: center; 
 
\t top: 50%; 
 
\t transform: translateX(-50%) translateY(-50%); 
 
} 
 

 
.textInput { 
 
\t background-color: transparent; 
 
\t border: none; 
 
\t border: 1px solid red; 
 
\t border-bottom: 2px solid transparent; 
 
\t box-sizing: border-box; 
 
\t padding: 16px; 
 
\t -webkit-transition: all 0.5s ease-in-out; 
 
    -moz-transition: all 0.5s ease-in-out; 
 
    -o-transition: all 0.5s ease-in-out; 
 
    transition: all 0.5s ease-in-out; 
 
    text-align:center; 
 
} 
 

 
.textInput:focus { 
 
\t border-bottom: 2px solid rgba(255, 138, 128, 0.7); 
 
} 
 

 
.textInput:invalid { 
 
\t box-shadow:0 0 0 transparent; 
 
} 
 
.submit { 
 
\t background-color: transparent; 
 
\t border: 2px solid rgba(255, 138, 128, 0.7); 
 
\t border: 1px solid red; 
 
\t box-sizing: border-box; 
 
\t padding: 16px; 
 
\t -webkit-transition: all 0.5s ease-in-out; 
 
    -moz-transition: all 0.5s ease-in-out; 
 
    -o-transition: all 0.5s ease-in-out; 
 
    transition: all 0.5s ease-in-out; 
 
} 
 

 
.submit:hover { 
 
\t background-color: rgba(255, 138, 128, 0.7); 
 
\t border: 2px solid transparent; 
 
}
<!DOCTYPE html> 
 
<html> 
 
\t <head> 
 
\t \t <title>Beautiful login - made with <3, PHP, CSS and HTML</title> 
 
\t \t <meta charset="utf-8" /> 
 
\t \t <link type="text/css" href="StyleSheet.css" rel="stylesheet" /> 
 
\t \t <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> 
 
\t </head> 
 
\t <body> 
 
\t \t <div class="form"> 
 
\t \t \t <form action="/index.php" method="post"> 
 
\t \t \t \t <input type="text" name="userName" class="textInput" title="This area is for your unique username" placeholder="Your username here" required /> 
 
\t \t \t \t <br /> 
 
\t \t \t \t <input type="password" name="passWord" class="textInput" title="This area is for your unique username" placeholder="Your password here" required /> 
 
\t \t \t \t <br /> 
 
\t \t \t \t <button type="submit" name="submit" class="submit" title="Click this button if you are sure your information is right" >Submit</button> 
 
\t \t \t </form> 
 
\t \t </div> 
 
\t \t <script> 
 
\t \t \t var screenWidth = $(window).width(); 
 
\t \t \t var screenHeight = $(window).height(); 
 
\t \t \t $(".form").css("width", screenWidth/3); 
 
\t \t \t $(".form").css("height", screenHeight/3 + 32); 
 
\t \t \t $(".textInput").css("width", screenWidth/4) 
 
\t \t \t $(".submit").css("width", screenWidth/4); 
 
\t \t \t var URL = "https://source.unsplash.com/" + screenWidth + "x" + screenHeight + "/?nature,water"; 
 
\t \t \t $("body").css("background-image", "url(" + URL + ")"); 
 
\t \t </script> 
 
\t </body> 
 
</html>

+0

これは入力自体 – Martijn

+0

従事PERFのテキストを整列します間違いなく、期限が切れたときに私は答えとしてマークします:) –

0

さて、あなたは本当に内容にあなたの方法を適用していない:)。あなたは外側を中心にまっすぐ同じ方法でそれらを中心に置くことができます.form div。あなたのCSSにこれを追加すると、動作するはずです:

.form{ 
display: flex; 
flex-direction: column; 
align-items: center; 
justify-contents: center; 
} 

、ページの途中でフォーム全体を配置するために、:縦内容を作るために

form { 
    position: absolute; 
    left: 50%; 
    top: 50%; 
    transform: translateX(-50%) translateY(-50%); 
} 
0

を水平中央フォームにこれらのスタイルを与えます例えば、50%の高さ100VHと容器内にラップ:絶対フォームを配置し、トップを与えることなく

.container{ 
height: 100vh; 
display: flex; 
align-items: center; 
} 
関連する問題