简体   繁体   English

为什么这个div不使用CSS移动?

[英]Why doesn't this div move using css?

I have a form inside a div. 我在div内有一个表格。 I want to move the div to the right, and I can do that if I use an inline style like this: 我想将div移到右侧,如果我使用如下内联样式,则可以这样做:

<div class="joinform-page" style="margin-left: 30%;>

I want to move it using margin-left: 30% in the css, not as an inline style because inline styles make media queries more difficult. 我想使用margin-left:在CSS中使用30%,而不是内联样式来移动它,因为内联样式会使媒体查询更加困难。 But it ignores any margin changes I make in the css. 但是它忽略了我在CSS中所做的任何边距更改。

Here's the full html: 这是完整的html:

<div class="joinform-page">
  <div class="form">
    <form action="data_in.php" method="post" name='data_in' id='data_in'>

      <input type="text" placeholder="Email" name="email_field" maxlength="60">
      <input type="text" placeholder="First Name (optional)" name="firstname"   maxlength="50">
      <input type="text" placeholder="Last Name (optional)" name="lastname" maxlength="50">

      <div><input type="hidden" id="password" name="password" value="pwdtemp"></div>
      <div><input type="hidden" id="comments" name="comments" value="none"></div>

      <button class="btn_class" style="color:rgb(255,255,255); background-color:rgb(25,25,25);  text-align:center;" id="btn_submit" onclick="GetDate();">Submit Form</button><br><br><br>

     <div style="padding-left:0%;">
     <label class="container">
     <span class="betajoinpage_cbx">Add me to your list</span>
     <input type="hidden" name="custom_checkbox" value="No">
     <input type="checkbox" id="ckbx" name="custom_checkbox" checked="checked"  value="Yes"><span class="checkmark" style="color:blue;"></span>
     </label></div><br>

</form>
</div>
</div>

Here's the relevant css class: 这是相关的CSS类:

.joinform-page {
  width: 80%;
  padding: 0% 0 0;
  margin-top: -2.5%;
  margin-left: 30%; }

Why doesn't this div move when I use margin-left in the css,. 当我在CSS中使用margin-left时,为什么此div不移动。 not as an inline style. 不作为内联样式。

Thanks for any help. 谢谢你的帮助。

Actually It was working with the same piece of code. 实际上,它正在使用同一段代码。

在此处输入图片说明

If it still doesn't work, there might be styling for parent element or another styling for same element. 如果仍然无法使用,则可能是父元素的样式或同一元素的其他样式。

The CSS you have above works as you would expect. 您上面的CSS可以按预期工作。 Please ensure your CSS is correctly imported like so: 请确保您的CSS已正确导入,如下所示:

<!-- Where FILE_NAME is the name of your .CSS file --> 
<link rel="stylesheet" type="text/css" href="FILE_NAME.css">

 .joinform-page { width: 80%; padding: 0% 0 0; /*margin-top: -2.5%;*/ margin-left: 30%; } 
 <div class="joinform-page"> <div class="form"> <form action="data_in.php" method="post" name='data_in' id='data_in'> <input type="text" placeholder="Email" name="email_field" maxlength="60"> <input type="text" placeholder="First Name (optional)" name="firstname" maxlength="50"> <input type="text" placeholder="Last Name (optional)" name="lastname" maxlength="50"> <div><input type="hidden" id="password" name="password" value="pwdtemp"></div> <div><input type="hidden" id="comments" name="comments" value="none"></div> <button class="btn_class" style="color:rgb(255,255,255); background-color:rgb(25,25,25); text-align:center;" id="btn_submit" onclick="GetDate();">Submit Form</button><br><br><br> <div style="padding-left:0%;"> <label class="container"> <span class="betajoinpage_cbx">Add me to your list</span> <input type="hidden" name="custom_checkbox" value="No"> <input type="checkbox" id="ckbx" name="custom_checkbox" checked="checked" value="Yes"><span class="checkmark" style="color:blue;"></span> </label></div><br> </form> </div> </div> 

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

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