将元素相对于其他元素定位

时间:2017-11-18 17:11:30

标签: html css

我有一个元素(span),我想放在主元素(文本输入)的右边。主元素以父div为中心。如果将span放置为绝对值,则它与父div相关而不是与输入相关,如果我将span放在相对位置,它会从父项的中间移动输入并从输入的左侧开始(我想要它在左侧并且没有移动他)我不想将跨度相对于父级定位,因为输入大小在滚动中是变化的。 顺便说一句,我的整个网络都是方向:rtl,如果我改变它,那么跨度是输入的右侧,但仍然从中心移动它,我不想改变其他元素的方向我的网站。

1 个答案:

答案 0 :(得分:0)



body{
  direction: rtl;
}
.main_div{
   background: red;
  margin: auto;
   padding: 10px;
   text-align: center;
   width:400px;
  height: 600px;
 }
input{	
  margin: 30px auto;
}
span.titles{
  display:block;
}

<html>
  <head>
  </head>
  <body>
    <div class="main_div">
      <form>
        <span class="titles">input 1</span><span>the additional span</span><input type="text">
        <span class="titles">input 2</span><input type="text">
        <p>i want input 1 to be in the center and the additional span to go more left and i want it to be dynamic like always 5px space to the right of the input.
        thenks
    </div>
  </body>
  </html>
&#13;
&#13;
&#13;