【问题标题】:Contact Form submit button positioning联系表单提交按钮定位
【发布时间】:2018-02-12 00:26:07
【问题描述】:

这是我的网站:

http://cvkj.agencialosnavegantes.cl/

我在页面底部有一个联系表单,我试图将提交按钮放在文本框旁边,但我很努力。

这是我最初的 CSS:

#enviarbajo {
    background:url(http://cvkj.agencialosnavegantes.cl/wp-content/uploads/2017/08/paper-plane-2.png) no-repeat;
    background-color: #564585;
    width:40px; 
    height:40px; 
    padding:0px 0 4px 0; 
    border:none; text-indent: -1000em; cursor:pointer;
    border-radius: 0;
    margin: 5%;
    position: relative;
    left: 35%;
   
}

举报帖子 周五下午 1:00 发布 你好

这是我的网站:

http://cvkj.agencialosnavegantes.cl/

我在页面底部有一个联系表单,我试图将提交按钮放在文本框旁边,但我很努力。

这是我最初的 CSS:

enviarbajo {

background:url(http://cvkj.agencialosnavegantes.cl/wp-content/uploads/2017/08/paper-plane-2.png) no-repeat;
background-color: #564585;
width:40px; 
height:40px; 
padding:0px 0 4px 0; 
border:none; text-indent: -1000em; cursor:pointer;
border-radius: 0;
margin: 5%;
position: relative;
left: 35%;

} 然后我尝试使用媒体查询定位按钮,但我无法将按钮放在我想要的位置

@media (max-width: 768px){
   #enviarbajo {
    position: relative;
    right: 100px;
    }
}

以下其他媒体查询:

@media only screen and (max-width: 500px) {
    #enviarbajo {
    position: relative;
    right: 50px;
    }

有没有更有效的方法?

【问题讨论】:

  • 移除#enviarbajo.wpcf7-submit{ left: 0px; } 然后让响应输出都像这样清除 .wpcf7-response-output{ clear: both; } 这样,此消息就不会与表单重叠。

标签: wordpress css css-position contact-form-7


【解决方案1】:

这是这个问题的明确答案,由 Lukasz Mazan 提供

#footer-widgets form.wpcf7-form div:nth-child(2){
  width: calc(100% - 40px);
}
#footer-widgets form.wpcf7-form div:nth-child(2) > span{
  margin: 0;
}
#footer-widgets form.wpcf7-form div:nth-child(2) input{
  width: 100%;
}

#footer-widgets form.wpcf7-form div:nth-child(3){
  width: 40px;
}

有了这个,您可以在每个屏幕尺寸的电子邮件框旁边都有提交按钮。

问题解决了。

【讨论】:

    【解决方案2】:

    当您使用固定宽度按钮时,有 2 个不错的选择,而不是使用 75% 和 25% 宽度的 div。 在这两种解决方案中,都使用 40px 作为按钮宽度。

    第一种解决方案

    对于第一个 div,使用计算宽度:calc(100% - 40px)

    #footer-widgets form.wpcf7-form div:nth-child(2){
      width: calc(100% - 40px);
    }
    #footer-widgets form.wpcf7-form div:nth-child(2) > span{
      margin: 0;
    }
    #footer-widgets form.wpcf7-form div:nth-child(2) input{
      width: 100%;
    }
    
    #footer-widgets form.wpcf7-form div:nth-child(3){
      width: 40px;
    }
    

    第二个解决方案

    使用内边距(40px)和按钮的绝对定位

    #footer-widgets form.wpcf7-form {
      position: relative;
    }
    #footer-widgets form.wpcf7-form div:nth-child(2){
      width: 100%;
      padding-right: 40px;
    }
    #footer-widgets form.wpcf7-form div:nth-child(2) > span{
      margin: 0;
    }
    #footer-widgets form.wpcf7-form div:nth-child(2) input{
      width: 100%;
    }
    
    #footer-widgets form.wpcf7-form div:nth-child(3){
      width: 40px;
      position: absolute;
      top:0;
      right: 0;
    }
    

    【讨论】:

    • 第一个解决方案是最好的,第二个不是那么多。对于第一个解决方案,我希望提交按钮更接近输入类型的电子邮件,我尝试在 #footer-widgets form.wpcf7-form div:nth-child(2){ width: calc(100% - 40像素);像宽度:calc(100% - 100px);但它保持不变。
    • 我可以看到,对于这 2 个宽度为百分比的 div,您仍然有内联 CSS,例如:
      。您需要删除它或使用 !important 来覆盖宽度。您还应该删除 #enviarbajo CSS 上的“left: 35%”。
    • 现在工作正常!但我没有从 div 中删除内联 CSS,因为这会使按钮向下,我只是删除了 #enviarbajo CSS 上的 emove 'left: 35%'
    猜你喜欢
    相关资源
    最近更新 更多
    热门标签