为什么没有这个文本对齐:合理的工作?

时间:2015-11-13 06:01:06

标签: html css anchor text-align

我面临的问题是,在div text-align:justified;内,有a个元素,text-align:justified无法正常运行。所以我写了一个SSCCE来证明这个问题,但令我惊讶和沮丧的是,它确实在SSCCE中起作用。

我已经利用我所有的脑力使SSCCE尽可能与原始代码相似,而且它们在这一点上就像是等效的。所以我发布了两个页面的截图,还有代码。

原始网站的一部分:

enter image description here

以下标记来自.php文件,此<section>有一个<div>,其中包含position:relative; display:table;和几个同级<section>元素,每个元素都有有position:relative。这些是<div>的孩子,position:relative也是<body>的孩子,height:100%的孩子没有位置或显示属性集,但有<section class="body-wrapper full-width"> <div class="everything-wrapper fixed-width"> <p class="desc-para">Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</p> <div class="links-wrapper"> <?php //$num=1; foreach ($links as $a_link) { echo '<a class="a-link" href="' . $a_link->the_url . '" target="_blank">'; echo '<div class="image-replace the-div" style="background-image:url(pix/colours.png); background-repeat:no-repeat; background-position:center center;" >'; echo 'just a link'; echo '</div>'; echo '<p class="caption">Those angel eyes</p>'; echo '</a>'; } ?> </div><!-- .links-wrapper --> </div><!-- .everything-wrapper --> </section>

article, aside, figure, footer, header, hgroup, nav, section, details, summary {
    display: block;
}


section.body-wrapper {
	position:relative;
	background-color:teal;
	width:100%;
	min-width:960px;
}

div.fixed-width {
	width:960px;
	margin-left:auto;
	margin-right:auto;
	padding:0px 10px;
}

.everything-wrapper p.desc-para {
	font-size:18px;
	width:460px;
	margin:0 auto;
	padding:40px 0px 27px;
}

div.links-wrapper {
	background-color:black;
	padding: 20px 0px 50px;
	text-align:justify;
}
div.links-wrapper:after{
  content: "";
  width: 100%;
  display: inline-block;
}

.a-link {
	display:inline-block;
	text-decoration:none;
}

div.the-div {
	font: 0px/0 a;
	border: coral 2px solid;
	height:140px;
	width:140px;
	transition: all 0.3s ease 0s
}

.the-div:hover {
	background-color:grey;
	border: coral 6px solid;
}

.caption {
	font-family:sans-serif;
	font-size:14px;
	padding-top:20px;
	text-align:center;
	color:white;
	font-weight:100;
	transition: all 0.3s ease 0s;
}
.caption:hover {
	color:cyan;
	font-weight:200;
}

CSS:我将CSS复制并粘贴到SSCCE,因此您可以在代码编辑器中找到它;我不是在这里发布的,因为这会让问题变得更长,没有充分的理由。

SSCCE:

enter image description here

&#13;
&#13;
<section class="body-wrapper">



	<div class="everything-wrapper fixed-width">
		<p class="desc-para">Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</p>

		<div class="links-wrapper">

			<a class="a-link" href="#">
				<div class="the-div" style="background-image:url(http://www.monitoryourheart.com/wcm/groups/mdtcom_sg/@mdt/@crdm/documents/images/icon-mri-50px.gif); background-repeat:no-repeat; background-position:center center;">Bulb</div>
				<p class="caption">Strangler Wrangler</p>
			</a>

			<a class="a-link" href="#">
				<div class="the-div" style="background-image:url(http://www.monitoryourheart.com/wcm/groups/mdtcom_sg/@mdt/@crdm/documents/images/icon-mri-50px.gif); background-repeat:no-repeat; background-position:center center;">Bulb</div>
				<p class="caption">Strangler Wrangler</p>
			</a>

			<a class="a-link" href="#">
				<div class="the-div" style="background-image:url(http://www.monitoryourheart.com/wcm/groups/mdtcom_sg/@mdt/@crdm/documents/images/icon-mri-50px.gif); background-repeat:no-repeat; background-position:center center;">Bulb</div>
				<p class="caption">Strangler Wrangler</p>
			</a>

			<a class="a-link" href="#">
				<div class="the-div" style="background-image:url(http://www.monitoryourheart.com/wcm/groups/mdtcom_sg/@mdt/@crdm/documents/images/icon-mri-50px.gif); background-repeat:no-repeat; background-position:center center;">Bulb</div>
				<p class="caption">Strangler Wrangler</p>
			</a>

			<a class="a-link" href="#">
				<div class="the-div" style="background-image:url(http://www.monitoryourheart.com/wcm/groups/mdtcom_sg/@mdt/@crdm/documents/images/icon-mri-50px.gif); background-repeat:no-repeat; background-position:center center;">Bulb</div>
				<p class="caption">Strangler Wrangler</p>
			</a>

			<a class="a-link" href="#">
				<div class="the-div" style="background-image:url(http://www.monitoryourheart.com/wcm/groups/mdtcom_sg/@mdt/@crdm/documents/images/icon-mri-50px.gif); background-repeat:no-repeat; background-position:center center;">Bulb</div>
				<p class="caption">Strangler Wrangler</p>
			</a>

		</div> <!-- .links-wrapper -->

	</div> <!-- .everything-wrapper -->



</section><!-- .body-wrapper -->
&#13;
 var value=[];
               var allValue;
               $('#btn_del').click(function (){
                   $("table tr :checkbox:checked").each(function (){
                     var attrValue=$(this).closest('tr').find("td:eq(1)").attr('id') ;
                     console.log('value is'+attrValue);
                     value.push($('#'+attrValue).html());
                     allValue=value.join();
                     alert('Values Are'+allValue);
                     if($(this).closest('tr').length>0){
                         $(this).closest('tr').remove();
                     }

                  });
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:2)

问题可能是,在您的实时代码中,a元素之间没有空格,而在SSCCE中有一些空格。 text-align:justify通过加宽空格来工作,所以如果没有空格就不会发生