@likeapimp
web dev, web design

Почему смещаются div'ы при переносе строки?

Здравствуйте! Первый раз такое встречаю.

Так все норм (когда в 1 строку)
<div class="mid"><section class="item"><h1>Title</h1></section><section class="item"><h1>Title</h1></section><section class="item"><h1>Title</h1></section><section class="item"><h1>Title</h1></section></div>


Так появляются пробелы в 4px между блоками .item
<div class="mid">
  <section class="item"><h1>Title</h1></section>
  <section class="item"><h1>Title</h1></section>
  <section class="item"><h1>Title</h1></section>
  <section class="item"><h1>Title</h1></section>
 </div>


Часть кода с данными блоками (body .wrapper .mid):
<!-- Mid blocks -->
	<div class="mid">
		<section class="item"><h1>Title</h1></section>
		<section class="item"><h1>Title</h1></section>
		<section class="item"><h1>Title</h1></section>
		<section class="item"><h1>Title</h1></section>
	</div>


Стили:
@import "../css/const.css";

@font-face {
    font-family: MyriadProReg;
    src: url(../fonts/MYRIADPROREGULAR.eot); 
}

@font-face {
    font-family: MyriadProReg;
    src: url(../fonts/MYRIADPROREGULAR.ttf); 
}

@font-face {
    font-family: MyriadProReg;
    src: url(../fonts/MyriadPro-Regular.otf); 
}


@font-face {
    font-family: MyriadProSemibold;
    src: url(../fonts/MyriadPro-Semibold.otf); 
}

@font-face {
    font-family: RobotoReg;
    src: url(../fonts/Roboto-Regular.ttf); 
}

@font-face {
    font-family: PTSansNarrow;
    src: url(../fonts/PTN57F.ttf); 
}

@font-face {
    font-family: PTSansNarrowBold;
    src: url(../fonts/PTN77F.ttf); 
}

@font-face {
    font-family: Helvetica;
    src: url(../fonts/Helvetica.ttf); 
}


body {
	background:#d3d3d3;
	position:relative;
	height:2000px;
}

.wrapper {
	width: 969px;
	margin: 0 auto; 
	margin-top: 11px;
}

/* Header */
.header {
	background: #fff;
	position:relative;
	height: 100px;
	border-radius:8px;
}

.header .logo {
	width: 227px;
	position:absolute;
	left:6px;
	top:12px;
}

.header .nav {
	position:absolute;
	right:24px;
	top:39px;
	font-family:RobotoReg, Segoe UI, Arial;
	font-size:13px;
}

.header .nav a {
	display:inline-block;
	color:#000;
}

.header .nav a:after {
	content: "|";
	padding:0 7px 0 9px;
	font-size:18px;
	text-decoration:none !important;
}

.header .nav a:last-child:after,
.header .nav .home:after,
.none {
	display:none !important;
}

.header .nav .home {
	background:#7d7d7d;
	color:#fff;
	padding:6px 22px 6px 15px;
	border-radius:5px;
	margin-right: 6px;
}

/* Top blocks */
.tops {
	margin-top:18px;
	position:relative;
}

/* Slider */
.tops .slider,
.tops .slider a img {
	border-radius:8px;
	width: 566px;
	height:294px;
}
.slick-slider {
	position: relative; 
	display: block; 
	box-sizing: border-box; 
	-moz-box-sizing: border-box; 
	-webkit-touch-callout: none; 
	-webkit-user-select: none; 
	-khtml-user-select: none; 
	-moz-user-select: none; 
	-ms-user-select: none; 
	user-select: none; 
	-ms-touch-action: pan-y; 
	touch-action: pan-y; 
	-webkit-tap-highlight-color: transparent;
	z-index:1;
}

.slick-list {
	position: relative; 
	overflow: hidden; 
	display: block; 
	margin: 0; 
	padding: 0;
}

.slick-list:focus {
	outline: none;
}

.slick-loading .slick-list {
	background: #fff url(../slick/ajax-loader.gif) center center no-repeat;
}

.slick-list.dragging {
	cursor: pointer; 
	cursor: hand;
}

.slick-slider .slick-track {
	-webkit-transform: translate3d(0, 0, 0); 
	-moz-transform: translate3d(0, 0, 0); 
	-ms-transform: translate3d(0, 0, 0); 
	-o-transform: translate3d(0, 0, 0); 
	transform: translate3d(0, 0, 0);
}

.slick-track {
	position: relative; 
	left: 0; 
	top: 0; 
	display: block;
}

.slick-track:before, .slick-track:after {
	content: ""; 
	display: table;
}

.slick-track:after {
	clear: both;
}

.slick-loading .slick-track {
	visibility: hidden;
}

.slick-slide {
	float: left; 
	height: 100%; 
	min-height: 1px; 
	display: none;
}

[dir="rtl"] .slick-slide {
	float: right;
}

.slick-slide img {
	display: block;
}

.slick-slide.slick-loading img {
	display: none;
}

.slick-slide.dragging img {
	pointer-events: none;
}

.slick-initialized .slick-slide {
	display: block;
}

.slick-loading .slick-slide {
	visibility: hidden;
}

.slick-vertical .slick-slide {
	display: block; 
	height: auto; 
	border: 1px solid transparent;
}

.slick-dots {
	margin:0 auto;
	width:60px;
	position:relative;
	margin-top: -22px;
	padding-left: 10px
}

.slick-dots li {
	display:inline;
}

.slick-dots li div{
	display:inline-block;
	background: #7b7f7e;
	border: 1px solid #f2f2f2;
	width: 1px;
	height: 1px;
	padding: 3px;
	margin-right: 6px;
	border-radius: 10px;
	color: transparent; 
	cursor:pointer;
}

.slick-dots li:last-child div{
	margin-right:0;
}

.slick-dots li.slick-active div{
	background:#000;
}

.tops .sign_up {
	background: url(../img/wman.png) no-repeat #fff 200px 3px;
	font-family: MyriadProReg, Segoe UI, Arial Narrow, Arial;
	border-radius: 8px;
	position: absolute;
	padding-left: 19px;
	top: 0;
	right: 0;
	width: 359px;
	height: 294px;
}

.tops .sign_up  .title {
	letter-spacing: -1px;
	font-size: 31.5px;
	color: #2a4e95;
	margin-left:-1px;
	margin-top: 16px;
	line-height: 28px;
}

.tops .sign_up  .text {
	font-size: 14px;
	color: #333333;
	width: 251px;
	width: 274px\0/;
	margin-top: 11px;
	line-height: 15px;
}

.tops .sign_up .options {
	margin-top:16px;
}

.tops .sign_up .options .item {
	display:inline-table;
}

.tops .sign_up .options .item label {
	display:block;
	font-family:Helvetica;
	font-size:13px;
	color:#333333;
	margin-bottom:2px;
}

.tops .sign_up .options .item .select:before{
	content: url(../img/selarr.png);
	display: block;
	width: 12px;
	height: 25px;
	position: absolute;
	top: 0px;
	right: -1px;
	border-left: 2px solid #e0e0e0;
	padding-top: 6px;
	padding-left: 5px;
	box-shadow: inset -2px -5px 3px rgba(0,0,0,0.1);
	z-index:1;
}

.tops .sign_up .options .item .select {
	display: inline-block;
	background: linear-gradient(to bottom, #e9e9e9, #fff);
	width: 48px;
	height: 25px;
	border: 2px solid #e0e0e0;
	border-radius: 5px;
	box-shadow: inset 2px 0px 5px rgba(0,0,0,0.1);
	overflow:hidden;
	position:relative;
	margin-right:1px;
	-webkit-margin-end:4px;
}

.tops .sign_up .options .item select {
	background: transparent;
	font-family: MyriadProReg, Segoe UI, Arial Narrow, Arial;
	border: 0;
	width: 70px;
	height: 24px;
	padding-left: 3px;
	position:relative;
	z-index:2;
}

.tops .sign_up .options .item .w62 select {
	width:84px !important;
}

.tops .sign_up .options .item input {
	border:1px solid #c5c5c5;
	border-radius: 5px;
	height: 24px;
	padding-left: 5px;
	box-shadow: inset 0px 2px 4px rgba(0,0,0,0.1);
	width: 108px;
}

.tops .sign_up .options .item .carrier {
	position:absolute;
	margin-top: -2px;
	margin-left: 1px;
	-moz-margin-start:2px;
	-webkit-margin-start:6px;
}

.tops .sign_up .options .item .w111 select {
	width:133px !important;
}

.tops .sign_up .options .submit {
	display: block;
	background: url(../img/signup.png) no-repeat;
	border: 0;
	width: 94px;
	height: 36px;
	margin-top: 10px;
	cursor: pointer;
}

.tops .sign_up .options .alert {
	position: absolute;
	top: 4px;
	font-family: PTSansNarrow, Arial Narrow, Segoe UI, Arial;
	left: 98px;
	font-size: 14px;
	width: 150px;
	color: #333333;
	text-shadow: 1px 1px 0px #fff;
	line-height: 13px;
}

.mid {
	margin-top:18px;
	height:153px;
}

.mid .item {
	position:relative;
	display:inline-table;
	background:#fff;
	border-right:1px solid #d3d3d3;
	height:153px;
	width:241px;
}

.mid .item:first-child {
	border-radius: 8px 0 0 8px;
}

.mid .item:last-child {
	border-right:0;
	border-radius: 0 8px 8px 0; 
	width:243px;
}

.mid .item:hover {
	background:#5ca5f7;
	cursor:pointer;
}
  • Вопрос задан
  • 2714 просмотров
Решения вопроса 1
thewind
@thewind
php программист, front / backend developer
Потому что блоки имеют стиль inline - из-за этого учитываются пробелы в исходнике между ними.
Сделайте их display:block; float:left; и пробелы уйдут
Ответ написан
Пригласить эксперта
Ответы на вопрос 2
@AlexeyIvanov
Developer
Похожий вопрос был совсем недавно. Как решить проблему с навигацией?
Ответ написан
Комментировать
А в этой статье описано как с помощью костылей победить отступы в inline-block
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы