Dr_Hoon
Dr_Hoon

Reputation: 67

css tables out of alignment with bootstrap

I've sliced up a bunch of images in Photoshop and exported the slices with the css table mark-up. The css works fine, placing each slice in the correct position, that is, until the bootstrap css file is added to the page. This causes some of the images go out of alignment on a desktop browser but not on a mobile device.

Here's an example of a table that looks fine, until bootstrap.css is placed in the head of the document. In this instance, it's just 1 image, image #3 that's out of alignment (4 pixels down with bootstrap 3, and 6 pixels down with bootstrap 4).

Without Bootstrap

div.Table_01 {
	position:absolute;
	left:0px;
	top:0px;
	width:272px;
	height:340px;
}

div.jyd-01 {
	position:absolute;
	left:0px;
	top:0px;
	width:272px;
	height:68px;
}

div.jyd-02 {
	position:absolute;
	left:0px;
	top:68px;
	width:67px;
	height:71px;
}

div.jyd-03 {
	position:absolute;
	left:67px;
	top:68px;
	width:57px;
	height:15px;
}

div.jyd-04 {
	position:absolute;
	left:124px;
	top:68px;
	width:148px;
	height:71px;
}

div.jyd-05 {
	position:absolute;
	left:67px;
	top:83px;
	width:57px;
	height:56px;
}

div.jyd-06 {
	position:absolute;
	left:0px;
	top:139px;
	width:42px;
	height:201px;
}

div.jyd-07 {
	position:absolute;
	left:42px;
	top:139px;
	width:28px;
	height:24px;
}

div.jyd-08 {
	position:absolute;
	left:70px;
	top:139px;
	width:51px;
	height:201px;
}

div.jyd-09 {
	position:absolute;
	left:121px;
	top:139px;
	width:27px;
	height:23px;
}

div.jyd-10 {
	position:absolute;
	left:148px;
	top:139px;
	width:124px;
	height:115px;
}

div.jyd-11 {
	position:absolute;
	left:121px;
	top:162px;
	width:27px;
	height:178px;
}

div.jyd-12 {
	position:absolute;
	left:42px;
	top:163px;
	width:28px;
	height:177px;
}

div.jyd-13 {
	position:absolute;
	left:148px;
	top:254px;
	width:24px;
	height:86px;
}

div.jyd-14 {
	position:absolute;
	left:172px;
	top:254px;
	width:100px;
	height:86px;
}

body {
  background: yellow;
}
<div class="Table_01">
	<div class="jyd-01">
		<img src="https://picsum.photos/272/68?image=990" width="272" height="68" alt="">
	</div>
	<div class="jyd-02">
		<img src="https://picsum.photos/67/71?image=990" width="67" height="71" alt="">
	</div>
	<div class="jyd-03">
		<img src="https://picsum.photos/15/57?image=990" width="57" height="15" alt="">
	</div>
	<div class="jyd-04">
		<img src="https://picsum.photos/148/71?image=990" width="148" height="71" alt="">
	</div>
	<div class="jyd-05">
		<img src="https://picsum.photos/57/56?image=990" width="57" height="56" alt="">
	</div>
	<div class="jyd-06">
		<img src="https://picsum.photos/42/201?image=990" width="42" height="201" alt="">
	</div>
	<div class="jyd-07">
		<img src="https://picsum.photos/28/28?image=990" width="28" height="24" alt="">
	</div>
	<div class="jyd-08">
		<img src="https://picsum.photos/51/201?image=990" width="51" height="201" alt="">
	</div>
	<div class="jyd-09">
		<img src="https://picsum.photos/27/23?image=990" width="27" height="23" alt="">
	</div>
	<div class="jyd-10">
		<img src="https://picsum.photos/124/115?image=990" width="124" height="115" alt="">
	</div>
	<div class="jyd-11">
		<img src="https://picsum.photos/27/178?image=990" width="27" height="178" alt="">
	</div>
	<div class="jyd-12">
		<img src="https://picsum.photos/28/177?image=990" width="28" height="177" alt="">
	</div>
	<div class="jyd-13">
		<img src="https://picsum.photos/24/86?image=990" width="24" height="86" alt="">
	</div>
	<div class="jyd-14">
		<img src="https://picsum.photos/100/86?image=990" width="100" height="86" alt="">
	</div>
</div>

With Bottstrap

div.Table_01 {
	position:absolute;
	left:0px;
	top:0px;
	width:272px;
	height:340px;
}

div.jyd-01 {
	position:absolute;
	left:0px;
	top:0px;
	width:272px;
	height:68px;
}

div.jyd-02 {
	position:absolute;
	left:0px;
	top:68px;
	width:67px;
	height:71px;
}

div.jyd-03 {
	position:absolute;
	left:67px;
	top:68px;
	width:57px;
	height:15px;
}

div.jyd-04 {
	position:absolute;
	left:124px;
	top:68px;
	width:148px;
	height:71px;
}

div.jyd-05 {
	position:absolute;
	left:67px;
	top:83px;
	width:57px;
	height:56px;
}

div.jyd-06 {
	position:absolute;
	left:0px;
	top:139px;
	width:42px;
	height:201px;
}

div.jyd-07 {
	position:absolute;
	left:42px;
	top:139px;
	width:28px;
	height:24px;
}

div.jyd-08 {
	position:absolute;
	left:70px;
	top:139px;
	width:51px;
	height:201px;
}

div.jyd-09 {
	position:absolute;
	left:121px;
	top:139px;
	width:27px;
	height:23px;
}

div.jyd-10 {
	position:absolute;
	left:148px;
	top:139px;
	width:124px;
	height:115px;
}

div.jyd-11 {
	position:absolute;
	left:121px;
	top:162px;
	width:27px;
	height:178px;
}

div.jyd-12 {
	position:absolute;
	left:42px;
	top:163px;
	width:28px;
	height:177px;
}

div.jyd-13 {
	position:absolute;
	left:148px;
	top:254px;
	width:24px;
	height:86px;
}

div.jyd-14 {
	position:absolute;
	left:172px;
	top:254px;
	width:100px;
	height:86px;
}

body {
  background: yellow;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<div class="Table_01">
	<div class="jyd-01">
		<img src="https://picsum.photos/272/68?image=990" width="272" height="68" alt="">
	</div>
	<div class="jyd-02">
		<img src="https://picsum.photos/67/71?image=990" width="67" height="71" alt="">
	</div>
	<div class="jyd-03">
		<img src="https://picsum.photos/15/57?image=990" width="57" height="15" alt="">
	</div>
	<div class="jyd-04">
		<img src="https://picsum.photos/148/71?image=990" width="148" height="71" alt="">
	</div>
	<div class="jyd-05">
		<img src="https://picsum.photos/57/56?image=990" width="57" height="56" alt="">
	</div>
	<div class="jyd-06">
		<img src="https://picsum.photos/42/201?image=990" width="42" height="201" alt="">
	</div>
	<div class="jyd-07">
		<img src="https://picsum.photos/28/28?image=990" width="28" height="24" alt="">
	</div>
	<div class="jyd-08">
		<img src="https://picsum.photos/51/201?image=990" width="51" height="201" alt="">
	</div>
	<div class="jyd-09">
		<img src="https://picsum.photos/27/23?image=990" width="27" height="23" alt="">
	</div>
	<div class="jyd-10">
		<img src="https://picsum.photos/124/115?image=990" width="124" height="115" alt="">
	</div>
	<div class="jyd-11">
		<img src="https://picsum.photos/27/178?image=990" width="27" height="178" alt="">
	</div>
	<div class="jyd-12">
		<img src="https://picsum.photos/28/177?image=990" width="28" height="177" alt="">
	</div>
	<div class="jyd-13">
		<img src="https://picsum.photos/24/86?image=990" width="24" height="86" alt="">
	</div>
	<div class="jyd-14">
		<img src="https://picsum.photos/100/86?image=990" width="100" height="86" alt="">
	</div>
</div>

I can fix the inexplicable misalignment by changing the css to top:64px except that it will then be misaligned on a mobile device.

A similar thing happens on every single table I've exported. I can't seem to find anything on the issue. I guess I must be the only person still using Photoshop sliced tables and trying to do so with Bootstrap. But I have my reasons. Thanks in advance.

Upvotes: 0

Views: 42

Answers (1)

yunzen
yunzen

Reputation: 33439

The Bootstrap changes the line-height and font-size of the body element, which is inherited. This is problematic on the small images, as one line—which the image is part of—will be higher than the image.

Setting the line-height to zero on the image container divs solves your issue

div.Table_01,
div.Table_02,
div.Table_03,
div.Table_04,
div.Table_05,
div.Table_06,
div.Table_07,
div.Table_08,
div.Table_09,
div.Table_10,
div.Table_11,
div.Table_12,
div.Table_13,
div.Table_14 {
  line-height: 0;
}

div.Table_01 {
	position:absolute;
	left:0px;
	top:0px;
	width:272px;
	height:340px;
}

div.jyd-01 {
	position:absolute;
	left:0px;
	top:0px;
	width:272px;
	height:68px;
}

div.jyd-02 {
	position:absolute;
	left:0px;
	top:68px;
	width:67px;
	height:71px;
}

div.jyd-03 {
	position:absolute;
	left:67px;
	top:68px;
	width:57px;
	height:15px;
}

div.jyd-04 {
	position:absolute;
	left:124px;
	top:68px;
	width:148px;
	height:71px;
}

div.jyd-05 {
	position:absolute;
	left:67px;
	top:83px;
	width:57px;
	height:56px;
}

div.jyd-06 {
	position:absolute;
	left:0px;
	top:139px;
	width:42px;
	height:201px;
}

div.jyd-07 {
	position:absolute;
	left:42px;
	top:139px;
	width:28px;
	height:24px;
}

div.jyd-08 {
	position:absolute;
	left:70px;
	top:139px;
	width:51px;
	height:201px;
}

div.jyd-09 {
	position:absolute;
	left:121px;
	top:139px;
	width:27px;
	height:23px;
}

div.jyd-10 {
	position:absolute;
	left:148px;
	top:139px;
	width:124px;
	height:115px;
}

div.jyd-11 {
	position:absolute;
	left:121px;
	top:162px;
	width:27px;
	height:178px;
}

div.jyd-12 {
	position:absolute;
	left:42px;
	top:163px;
	width:28px;
	height:177px;
}

div.jyd-13 {
	position:absolute;
	left:148px;
	top:254px;
	width:24px;
	height:86px;
}

div.jyd-14 {
	position:absolute;
	left:172px;
	top:254px;
	width:100px;
	height:86px;
}

body {
  background: yellow;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<div class="Table_01">
	<div class="jyd-01">
		<img src="https://picsum.photos/272/68?image=990" width="272" height="68" alt="">
	</div>
	<div class="jyd-02">
		<img src="https://picsum.photos/67/71?image=990" width="67" height="71" alt="">
	</div>
	<div class="jyd-03">
		<img src="https://picsum.photos/15/57?image=990" width="57" height="15" alt="">
	</div>
	<div class="jyd-04">
		<img src="https://picsum.photos/148/71?image=990" width="148" height="71" alt="">
	</div>
	<div class="jyd-05">
		<img src="https://picsum.photos/57/56?image=990" width="57" height="56" alt="">
	</div>
	<div class="jyd-06">
		<img src="https://picsum.photos/42/201?image=990" width="42" height="201" alt="">
	</div>
	<div class="jyd-07">
		<img src="https://picsum.photos/28/28?image=990" width="28" height="24" alt="">
	</div>
	<div class="jyd-08">
		<img src="https://picsum.photos/51/201?image=990" width="51" height="201" alt="">
	</div>
	<div class="jyd-09">
		<img src="https://picsum.photos/27/23?image=990" width="27" height="23" alt="">
	</div>
	<div class="jyd-10">
		<img src="https://picsum.photos/124/115?image=990" width="124" height="115" alt="">
	</div>
	<div class="jyd-11">
		<img src="https://picsum.photos/27/178?image=990" width="27" height="178" alt="">
	</div>
	<div class="jyd-12">
		<img src="https://picsum.photos/28/177?image=990" width="28" height="177" alt="">
	</div>
	<div class="jyd-13">
		<img src="https://picsum.photos/24/86?image=990" width="24" height="86" alt="">
	</div>
	<div class="jyd-14">
		<img src="https://picsum.photos/100/86?image=990" width="100" height="86" alt="">
	</div>
</div>

Upvotes: 1

Related Questions