2016-08-16 5 views
0

私は自分のHTML文書に縦方向のナビゲーションメニューを作成しましたが、どのようにボタンをメニューの右に向けずに左に並べるかを知りたいと思います。私はまた、それの下に灰色のボックスを薄くする方法を知りたいので、私のメニューボタンが左にあるとき、右に大きな空白スペースを残しません。メニューボタンを左に置くにはどうすればいいですか?

body { 
 
    background-color: #101010; 
 
} 
 
.main-header { 
 
    text-align: center; 
 
    padding: 5px; 
 
    padding-left: 300px; 
 
    height: 160px; 
 
    margin: left; 
 
} 
 
IMG.displayed { 
 
    display: block; 
 
    margin-left: auto; 
 
    margin-right: auto; 
 
    float: left; 
 
} 
 
h1 { 
 
    color: #ffffff; 
 
} 
 
div.wrapper { 
 
    margin: 10px left; 
 
    width: 250px; 
 
    float: left; 
 
} 
 
nav.vertical { 
 
    border-radius: 5px; 
 
    box-shadow: 0 0 10px rgba(0, 0, 0, .15); 
 
    overflow: hidden; 
 
    text-align: center; 
 
} 
 
nav.vertical > ul > li { 
 
    display: block; 
 
} 
 
nav.vertical > ul > li > label, 
 
nav.vertical > ul > li > a { 
 
    background-color: rgb(157, 34, 60); 
 
    background-image: -webkit-linear-gradient(135deg, rgb(114, 51, 98), rgb(157, 34, 60)); 
 
    background-image: -moz-linear-gradient(135deg, rgb(114, 51, 98), rgb(157, 34, 60)); 
 
    background-image: -o-linear-gradient(135deg, rgb(114, 51, 98), rgb(157, 34, 60)); 
 
    background-image: linear-gradient(135deg, rgb(114, 51, 98), rgb(157, 34, 60)); 
 
    border-bottom: 1px solid rgba(255, 255, 255, .1); 
 
    box-shadow: inset 0 1px 1px rgba(0, 0, 0, .1), 0 1px 1px rgba(0, 0, 0, .1); 
 
    color: rgb(255, 255, 255); 
 
    display: block; 
 
    font-size: .85rem; 
 
    font-weight: 500; 
 
    height: 50px; 
 
    letter-spacing: .5rem; 
 
    line-height: 50px; 
 
    text-shadow: 0 1px 1px rgba(0, 0, 0, .1); 
 
    text-transform: uppercase; 
 
    transition: all .1s ease; 
 
    text-decoration: none; 
 
} 
 
nav.vertical > ul > li > label:hover, 
 
nav.vertical > ul > li > a:hover { 
 
    background-color: rgb(114, 51, 98); 
 
    background-image: -webkit-linear-gradient(150deg, rgb(114, 51, 98), rgb(114, 51, 98)); 
 
    background-image: -moz-linear-gradient(150deg, rgb(114, 51, 98), rgb(114, 51, 98)); 
 
    background-image: -o-linear-gradient(150deg, rgb(114, 51, 98), rgb(114, 51, 98)); 
 
    background-image: linear-gradient(150deg, rgb(114, 51, 98), rgb(114, 51, 98)); 
 
    cursor: pointer; 
 
} 
 
nav.vertical > ul > li > label + input { 
 
    display: none; 
 
    visability: hidden; 
 
} 
 
/* unvisited link */ 
 

 
a:link { 
 
    color: #AAAAFF; 
 
} 
 
/* visited link */ 
 

 
a:visited { 
 
    color: #DD04FF; 
 
} 
 
/* mouse over link */ 
 

 
a:hover { 
 
    color: #FF0000; 
 
} 
 
/* selected link */ 
 

 
a:active { 
 
    color: #FFCC00; 
 
} 
 
footer { 
 
    color: #ffffff; 
 
} 
 
nav { 
 
    background-color: dimgrey; 
 
    border: 5px solid #333; 
 
} 
 
nav ul { 
 
    nav ul: list-style-type: none; 
 
} 
 
nav li { 
 
    padding: 2px; 
 
    display: inline-block; 
 
    border-right: 1px solid #fff; 
 
} 
 
nav li a:link { 
 
    text-decoration: none: font-weight: 700; 
 
    text-transform: uppercase; 
 
    color: #fff; 
 
    font-family: sans-serif; 
 
    font-size: 0.9em; 
 
} 
 
nav li:hover { 
 
    background-color: teal; 
 
}
<!DOCTYPE html> 
 
<html> 
 

 
<head> 
 
    <title>Home</title> 
 
    <link rel="stylesheet" type="text/css" href="cssTest.css"> 
 
    <meta charset="UTF-8"> 
 
</head> 
 

 
<body> 
 
    <main> 
 
    <div id="header"> 
 
     <h1><img class="displayed" src="img/banner.png"/></h1> 
 
    </div> 
 
    <div class="wrapper"> 
 
     <nav class="vertical"> 
 
     <ul> 
 
      <li> 
 
      <a href="homePage.html">Home</a> 
 
      </li> 
 
      <li> 
 
      <a href="blog.html">Blog</a> 
 
      </li> 
 
      <li> 
 
      <a href="news.html">News</a> 
 
      </li> 
 
      <li> 
 
      <a href="contact.html">Contact</a> 
 
      </li> 
 
     </ul> 
 
     </nav> 
 
    </div> 
 
    <section> 
 
     <article> 
 
     <h2>This is the section</h2> 
 
     <p style="color: #50FFFF; font-size: 16px; 
 
    \t \t \t \t text-shadow: 
 
    \t \t \t \t 0px 0px 2px #1040FF, 
 
    \t \t \t \t -2px -2px 2px #1040FF, 
 
    \t \t \t \t 2px -2px 2px #1040FF, 
 
    \t \t \t \t -2px 2px 2px #1040FF, 
 
    \t \t \t \t 2px 2px 2px #1040FF;"> 
 
      This is my home page of my test HTML web page. Right now i am using a HTML style on this paragraph. It uses a hexidecimal color, font size of 16 px and text shadow. 
 
     </p> 
 
     </article> 
 
    </section> 
 
    <hr> 
 
    <footer> 
 
     <strong> 
 
       Copyright &copy; 2016 Stephen Fawcett, All rights reserved 
 
     </strong> 
 
    </footer> 
 
    </main> 
 
</body> 
 

 
</html>

答えて

0

ul要素はデフォルトパディング値を持っている:

は、ここに私のコードです。だからそれを取り除く。

ul { 
    padding: 0; 
} 

空白の灰色のスペースの問題も解決します。

0

ちょうど上にあるメニューが原因ulliタグであるulタグ

0

body { 
 
    background-color: #101010; 
 
} 
 
.main-header { 
 
    text-align: center; 
 
    padding: 5px; 
 
    padding-left: 300px; 
 
    height: 160px; 
 
    margin: left; 
 
} 
 
IMG.displayed { 
 
    display: block; 
 
    margin-left: auto; 
 
    margin-right: auto; 
 
    float: left; 
 
} 
 
h1 { 
 
    color: #ffffff; 
 
} 
 
div.wrapper { 
 
    margin: 10px left; 
 
    width: 250px; 
 
    float: left; 
 
} 
 
nav.vertical { 
 
    border-radius: 5px; 
 
    box-shadow: 0 0 10px rgba(0, 0, 0, .15); 
 
    overflow: hidden; 
 
    text-align: center; 
 
} 
 

 
nav.vertical > ul { 
 
    padding: 0; 
 
} 
 

 
nav.vertical > ul > li { 
 
    display: block; 
 
} 
 
nav.vertical > ul > li > label, 
 
nav.vertical > ul > li > a { 
 
    background-color: rgb(157, 34, 60); 
 
    background-image: -webkit-linear-gradient(135deg, rgb(114, 51, 98), rgb(157, 34, 60)); 
 
    background-image: -moz-linear-gradient(135deg, rgb(114, 51, 98), rgb(157, 34, 60)); 
 
    background-image: -o-linear-gradient(135deg, rgb(114, 51, 98), rgb(157, 34, 60)); 
 
    background-image: linear-gradient(135deg, rgb(114, 51, 98), rgb(157, 34, 60)); 
 
    border-bottom: 1px solid rgba(255, 255, 255, .1); 
 
    box-shadow: inset 0 1px 1px rgba(0, 0, 0, .1), 0 1px 1px rgba(0, 0, 0, .1); 
 
    color: rgb(255, 255, 255); 
 
    display: block; 
 
    font-size: .85rem; 
 
    font-weight: 500; 
 
    height: 50px; 
 
    letter-spacing: .5rem; 
 
    line-height: 50px; 
 
    text-shadow: 0 1px 1px rgba(0, 0, 0, .1); 
 
    text-transform: uppercase; 
 
    transition: all .1s ease; 
 
    text-decoration: none; 
 
} 
 
nav.vertical > ul > li > label:hover, 
 
nav.vertical > ul > li > a:hover { 
 
    background-color: rgb(114, 51, 98); 
 
    background-image: -webkit-linear-gradient(150deg, rgb(114, 51, 98), rgb(114, 51, 98)); 
 
    background-image: -moz-linear-gradient(150deg, rgb(114, 51, 98), rgb(114, 51, 98)); 
 
    background-image: -o-linear-gradient(150deg, rgb(114, 51, 98), rgb(114, 51, 98)); 
 
    background-image: linear-gradient(150deg, rgb(114, 51, 98), rgb(114, 51, 98)); 
 
    cursor: pointer; 
 
} 
 
nav.vertical > ul > li > label + input { 
 
    display: none; 
 
    visability: hidden; 
 
} 
 
/* unvisited link */ 
 

 
a:link { 
 
    color: #AAAAFF; 
 
} 
 
/* visited link */ 
 

 
a:visited { 
 
    color: #DD04FF; 
 
} 
 
/* mouse over link */ 
 

 
a:hover { 
 
    color: #FF0000; 
 
} 
 
/* selected link */ 
 

 
a:active { 
 
    color: #FFCC00; 
 
} 
 
footer { 
 
    color: #ffffff; 
 
} 
 
nav { 
 
    background-color: dimgrey; 
 
    border: 5px solid #333; 
 
} 
 
nav ul { 
 
    nav ul: list-style-type: none; 
 
} 
 
nav li { 
 
    padding: 2px; 
 
    display: inline-block; 
 
    border-right: 1px solid #fff; 
 
} 
 
nav li a:link { 
 
    text-decoration: none: font-weight: 700; 
 
    text-transform: uppercase; 
 
    color: #fff; 
 
    font-family: sans-serif; 
 
    font-size: 0.9em; 
 
} 
 
nav li:hover { 
 
    background-color: teal; 
 
}
<!DOCTYPE html> 
 
<html> 
 

 
<head> 
 
    <title>Home</title> 
 
    <link rel="stylesheet" type="text/css" href="cssTest.css"> 
 
    <meta charset="UTF-8"> 
 
</head> 
 

 
<body> 
 
    <main> 
 
    <div id="header"> 
 
     <h1><img class="displayed" src="img/banner.png"/></h1> 
 
    </div> 
 
    <div class="wrapper"> 
 
     <nav class="vertical"> 
 
     <ul> 
 
      <li> 
 
      <a href="homePage.html">Home</a> 
 
      </li> 
 
      <li> 
 
      <a href="blog.html">Blog</a> 
 
      </li> 
 
      <li> 
 
      <a href="news.html">News</a> 
 
      </li> 
 
      <li> 
 
      <a href="contact.html">Contact</a> 
 
      </li> 
 
     </ul> 
 
     </nav> 
 
    </div> 
 
    <section> 
 
     <article> 
 
     <h2>This is the section</h2> 
 
     <p style="color: #50FFFF; font-size: 16px; 
 
    \t \t \t \t text-shadow: 
 
    \t \t \t \t 0px 0px 2px #1040FF, 
 
    \t \t \t \t -2px -2px 2px #1040FF, 
 
    \t \t \t \t 2px -2px 2px #1040FF, 
 
    \t \t \t \t -2px 2px 2px #1040FF, 
 
    \t \t \t \t 2px 2px 2px #1040FF;"> 
 
      This is my home page of my test HTML web page. Right now i am using a HTML style on this paragraph. It uses a hexidecimal color, font size of 16 px and text shadow. 
 
     </p> 
 
     </article> 
 
    </section> 
 
    <hr> 
 
    <footer> 
 
     <strong> 
 
       Copyright &copy; 2016 Stephen Fawcett, All rights reserved 
 
     </strong> 
 
    </footer> 
 
    </main> 
 
</body> 
 

 
</html>

0

padding:0margin:0を作ります。
ブラウザが自動的に読み込むスタイルシートは、liアイテムを右に40ピクセルの位置に配置します。
簡単な修正の1つはulタグpadding: 0またはメニューバーのアイテムmargin-left: -40pxです。
ナビバー自体を小さくしたい場合は、nav要素のサイズをwidthプロパティに変更して、具体的にサイズを変更することができます。

html, body { 
 
    background-color: #101010; 
 
    margin: 0; 
 
    padding: 0; 
 
} 
 
.main-header { 
 
    text-align: center; 
 
    padding: 5px; 
 
    padding-left: 300px; 
 
    height: 160px; 
 
    margin: left; 
 
} 
 
IMG.displayed { 
 
    display: block; 
 
    margin-left: auto; 
 
    margin-right: auto; 
 
    float: left; 
 
} 
 
h1 { 
 
    color: #ffffff; 
 
} 
 
div.wrapper { 
 
    margin: 10px left; 
 
    width: 250px; 
 
    float: left; 
 
} 
 
nav.vertical { 
 
    border-radius: 5px; 
 
    box-shadow: 0 0 10px rgba(0, 0, 0, .15); 
 
    overflow: hidden; 
 
    text-align: center; 
 
} 
 
nav.vertical > ul > li { 
 
    display: block; 
 
} 
 
nav.vertical > ul > li > label, 
 
nav.vertical > ul > li > a { 
 
    background-color: rgb(157, 34, 60); 
 
    background-image: -webkit-linear-gradient(135deg, rgb(114, 51, 98), rgb(157, 34, 60)); 
 
    background-image: -moz-linear-gradient(135deg, rgb(114, 51, 98), rgb(157, 34, 60)); 
 
    background-image: -o-linear-gradient(135deg, rgb(114, 51, 98), rgb(157, 34, 60)); 
 
    background-image: linear-gradient(135deg, rgb(114, 51, 98), rgb(157, 34, 60)); 
 
    border-bottom: 1px solid rgba(255, 255, 255, .1); 
 
    box-shadow: inset 0 1px 1px rgba(0, 0, 0, .1), 0 1px 1px rgba(0, 0, 0, .1); 
 
    color: rgb(255, 255, 255); 
 
    display: block; 
 
    font-size: .85rem; 
 
    font-weight: 500; 
 
    height: 50px; 
 
    letter-spacing: .5rem; 
 
    line-height: 50px; 
 
    text-shadow: 0 1px 1px rgba(0, 0, 0, .1); 
 
    text-transform: uppercase; 
 
    transition: all .1s ease; 
 
    text-decoration: none; 
 
} 
 
nav.vertical > ul > li > label:hover, 
 
nav.vertical > ul > li > a:hover { 
 
    background-color: rgb(114, 51, 98); 
 
    background-image: -webkit-linear-gradient(150deg, rgb(114, 51, 98), rgb(114, 51, 98)); 
 
    background-image: -moz-linear-gradient(150deg, rgb(114, 51, 98), rgb(114, 51, 98)); 
 
    background-image: -o-linear-gradient(150deg, rgb(114, 51, 98), rgb(114, 51, 98)); 
 
    background-image: linear-gradient(150deg, rgb(114, 51, 98), rgb(114, 51, 98)); 
 
    cursor: pointer; 
 
} 
 
nav.vertical > ul > li > label + input { 
 
    display: none; 
 
    visability: hidden; 
 
} 
 
/* unvisited link */ 
 

 
a:link { 
 
    color: #AAAAFF; 
 
} 
 
/* visited link */ 
 

 
a:visited { 
 
    color: #DD04FF; 
 
} 
 
/* mouse over link */ 
 

 
a:hover { 
 
    color: #FF0000; 
 
} 
 
/* selected link */ 
 

 
a:active { 
 
    color: #FFCC00; 
 
} 
 
footer { 
 
    color: #ffffff; 
 
} 
 
nav { 
 
    background-color: dimgrey; 
 
    border: 5px solid #333; 
 
    width: 80%; 
 
} 
 
nav ul { 
 
    nav ul: list-style-type: none; 
 
    margin: 0; 
 
} 
 
nav li { 
 
    padding: 2px; 
 
    display: inline-block; 
 
    border-right: 1px solid #fff; 
 
    margin-left: -40px; 
 
    
 
} 
 
nav li a:link { 
 
    text-decoration: none: font-weight: 700; 
 
    text-transform: uppercase; 
 
    color: #fff; 
 
    font-family: sans-serif; 
 
    font-size: 0.9em; 
 
}
<!DOCTYPE html> 
 
<html> 
 

 
<head> 
 
    <title>Home</title> 
 
    <link rel="stylesheet" type="text/css" href="cssTest.css"> 
 
    <meta charset="UTF-8"> 
 
</head> 
 

 
<body> 
 
    <main> 
 
    <div id="header"> 
 
     <h1><img class="displayed" src="img/banner.png"/></h1> 
 
    </div> 
 
    <div class="wrapper"> 
 
     <nav class="vertical"> 
 
     <ul> 
 
      <li> 
 
      <a href="homePage.html">Home</a> 
 
      </li> 
 
      <li> 
 
      <a href="blog.html">Blog</a> 
 
      </li> 
 
      <li> 
 
      <a href="news.html">News</a> 
 
      </li> 
 
      <li> 
 
      <a href="contact.html">Contact</a> 
 
      </li> 
 
     </ul> 
 
     </nav> 
 
    </div> 
 
    <section> 
 
     <article> 
 
     <h2>This is the section</h2> 
 
     <p style="color: #50FFFF; font-size: 16px; 
 
    \t \t \t \t text-shadow: 
 
    \t \t \t \t 0px 0px 2px #1040FF, 
 
    \t \t \t \t -2px -2px 2px #1040FF, 
 
    \t \t \t \t 2px -2px 2px #1040FF, 
 
    \t \t \t \t -2px 2px 2px #1040FF, 
 
    \t \t \t \t 2px 2px 2px #1040FF;"> 
 
      This is my home page of my test HTML web page. Right now i am using a HTML style on this paragraph. It uses a hexidecimal color, font size of 16 px and text shadow. 
 
     </p> 
 
     </article> 
 
    </section> 
 
    <hr> 
 
    <footer> 
 
     <strong> 
 
       Copyright &copy; 2016 Stephen Fawcett, All rights reserved 
 
     </strong> 
 
    </footer> 
 
    </main> 
 
</body> 
 

 
</html>

関連する問題