简体   繁体   English

如何将THIS放置在Flex容器中?

[英]How to position –THIS– in a Flex-container?

I'm trying to position the "register" as the picture #1... But the only thing I get is picture #2. 我正在尝试将“注册”定位为图片#1 ...但是我得到的唯一东西是图片#2。

The pic#2 is done as we know in a flexbox, reson why is I'm making the site responsive, and the first site I did (pic#1) wasn't responsive. 正如我们在Flexbox中所知,pic#2已完成,请回想为什么我要使站点响应,而我做的第一个站点(pic#1)却没有响应。

I don't know if I should mix up "col-" classes to my flexbox code or what. 我不知道是否应该在我的flexbox代码中混合使用“ col-”类或什么。 Both pictures are tables. 两张图片均为表格。 And the one in the flexbox is working fine when the viewport is reduced. 当缩小视口时,flexbox中的那个可以正常工作。 I'm using media queries for the responsiveness, pure CSS. 我正在使用媒体查询来获得响应性,即纯CSS。 Not using frameworks. 不使用框架。

How can I freely position anything in a flexbox while keeping everything responsive, if I position elements with padding and margins I won't be able positions anything else there. 我如何在Flexbox中自由放置任何内容,同时保持所有内容的响应速度,如果我使用填充和边距放置元素,那么我将无法在其中放置任何其他内容。

This is what I want: (not a flexbox) 这就是我想要的:(不是flexbox)
This is the most I can get to it: (inside the flexbox) 这是我能得到的最多的东西:(在flexbox内部)

** CSS code for pic# 2 (flexbox childs):** ** pic#2的CSS代码(flexbox childs):**

      /*flex-container*/
          #header {
            position: fixed;
            display: flex;
            flex-wrap: wrap;
            background-color: #343434;
            top: 0;
            right: 0;
            left: 0;
            height: auto;
            padding-left: 10px;
            padding-right: 10px;
            padding-bottom: .3%;
            padding-top: .3%;
            border-bottom: 1px solid white;
            z-index: 1000;
        }

    /*flex-childs*/
/*table*/    #login {
            margin-left: auto;
           }


 /*td*/      #users {
            width: 100%;
            border: 1px solid #ccc;
            box-shadow: 0px 0px 5px black;
            border-radius: 1px;
            font-size: 12px;
            padding: 2px 2px 2px 2px;
        }

   /*td*/     #pass {
            width: 100%;
            border: 1px solid #ccc;
            box-shadow: 0px 0px 5px black;
            border-radius: 1px;
            font-size: 12px;
            padding: 2px 2px 2px 2px;
        }



 /*td*/       #register {
            font-size: 17.5px;
        }

what about something like this, i wrote it from scratch didn't made it to be exactly the same but i believe the structure should be sufficient 像这样的事情呢,我从头开始写并没有做到完全一样,但我认为结构应该足够

first image (to get the full responsive affect you will need to set media query on top-row and change the justify-content: flex-start; ) 第一张图片(要获得全面的响应效果,您需要在顶行设置媒体查询并更改justify-content: flex-start;

https://jsfiddle.net/suunyz3e/1450/ https://jsfiddle.net/suunyz3e/1450/

html: HTML:

<div class="column rows-container">
<div  class="top-row row">
<div>
  <span>Register?</span>
</div>
<div>
  <span>Help Contact</span>
</div>

</div>
<div class="bottom-row row" >
  <div>
    <input type="text" placeholder="email">
  </div>
  <div>
     <input type="text" placeholder="password">
  </div>
</div>

</div>

css: CSS:

.register-box{
  display:inline-flex;
  color:#fff;
  background-color:#111;
  padding-top: 5px;
  padding-bottom: 5px; 
}
.register-box .register-title{
  margin-left:20px;
  font-weight:bold;
}
.column{
  display:flex;
  -webkit-box-orient: vertical;
  -webkit-flex-direction: column;
  flex-direction: column;
  -webkit-box-direction: normal;
}
.rows-container{
    flex-wrap:wrap;
    display:inline-flex;
    color:#fff;
    background-color:#111;
    padding-top: 5px;
    padding-bottom: 5px;
}
.row{
  display:flex;
  -webkit-box-orient: horizontal;
  -webkit-flex-direction: row;
  flex-direction: row;
}

.top-row{
 flex-wrap:wrap;
 justify-content: space-between;
 padding-bottom:12px;
}
.top-row span{
  padding-right:10px;
  font-size:14px;
  font-weight:bold;
  display:block;
  line-height:11px;
}
.bottom-row{
  flex-wrap:wrap;
  margin-right: 25px;
  margin-left:65px;
}

second image 第二张图片

https://jsfiddle.net/suunyz3e/1448/ https://jsfiddle.net/suunyz3e/1448/

html: HTML:

<div class="register-box column">
  <div class="top-row row">
      <div>
          <span class="register">register?</span>
      </div>
      <div>
        <span class="contact">help contact </span>
      </div>
  </div>
   <div class="bottom-row row">
      <div>
        <input type="text" placeholder="email">
      </div>
      <div>
       <input type="text" placeholder="password">
      </div>
      <div>
       <button>
       login
       </button>
      </div>
  </div>
</div>

css: CSS:

.register-box{
  background-color:#111;
  padding-top: 10px;
  padding-bottom: 10px;
 }

.column{
  display:flex;
  -webkit-box-orient: vertical;
  -webkit-flex-direction: column;
  flex-direction: column;
  -webkit-box-direction: normal;
}

.row{
  display:flex;
  -webkit-box-orient: horizontal;
  -webkit-flex-direction: row;
  flex-direction: row;
}

.register-box .top-row{
  flex-wrap:wrap;
  color:#fff;
  text-transform: capitalize;
  padding: 0px 18px 5px 12px;
  justify-content: space-between;
}
.register-box .top-row .register{
      font-weight: bold;
}
.register-box .top-row .contact{
         font-size: 14px;
         line-height:11px;
         font-weight: bold;
         display: block;
}

.register-box .bottom-row{
  flex-wrap:wrap;
  padding: 0px 18px 0px 12px;
}

.register-box .bottom-row input{
  margin-right:5px;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM