【问题标题】:Separate sidebar from image将侧边栏与图像分开
【发布时间】:2016-08-24 10:37:07
【问题描述】:

我不希望侧边栏重叠图像。 所以基本上我想要它们,并排,我认为问题在于我有一个立场:绝对;在侧边栏中,但当我删除它时,侧边栏和图像不会留在原位。

body {
  text-decoration: none;
  margin: 0 auto;
  max-width: 100% !important;
  height: auto;
}
.fundo img {
  max-width: 100% !important;
  height: auto;
}
.menuleft {
  background-color: #CDD0D2;
  list-style-type: none;
  position: absolute;
  width: 9%;
  height: 100%;
  display: table;
}
.menuleft ul {
  display: table-cell;
  list-style-type: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  vertical-align: middle;
}
#text {
  -webkit-box-shadow: inset -7px 4px 5px 0px rgba(0, 0, 0, 0.22);
  -moz-box-shadow: inset -7px 4px 5px 0px rgba(0, 0, 0, 0.22);
  box-shadow: inset -7px 4px 5px 0px rgba(0, 0, 0, 0.22);
  width: 100%;
  height: 17%;
  color: white;
  text-align: center;
  text-decoration: none;
  background-color: #F06D22;
}
.menuleft li a {
  font-family: Futura LT, 'Trebuchet MS', Arial;
  letter-spacing: 0.28vw;
  color: #fff;
  text-decoration: none;
  height: 100%;
  text-align: center;
  display: flex;
  vertical-align: middle;
  align-items: center;
  justify-content: center;
  width: 100%;
  writing-mode: tb-rl;
  -webkit-transform: rotate(180deg);
  -moz-transform: rotate(180deg);
  -o-transform: rotate(180deg);
  -ms-transform: rotate(180deg);
  transform: rotate(180deg);
  white-space: nowrap;
}
.menuleft li:hover {
  text-decoration: none;
  background: rgba(255, 255, 255, 0.2);
}
.menuleft li a:hover {
  text-decoration: none;
  color: #fff;
}
#whitebar {
  text-decoration: none;
  display: table;
  width: 100%;
  height: 3px;
  background-color: #fff;
  writing-mode: tb-rl;
  -webkit-transform: rotate(90deg);
  -moz-transform: rotate(90deg);
  -o-transform: rotate(90deg);
  -ms-transform: rotate(90deg);
  transform: rotate(180deg);
  white-space: nowrap;
  bottom: 0;
  margin: 0 auto;
}
.image {
  width: 92%;
  height: 100%;
}
.image img {
  width: 100%;
  height: 100%;
}
<div class="menuleft">
  <ul>
    <li id="text">
      <a href="#">Eficácia</a>
    </li>
    <li id="whitebar">
    </li>
    <li id="text">
      <a href="#">Rapidez</a>
    </li>
    <li id="whitebar">
    </li>
    <li id="text">
      <a href="#">Impacto <br> na vida real</a>
    </li>
    <li id="whitebar">
    </li>
    <li id="text">
      <a href="#">Tecnologia <br> avançada</a>
    </li>
    <li id="whitebar">
    </li>
    <li id="text">
      <a href="#">Segurança</a>
    </li>
  </ul>
</div>
<div class="image">
  <img src="https://image.freepik.com/free-vector/modern-abstract-background_1048-1003.jpg" />
</div>

【问题讨论】:

    标签: html css image sidebar overlap


    【解决方案1】:

    为 .image 类添加浮动属性

    .image { float:right; }
    

    【讨论】:

      【解决方案2】:

      在你的 CSS 上试试这个:

      body{
      text-decoration: none;
      margin: 0 auto;
      max-width:100% !important;
      height:auto;}
      
      .fundo img{
      max-width:100% !important;
      height:auto;}
      
      .menuleft {
      background-color: #CDD0D2;
      list-style-type: none;
      position: relative;
      width: 9%;
      height: 100%;
      display:inline-block;
      }
      
      .menuleft ul{
      list-style-type: none;
      margin: 0;
      padding: 0;
      overflow: hidden;
      vertical-align: middle;
      position: absolute;
      top: 50%;
      left: 50%;
      margin-right: -50%;
      transform: translate(-50%, -50%);
      }
      
      #text {
      -webkit-box-shadow: inset -7px 4px 5px 0px rgba(0,0,0,0.22);
      -moz-box-shadow: inset -7px 4px 5px 0px rgba(0,0,0,0.22);
      box-shadow: inset -7px 4px 5px 0px rgba(0,0,0,0.22);
      width: 100%;
      height: 17%;
      color: white;
      text-align: center;
      text-decoration: none;
      background-color: #F06D22;
      }
      
      .menuleft li a {
      font-family: Futura LT,'Trebuchet MS', Arial;
      letter-spacing: 0.28vw;
      color: #fff;
      text-decoration: none;
      height: 100%;
      text-align: center;
      display: flex;
      vertical-align: middle;
      align-items: center;
      justify-content: center;
      width: 100%;
      writing-mode: tb-rl;
      -webkit-transform:rotate(180deg);
      -moz-transform:rotate(180deg);
      -o-transform: rotate(180deg);
      -ms-transform:rotate(180deg);
      transform: rotate(180deg);
      white-space:nowrap;
      }
      
      .menuleft li:hover {
      text-decoration: none;
      background: rgba(255,255,255,0.2);
      }
      
      .menuleft li a:hover {
      text-decoration: none;
      color: #fff;
      }
      
      #whitebar{
      text-decoration: none;
      display: table;
      width: 100%;
      height: 3px;
      background-color: #fff;
      writing-mode:tb-rl;
      -webkit-transform:rotate(90deg);
      -moz-transform:rotate(90deg);
      -o-transform: rotate(90deg);
      -ms-transform:rotate(90deg);
      transform: rotate(180deg);
      white-space:nowrap;
      bottom:0;
      margin: 0 auto;
      }
      
      .image {
      width: 90%;
      height:100%;
      display:inline-block;
      }
      
      .image img {
      width: 100%;
      height: 100%;
      }
      

      【讨论】:

        【解决方案3】:

        您在 CSS 上使用“class”(.) 标签而不是“id”(#) 标签,因此请尝试将 HTML 上的所有“id”标签更改为“class”。像这样:

        <body>
            <div class="menuleft">
                <ul>
                    <li class="text">
                        <a href="#">Eficácia</a>
                    </li>
                    <li class="whitebar">
                    </li>
                    <li class="text">
                        <a href="#">Rapidez</a>
                    </li>
                    <li class="whitebar">
                    </li>
                    <li class="text">
                        <a href="#">Impacto <br> na vida real</a>
                    </li>
                    <li id="whitebar">
                    </li>
                    <li class="text">
                        <a href="#">Tecnologia <br> avançada</a>
                    </li>
                    <li class="whitebar">
                    </li>
                    <li class="text">
                        <a href="#">Segurança</a>
                    </li>
                </ul>
        </div>
          <div class="image">
            <img src="https://image.freepik.com/free-vector/modern-abstract-background_1048-1003.jpg" />
        </div>
        

        【讨论】:

        • 好的,谢谢,但这并不能解决我的问题...图片仍在边栏后面,我希望它在边栏旁边
        • 我发布了一个新答案。
        【解决方案4】:

        根据cmets理解更新demo如下DEMO 2

        DEMO 1

        css 变化

        .menuleft {
          background-color: #CDD0D2;
          list-style-type: none;
          /*position: absolute;*/
          width: 9%;
          height: 100%;
          /*display: table;*/
          float: left; /* float to left */
        }
        
        .menuleft ul {
          /*display: table-cell;*/ /* remove this */
          list-style-type: none;
          margin: 0;
          padding: 0;
          overflow: hidden;
          vertical-align: middle;
        }
        
        .menuleft li a {
          font-family: Futura LT, 'Trebuchet MS', Arial;
          letter-spacing: 0.28vw;
          color: #fff;
          text-decoration: none;
          /*height: 100%;*/
          text-align: center;
          display: flex;
          vertical-align: middle;
          align-items: center;
          justify-content: center;
          width: 100%;
          writing-mode: tb-rl;
          -webkit-transform: rotate(180deg);
          -moz-transform: rotate(180deg);
          -o-transform: rotate(180deg);
          -ms-transform: rotate(180deg);
          transform: rotate(180deg);
          white-space: nowrap;
        }
        
        .image {
          width: 91%; /* remaining space */
          height: 100%;
          float: right; /* add this to float it to right */
        }
        

        【讨论】:

        • 这样图像就在侧边栏下方。它不再重叠,但不在侧边栏的右侧。
        • 我没听懂你的意思,图片似乎在侧边栏的右侧。还是您需要侧边栏不随页面滚动?
        • 我希望图像就在侧边栏旁边(不重叠)和 100% 的屏幕宽度和高度
        【解决方案5】:

        body{
            text-decoration: none;
            margin: 0 auto;
            max-width:100% !important;
            height:auto;
        }
        
        .fundo img{
            max-width:100% !important;
            height:auto;
        }
        
        
        .menuleft {
            background-color: #CDD0D2;
            list-style-type: none;
            position: absolute;
            width: 9%;
            height: 100%;
            display: table;
        }
        .menuleft ul{
            display: table-cell;
            list-style-type: none;
            margin: 0;
            padding: 0;
            overflow: hidden;
            vertical-align: middle;
        }
        .text {
            -webkit-box-shadow: inset -7px 4px 5px 0px rgba(0,0,0,0.22);
        -moz-box-shadow: inset -7px 4px 5px 0px rgba(0,0,0,0.22);
        box-shadow: inset -7px 4px 5px 0px rgba(0,0,0,0.22);
            width: 100%;
            height: 17%;
            color: white;
            text-align: center;
            text-decoration: none;
            background-color: #F06D22;
        }
        
        .menuleft li a {
            font-family: Futura LT,'Trebuchet MS', Arial;
            letter-spacing: 0.28vw;
            color: #fff;
            text-decoration: none;
            height: 100%;
            text-align: center;
            display: flex;
            vertical-align: middle;
            align-items: center;
            justify-content: center;
            width: 100%;
            writing-mode: tb-rl;
            -webkit-transform:rotate(180deg);
            -moz-transform:rotate(180deg);
            -o-transform: rotate(180deg);
            -ms-transform:rotate(180deg);
            transform: rotate(180deg);
            white-space:nowrap;
        }
        
        .menuleft li:hover {
            text-decoration: none;
            background: rgba(255,255,255,0.2);
        }
        .menuleft li a:hover {
            text-decoration: none;
            color: #fff;
        }
        
        .whitebar{
            text-decoration: none;
            display: table;
            width: 100%;
            height: 3px;
            background-color: #fff;
            writing-mode:tb-rl;
            -webkit-transform:rotate(90deg);
            -moz-transform:rotate(90deg);
            -o-transform: rotate(90deg);
            -ms-transform:rotate(90deg);
            transform: rotate(180deg);
            white-space:nowrap;
            bottom:0;
            margin: 0 auto;
        }
        
        .image {
            list-style-type: none;
            padding: 0;
            top: 0;
            bottom: 0;
            left: 0;
            right: 0;
            margin: auto auto auto 9%;
        }
        .image img {
            width: 100%;
            height: 100%;
        }
        <body>
                <div class="menuleft">
                    <ul>
                        <li class="text">
                            <a href="#">Eficácia</a>
                        </li>
                        <li class="whitebar">
                        </li>
                        <li class="text">
                            <a href="#">Rapidez</a>
                        </li>
                        <li class="whitebar">
                        </li>
                        <li class="text">
                            <a href="#">Impacto <br> na vida real</a>
                        </li>
                        <li class="whitebar">
                        </li>
                        <li class="text">
                            <a href="#">Tecnologia <br> avançada</a>
                        </li>
                        <li class="whitebar">
                        </li>
                        <li class="text">
                            <a href="#">Segurança</a>
                        </li>
                    </ul>
            </div>                
            <div class="image">
                <img src="http://wallpaperfx.com/uploads/wallpapers/2016/04/14/18521/preview_vatna-glacier-icelend.jpg" />
            </div>
        
            
        
        
        </body>

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2021-02-10
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多