javascript - HTML 页面左侧和右侧的文本

标签 javascript html css

我想要类似这样的 HTML 输出 -

My First Sentence                       My Second Sentence

所以,我的代码是 -

<h3>
   <span style="float:left;">My first sentence</span>
   <a href="#" style="float:right;text-align:right;">My second sentence </a>
</h3>

输出是 -

My First SentenceMy Second Sentence

所以我向元素添加了“margin-left: 100px”,然后输出位于下一行 -

My First Sentence                       
                                 My Second Sentence

请引导我完成此操作。很可能其他一些 css 正在覆盖它,我需要知道如何获得我想要的 View 。我当前的代码看起来像 -

<h3>
   <span style="float:left;">My first sentence</span>
   <a href="#" style="float:right;text-align:right;margin-left: 100px;">My second sentence </a>
</h3>

最佳答案

我看到 displaytext-align/text-align-last 有 3 个选项(您已经使用了 float)。选择是关于您打算支持的浏览器的版本

span,
a {
  display: inline-block;
  /* optionnal*/
}


/* newest browser */

h3.flex {
  display: flex;
  justify-content: space-between;
}


/* check it on canisue.com */

h3.tAl {
  text-align: justify;
  text-align-last: justify;
}


/* oldest browsers such as IE8 */

h3.tA {
  text-align: justify;
}

h3.tA:after {
  content: '';
  display: inline-block;
  width: 100%;
}


/* optionnal to not allow wrapping 
h3[class=^ta] {
white-space:nowrap;
}
*/
<h3 class="flex">
  <span>My first sentence</span>
  <a href="#">My second sentence </a>
</h3>
<h3 class="tAl">
  <span>My first sentence</span>
  <a href="#">My second sentence </a>
</h3>
<h3 class="tA">
  <span>My first sentence</span>
  <a href="#">My second sentence </a>
</h3>

关于javascript - HTML 页面左侧和右侧的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47186732/

相关文章:

javascript - Angularjs 使用 json 填充选择选项

javascript - PHP 脚本作为表单操作 : give server side effents

html - 使用 CSS 时给文本加下划线

css - 是否可以对 @media 规则进行 CSS @supports 检查?

javascript - 更新子 div 的图像大小,使其永远不会超过父 div

javascript - 迭代对象直到找到与标签匹配的值

javascript - 如何在不同按钮之间交替颜色?

javascript - 在 xasis 上使用 jsreport 和纪元时间绘制图表

python - 将 html 写入 csv 时出现奇怪的格式

css - SP2010 QuickLaunch 被 head 标签之间的 css 规则隐藏 - 我不想要这个