【问题标题】:Edit the distance between two inline elements编辑两个内联元素之间的距离
【发布时间】:2016-05-19 20:47:09
【问题描述】:

目前我有 2 列内容在同一行内联显示。

我要克服的下一个挑战是让这两个元素在同一条线上更接近。

我想我可能在这里找到了答案,但不确定它的含义。如果这是实现上述结果的正确方法,对内容的解释将非常有帮助:Two column width 50% css

或者,我在样式表上设置了当前的 CSS:

.fields-1 {
	float: left;
	width: 46%;
	text-align: center;
	margin: auto auto auto 0;
}

.fields-2 {
	float: right;
	text-align: center;
	display: inline;
	width: 46%;
	padding-top: 5px;
	padding-left: -15px;
	margin: auto 0 auto auto;
}

.fields-2 p {
	font-size: 25px;
	font-weight: 500px;
}

#disclaimer {
	font-size: 16px;
	line-height: 17px;
	font-family: calibri;
	font-style: strong;
	padding-bottom: 15px;
	width: 45%;
}

#your-name {
	width: 45%;
	margin-right: 2px;
}

#your-email {
	width: 45%;
	margin-right: 2px;
}

#NewsletterOptions {
	width: 45%;
	height: 45px;
}
<div class="fields-1">
<p style="text-align: center">[text* your-name id:your-name placeholder: "Team Name/Filmmaker"] <b>(required)</b></p>

<p style="text-align: center">[email* your-email id:your-email placeholder: "Email Address"] <b>(required)</b></p>
<p id="disclaimer">*Your e-mail helps us discuss your contribution with you; this email will not be used for any third party or internal promotions without consent.</p>
</div>
<div class="fields-2">
<p>Would you like 3 new short films to watch each month? </p> <br>
[select* NewsletterOptions id:NewsletterOptions "Yes sure, sounds good!" "Not at the moment, thank you." "Already signed up."]

</div>

就上下文而言,它是联系表格的一半。

您可以就此事提供任何反馈或信息,我们将不胜感激。

另外,如果您建议我将底部的免责声明文本与第一个“.div”中的其他元素对齐,我将不胜感激。

亲切的问候,

【问题讨论】:

  • 您不能同时使用display:inlinefloat...选择其中一个。如果您希望它们靠得更近,请将宽度更改为接近 50%。

标签: html css


【解决方案1】:

您可以在两个 div 周围放置一个包装器并使用 flexbox,这将为您提供两个相邻的 div 的列状分布:

.wrapper {
      display: flex; 
      justify content: space-around;
}

在下面的 sn-p 中,我删除了一些多余的东西 - 不知道你想保留什么,不知道什么。

.wrapper {
  display: flex; 
  justify content: center;
 }
.fields-1 {
	width: 46%;
	text-align: center;
}

.fields-2 {
	text-align: center;
	width: 46%;
	padding-top: 5px;
}

.fields-2 p {
	font-size: 25px;
	font-weight: 500px;
}

#disclaimer {
	font-size: 16px;
	line-height: 17px;
	font-family: calibri;
	font-style: strong;
	padding-bottom: 15px;
}

#your-name {
	margin-right: 2px;
}

#your-email {
	margin-right: 2px;
}

#NewsletterOptions {
	width: 45%;
	height: 45px;
}
<div class="wrapper">
<div class="fields-1">
<p style="text-align: center">[text* your-name id:your-name placeholder: "Team Name/Filmmaker"] <b>(required)</b></p>

<p style="text-align: center">[email* your-email id:your-email placeholder: "Email Address"] <b>(required)</b></p>
<p id="disclaimer">*Your e-mail helps us discuss your contribution with you; this email will not be used for any third party or internal promotions without consent.</p>
</div>
<div class="fields-2">
<p>Would you like 3 new short films to watch each month? </p> <br>
[select* NewsletterOptions id:NewsletterOptions "Yes sure, sounds good!" "Not at the moment, thank you." "Already signed up."]

</div>
  </div>

【讨论】:

  • 您好,感谢您的快速回复。我已经在我的上面添加了你的代码。但是结果是一样的。
  • 我现在应该在弹性框中添加什么以使两列更接近?
  • 您可以做不同的事情:在包装器上尝试justify-content: center,它将它们一起移动到容器的水平中间。如果太接近,请使用左/右边距。还尝试更改左右 DIV 的宽度设置。并删除右侧容器上的负面padding-left(我在我的sn-p中忘记了,但我现在改变了它,也改变了justify-content: center
  • 谢谢你。我应该先运行 sn-p。意识到你现在做了什么,
  • 一个之间的空格有什么作用?我已经尝试过中心,但它似乎与周围的空间没有任何区别。