如何将菜单放在网站的右侧?

我有一个画廊网站,我试图在屏幕右侧创建一个菜单,但是菜单项位于图像的底部,而不是图像的右侧。无论我在 gallerymenu 和 menutyle 类中的何处设置宽度,菜单项仍然保留在图像下方。我该如何完成我想做的事?


<body class="galleryStyle">

    <div class="galleryGrid"> 

      <div class="galleryContainer">

        <div>

          <a href="google.com.html">

            <img src="https://upload.wikimedia.org/wikipedia/en/2/23/Philipgiaccone1.JPG" alt="google">

          </a>

        </div>

      </div>

      <div class="galleryContainer">

        <div>

          <a href="google.com.html">

            <img src="https://upload.wikimedia.org/wikipedia/commons/1/19/Delfini-Milian_cropped.png" alt="google">

          </a>

        </div>

      </div>

      </div>

<div class="galleryMenu">

    <div class="menuStyle">

      <a href="google.com">

        <p>google</p></a>

    </div>

    <div class="menuStyle">

      <a href="google.com">

        <p>google</p></a>

    </div>


.galleryStyle {

  color: grey;

  width: 100%;

  background: white;

}


.galleryContainer {

  height: auto;

  width: 15%;

  margin: 10px;

  padding: 15px;

}


.galleryGrid {

  display: grid;

  grid-template-columns: repeat(2, 8fr);

  padding: 5px;

  margin: 10px;

  height: 100%;

  width: 60%;

}


.galleryMenu  {

  height: 30%;

}


.menuContainer>div {

  font-size: 2vw;

  text-align: center;

  border-radius: 5px;

  box-shadow: 8px 13px black;

  margin: 50px;

  height: 50%;

  width: 40%;

}


.menuStyle {

  display: flex;

  align-items: center;

  justify-content: center;

  background: red;

  margin: 10px;

}

https://jsfiddle.net/ud3rfm2o/1/


aluckdog
浏览 94回答 3
3回答

长风秋雁

修复代码的最简单方法是在图片上使用 float:left ,在菜单上使用 float:right 。还给菜单 lt 宽度 40% 和边距顶部 40px 以对齐顶部。也就是说,Flexbox 通常更容易使用。.galleryStyle {&nbsp; color: grey;&nbsp; width: 100%;&nbsp; background: white;}.galleryContainer {&nbsp; height: auto;&nbsp; width: 15%;&nbsp; margin: 10px;&nbsp; padding: 15px;}.galleryGrid {&nbsp; display: grid;&nbsp; grid-template-columns: repeat(2, 8fr);&nbsp; padding: 5px;&nbsp; margin: 10px;&nbsp; height: 100%;&nbsp; width: 60%;&nbsp; float:left;}.galleryMenu&nbsp; {&nbsp; height: 30%;}.menuContainer>div {&nbsp; font-size: 2vw;&nbsp; text-align: center;&nbsp; border-radius: 5px;&nbsp; box-shadow: 8px 13px black;&nbsp; margin: 50px;&nbsp; height: 50%;&nbsp; width: 40%;}.menuStyle {&nbsp; display: flex;&nbsp; align-items: center;&nbsp; justify-content: center;&nbsp; background: red;&nbsp; margin: 10px;&nbsp; width:25%;&nbsp; float:right;&nbsp; margin-top:40px;}<body class="galleryStyle">&nbsp; &nbsp; <div class="galleryGrid">&nbsp;&nbsp; &nbsp; &nbsp; <div class="galleryContainer">&nbsp; &nbsp; &nbsp; &nbsp; <div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="google.com.html">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <img src="https://upload.wikimedia.org/wikipedia/en/2/23/Philipgiaccone1.JPG" alt="google">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </a>&nbsp; &nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp; <div class="galleryContainer">&nbsp; &nbsp; &nbsp; &nbsp; <div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="google.com.html">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <img src="https://upload.wikimedia.org/wikipedia/commons/1/19/Delfini-Milian_cropped.png" alt="google">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </a>&nbsp; &nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp; </div><div class="galleryMenu">&nbsp; &nbsp; <div class="menuStyle">&nbsp; &nbsp; &nbsp; <a href="google.com">&nbsp; &nbsp; &nbsp; &nbsp; <p>google</p></a>&nbsp; &nbsp; </div>&nbsp; &nbsp; <div class="menuStyle">&nbsp; &nbsp; &nbsp; <a href="google.com">&nbsp; &nbsp; &nbsp; &nbsp; <p>google</p></a>&nbsp; &nbsp; </div>

开心每一天1111

使用弹性:    <body class="galleryStyle">    <div class= gallery-wrap>        <div class="galleryGrid">           <div class="galleryContainer">            <div>              <a href="google.com.html">                <img src="https://upload.wikimedia.org/wikipedia/en/2/23/Philipgiaccone1.JPG" alt="google">              </a>            </div>          </div>          <div class="galleryContainer">            <div>              <a href="google.com.html">                <img src="https://upload.wikimedia.org/wikipedia/commons/1/19/Delfini-Milian_cropped.png" alt="google">              </a>            </div>          </div>          </div>    <div class="galleryMenu">        <div class="menuStyle">          <a href="google.com">            <p>google</p></a>        </div>        <div class="menuStyle">          <a href="google.com">            <p>google</p></a>        </div>        </div>.gallery-wrap{  display:flex;  flex-direction:row;   justify-content:space-between;}.galleryStyle {  color: grey;  width: 100%;  background: white;}.galleryContainer {  height: auto;  width: 15%;  margin: 10px;  padding: 15px;}.galleryGrid {  display: grid;  grid-template-columns: repeat(2, 8fr);  padding: 5px;  margin: 10px;  height: 100%;  width: 40%;}.galleryMenu  {  height: 30%;  flex-grow:1}.menuContainer>div {  font-size: 2vw;  text-align: center;  border-radius: 5px;  box-shadow: 8px 13px black;  margin: 50px;  height: 50%;  width: 20%;}.menuStyle {  display: flex;  align-items: center;  justify-content: center;  background: red;  margin: 10px;}

潇潇雨雨

试穿:float: right;_galleryMenu.galleryMenu&nbsp; {&nbsp; height: 30%;&nbsp; float: right;}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Html5