2016-07-18 7 views
0

<a>をdivの中央に配置するにはどうすればいいですか?40%のスペースを100%幅のdivの内側に配置します。2つのボタンの横にCSSがあります。

a.explore { 
 
    padding: 15px 20px; 
 
    text-decoration: none; 
 
    text-align: center; 
 
    border: 1px solid #4f96b6; 
 
    font-size: 20px; 
 
} 
 
#container { 
 
    width: 100%; 
 
}
<div id="container"> 
 
    <a class="explore" href="#" target="_blank">I'm Ready To Go</a> 
 
    <a class="explore" href="#" target="_blank">Take Me Somewhere</a> 
 
</div>

+0

[OK]を、リンク、私はそれをどのように行うのですか? –

答えて

2

あなたは...彼らはリンクしているこれらのボタンではありません#container

a.explore { 
 
    padding: 15px 20px; 
 
    text-decoration: none; 
 
    text-align: center; 
 
    border: 1px solid #4f96b6; 
 
    font-size: 20px; 
 
} 
 
a.explore:first-child { 
 
    margin-right:40px; 
 
} 
 
#container { 
 
    width: 100%; 
 
    display:flex; 
 

 
    justify-content: center; 
 
}
<div id="container"> 
 
    <a class="explore" href="#" target="_blank">I'm Ready To Go</a> 
 
    <a class="explore" href="#" target="_blank">Take Me Somewhere</a> 
 
</div>

+0

私はあなたの解決策で問題を見ることはできませんが、それは最も簡単な問題ではありませんが、確かにうまくいきます。 – Maharkus

+1

@Paulie_Dあなたのコード例では、2番目のコンテナ '#container2'に' padding:1em'と 'width:100%'を追加するのを忘れました。 ://codepen.io/Paulie-D/pen/BzYWPj。彼らは同じです –

+1

あなたは正しいです、私は謝罪します。私のupvoteを追加しました。 –

0

display:flexjustify-content:centerを使用してこれを行うことができます。 .. differenceがあります。

しかし、フレキシボックスはここに理想的です:

a.explore { 
 
    padding: 15px 20px; 
 
    text-decoration: none; 
 
    text-align: center; 
 
    border: 1px solid #4f96b6; 
 
    font-size: 20px; 
 
} 
 
#container { 
 
    width: 100%; 
 
    display: flex; 
 
    justify-content: center; 
 
    padding: 1em; 
 
    background: #c0ffee; 
 
} 
 
a:first-child { 
 
    margin-right: 20px; 
 
} 
 
a:last-child { 
 
    margin-left: 20px; 
 
}
<div id="container"> 
 
    <a class="explore" href="#" target="_blank">I'm Ready To Go</a> 
 
    <a class="explore" href="#" target="_blank">Take Me Somewhere</a> 
 
</div>

関連する問題