简体   繁体   English

HTML页面左侧和右侧的文本

[英]Text at Left side and Right Side in HTML Page

I want the HTML output similar like this - 我想要类似这样的HTML输出-

 My First Sentence My Second Sentence 

So, my code is - 所以,我的代码是-

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

and the output was - 输出是-

 My First SentenceMy Second Sentence 

So I added "margin-left: 100px" to the element and then the output was in next line- 所以我在元素上添加了“ margin-left:100px”,然后输出在下一行-

 My First Sentence My Second Sentence 

Please guide me through this.Most probably some other css is overwriting it and I need to know how can I get the view what I want. 请通过这个指导我。大多数其他CSS可能会覆盖它,我需要知道如何获得所需的视图。 My current code looks like - 我当前的代码看起来像-

 <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> 

i see 3 options(you used float already) with display and text-align / text-align-last . 我看到3个选项(您已经使用了float)与displaytext-align / text-align-last The choice is about how much old the browser is that you intend to support 选择是关于您打算支持多少版本的浏览器

 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> 

You can create different columns and then left align the text inside them. 您可以创建不同的列,然后使其中的文本左对齐。

 .row{ text-align: left; width: 100%; display: block; } .half-row{ display: inline-block; width: 48%; padding: 1%; float: left; } .clear{ clear: both; } 
 <div class="row"> <div class="half-row"> My First Sentence </div> <div class="half-row"> My Second Sentence </div> <div class="clear"></div> <!-- Needed for float handling --> </div> 

You can just wrap it in a div to keep it in line like this. 您可以将其包装在div中以使其保持一致。

 <div style="width:100%; height:2em; float:left;">
 <h3>
 <span style="float:left;">My first sentence</span>
 <a href="#" style="float:left;text-align:left;margin-left: 100px;">My second sentence </a>
 </h3>
 </div>

It worked by adding margin-left:80px;. 它通过添加margin-left:80px;来工作。 So the final code is - 所以最终的代码是-

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

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

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