2016-12-01 65 views
-1

我有定心具有最大宽度元件设置内容的问题。左右间距不一样。 This is a pen to my project。该问题似乎源于 side-post, span_1_of_3,因为右边的可变保证金。不能居中复杂的内容与最大宽度设定

我试图

.inner { 
     display: table; 
     margin: 0 auto; 
    } 

.outer2{ 
    margin: 0 auto; 
    display: table; 
    text-align:center; 
    } 

我有点困惑,这可能是解决这一万阿英,蒋达清。任何想法如何解决它?

此图像显示了cenetering问题,我面对:

enter image description here

+0

什么是'MAX-width'元素应用到它是不居中? – TylerH

+0

。容器元素 – sanjihan

+0

嗯,实际上在div上居中工作。这完全是一个旁发,span_1_of_1的问题。这比我原先想象的更复杂。 – sanjihan

回答

0

您可以使用display:弯曲的.outer2和证明内容:中心对齐项:中心,它应集中你所有的内容

@charset "UTF-8"; 
 
/* CSS Document */ 
 

 
/* Base Styles */ 
 

 
body{ 
 
\t margin: 0; 
 
\t padding: 0; 
 
\t font-size: 16px; 
 
\t line-height: 1.4em; 
 
\t color: #222; 
 
\t background: red; 
 
\t font-family: 'Lato', sans-serif; 
 
} 
 

 
img{ 
 
\t max-width: 100%; 
 
\t height: auto; 
 
\t border-radius: 3px; 
 
} 
 

 
.outer2{ 
 
    justify-content:center; 
 
    align-items:center; 
 
    display: flex; 
 

 
} 
 

 
a{ 
 
\t text-decoration: none; 
 
\t color: inherit; 
 
} 
 

 

 

 
/* Grid */ 
 

 
.section { 
 
\t clear: both; 
 
\t padding: 0; 
 
\t margin: 0; 
 
} 
 

 
.col { 
 
\t display: block; 
 
\t float:left; 
 
\t margin: 1% 0 1% 1.6%; 
 
} 
 
.col:first-child { margin-left: 0; } 
 

 

 
.span_2_of_3 { 
 
\t width: 67.1%; 
 
} 
 
.span_1_of_3 { 
 
\t width: 31.2%; 
 
} 
 

 

 
/* Header & Navigation */ 
 

 

 

 

 

 
/* Blog Posts */ 
 

 
.container{ 
 
\t max-width: 1420px; 
 
\t margin: 0 auto; 
 
\t padding: 20px; 
 
} 
 

 

 

 
.side-post{ 
 
\t background: #fff; 
 
\t margin: 0 auto 1.5em auto; 
 
\t width: 15em; 
 
\t padding: 20px; 
 
} 
 

 

 

 
.side-content{ 
 
\t font-size: .9em; 
 
\t margin-top: 8px; 
 
\t margin-bottom: 0; 
 
} 
 

 

 

 
.date{ 
 
\t 
 
\t text-decoration-color: currentColor; 
 
} 
 

 

 

 
/* Button */ 
 

 
.button{ 
 
\t display: block; 
 
\t padding: 15px 20px; 
 
\t margin-top: .8em; 
 
\t background: #009ACD; 
 
\t text-align: center; 
 
\t color: #fff; 
 
\t font-size: 1.4em; 
 
\t border-radius: 3px; 
 
\t transition: all .4s ease-in; 
 
} 
 

 
.button:hover{ 
 
\t background: #005c7b; 
 
} 
 

 
/*Media Queries*/ 
 

 
@media only screen and (min-width: 1200px) { 
 
.span_2_of_3 { 
 
\t width: 75.1%; 
 
} 
 
.span_1_of_3 { 
 
\t width: 17.2%; 
 
} 
 
} 
 

 
/* @900px*/ 
 
@media only screen and (max-width: 56.25em) { 
 
\t .col{ margin: 1% 0 1% 0%;} 
 
\t .span_2_of_3, .span_1_of_3{ width: 100%; } 
 
\t .side-post{ width: 42%; 
 
\t \t \t float: left; 
 
\t \t \t margin: -2% 0 1% 1.6%;} 
 
} 
 

 
/* @685px*/ 
 
@media only screen and (max-width: 42.813em) { 
 
\t .side-post{ width: auto; 
 
\t \t \t \t padding: 15px; 
 
\t \t \t  margin: -2% auto 8% auto; } 
 
\t .date{ font-size: .9em; } \t \t 
 
} 
 

 
/* @480px */ 
 

 
/* @380px*/ 
 
@media only screen and (max-width: 23.75em) { 
 
\t .side-content{ font-size: .8em; } 
 
\t .button{ padding: 10px 15px; } 
 
} 
 

 

 

 

 
/*CONTENT OF LEFT SIDE*/ 
 
@charset "UTF-8"; 
 
/* CSS Document */ 
 

 
/*PEN STYLES*/ 
 
@import url(https://fonts.googleapis.com/css?family=Open+Sans:400,700|Roboto:400,700); 
 

 
.blog-card { 
 
\t transition: height 0.3s ease; 
 
\t -webkit-transition: height 0.3s ease; 
 
\t background: #fff; 
 
\t border-radius: 3px; 
 
\t box-shadow: 0 3px 7px -3px rgba(0, 0, 0, 0.3); 
 
\t margin: 0 auto 1.6%; 
 
\t overflow: hidden; 
 
\t position: relative; 
 
\t font-size: 14px; 
 
\t line-height: 1.45em; 
 
\t height:460px; 
 
\t -webkit-font-smoothing: antialiased; 
 
\t -moz-osx-font-smoothing: grayscale; 
 
} 
 

 

 
.blog-card:hover .details { 
 
\t left: 0; 
 
} 
 

 
.blog-card:hover.alt .details { 
 
\t right: 0; 
 
} 
 

 
.blog-card.alt .details { 
 
\t right: -100%; 
 
\t left: inherit; 
 
} 
 

 
.blog-card .photo { 
 
\t height: 200px; 
 
\t position: relative; 
 
} 
 

 
.blog-card .photo.photo1 { 
 
\t background: url("http://i62.tinypic.com/34oq4o0.jpg") center no-repeat; 
 
\t background-size: cover; 
 
} 
 

 
.blog-card .photo.photo2 { 
 
\t background: url("http://i60.tinypic.com/xeiv79.jpg") center no-repeat; 
 
\t background-size: cover; 
 
} 
 

 
.blog-card .details { 
 
\t transition: all 0.3s ease; 
 
\t -webkit-transition: all 0.3s ease; 
 
\t background: rgba(0, 0, 0, 0.6); 
 
\t box-sizing: border-box; 
 
\t color: #fff; 
 
\t font-family: "Open Sans"; 
 
\t list-style: none; 
 
\t margin: 0; 
 
\t padding: 10px 15px; 
 
\t height: 300px; 
 
    /*POSITION*/ 
 
\t position: absolute; 
 
\t top: 0; 
 
\t left: -100%; 
 
} 
 

 
.blog-card .details > li { 
 
\t padding: 3px 0; 
 
} 
 

 
.blog-card .details li:before, .blog-card .details .tags ul:before { 
 
\t font-family: FontAwesome; 
 
\t margin-right: 10px; 
 
\t vertical-align: middle; 
 
} 
 

 
.blog-card .details .author:before { 
 
\t content: "\f007"; 
 
} 
 

 
.blog-card .details .date:before { 
 
\t content: "\f133"; 
 
} 
 

 
.blog-card .details .tags ul { 
 
\t list-style: none; 
 
\t margin: 0; 
 
\t padding: 0; 
 
} 
 

 
.blog-card .details .tags ul:before { 
 
\t content: "\f02b"; 
 
} 
 

 
.blog-card .details .tags li { 
 
\t display: inline-block; 
 
\t margin-right: 3px; 
 
} 
 

 
.blog-card .details a { 
 
\t color: inherit; 
 
\t border-bottom: 1px dotted; 
 
} 
 

 
.blog-card .details a:hover { 
 
\t color: #75D13B; 
 
} 
 

 
.blog-card .description { 
 
\t padding: 10px; 
 
\t box-sizing: border-box; 
 
\t position: relative; 
 
} 
 

 
.blog-card .description h1 { 
 
\t font-family: "Roboto"; 
 
\t line-height: 1em; 
 
\t margin: 0 0 10px 0; 
 
} 
 

 
.blog-card .description h2 { 
 
\t color: #9b9b9b; 
 
\t font-family: "Open Sans"; 
 
\t line-height: 1.2em; 
 
\t text-transform: uppercase; 
 
\t font-size: 1em; 
 
\t font-weight: 400; 
 
\t margin: 1.2% 0; 
 
} 
 

 
.blog-card .description p { 
 
\t position: relative; 
 
\t margin: 0; 
 
\t padding-top: 20px; 
 
} 
 

 
.blog-card .description p:after { 
 
\t content: ""; 
 
\t background: #75D13B; 
 
\t height: 6px; 
 
\t width: 40px; 
 
     /*POSITION*/ 
 
\t position: absolute; 
 
\t top: 6px; 
 
\t left: 0; 
 
} 
 

 
.blog-card .description a { 
 
\t color: #75D13B; 
 
\t margin-bottom: 10px; 
 
\t float: right; 
 
} 
 

 
.blog-card .description a:after { 
 
\t transition: all 0.3s ease; 
 
\t -webkit-transition: all 0.3s ease; 
 
\t content: "\f061"; 
 
\t font-family: FontAwesome; 
 
\t margin-left: -10px; 
 
\t opacity: 0; 
 
\t vertical-align: middle; 
 
} 
 

 
.blog-card .description a:hover:after { 
 
\t margin-left: 5px; 
 
\t opacity: 1; 
 
} 
 

 
@media screen and (min-width: 700px) { 
 
\t .blog-card { 
 
\t \t height: 300px; 
 
\t \t max-width: 900px; 
 
\t } 
 

 
\t .blog-card:hover .photo { 
 
\t \t transform: rotate(5deg) scale(1.3); 
 
\t } 
 

 
\t .blog-card:hover.alt .photo { 
 
\t \t transform: rotate(-5deg) scale(1.3); 
 
\t } 
 

 
\t .blog-card.alt .details { 
 
\t \t padding-left: 30px; 
 
\t } 
 

 
\t .blog-card.alt .description { 
 
\t \t float: right; 
 
\t } 
 

 
\t .blog-card.alt .description:before { 
 
\t \t transform: skewX(5deg); 
 
\t \t right: -15px; 
 
\t \t left: inherit; 
 
\t } 
 

 
\t .blog-card.alt .photo { 
 
\t \t float: right; 
 
\t } 
 

 
\t .blog-card .photo { 
 
\t \t transition: all 0.5s ease; 
 
\t \t -webkit-transition: all 0.5s ease; 
 
\t \t float: left; 
 
\t \t height: 100%; 
 
\t \t width: 40%; 
 
\t } 
 

 
\t .blog-card .details { 
 
\t \t width: 40%; 
 
\t } 
 

 
\t .blog-card .description { 
 
\t \t float: left; 
 
\t \t width: 60%; 
 
\t \t z-index: 0; 
 
\t } 
 

 
\t .blog-card .description:before { 
 
\t \t transform: skewX(-5deg); 
 
\t \t content: ""; 
 
\t \t background: #fff; 
 
\t \t width: 100%; 
 
\t \t z-index: -1; 
 
     /*POSITION*/ 
 
\t \t position: absolute; 
 
\t \t left: -15px; 
 
\t \t top: 0; 
 
\t \t bottom: 0; 
 
\t height:300px; 
 
\t } 
 
}
<html> 
 
<head> 
 
<meta charset="UTF-8"> 
 
<title>Untitled Document</title> 
 

 
\t <link rel="stylesheet" href="css/blog.css"> 
 
\t <link rel="stylesheet" href="css/blog2.css"> 
 

 
</head> 
 

 
<body> 
 
\t <div class="outer2"> 
 
\t <div class="container inner"> 
 
\t \t <div class="section"> 
 
\t \t \t  <div class="col span_2_of_3"> 
 
     \t 
 
<!--LEFT SIDE--> 
 
<div class="blog-card"> 
 
\t <div class="photo photo1"></div> 
 
\t <ul class="details"> 
 
\t \t <li class="author"><a href="#">John Doe</a></li> 
 
\t \t <li class="date">Aug. 24, 2015</li> 
 
\t \t <li class="tags"> 
 
\t \t \t <ul> 
 
\t \t \t \t <li><a href="#">Learn</a></li> 
 
\t \t \t \t <li><a href="#">Code</a></li> 
 
\t \t \t \t <li><a href="#">HTML</a></li> 
 
\t \t \t \t <li><a href="#">CSS</a></li> 
 
\t \t \t </ul> 
 
\t \t </li> 
 
\t </ul> 
 
\t <div class="description"> 
 
\t \t <h1>Learning to Code</h1> 
 
\t \t <h2>Opening a door to the future</h2> 
 
\t \t <p class="summary">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ad eum dolorum architecto obcaecati enim dicta praesentium, quam nobis! Neque ad aliquam facilis numquam. Veritatis, sit. Loren ipsum h Holalala araba aranbd the good dog now. <br> <br> Loren ipsum h Holalala araba aranbd the good dog now. Loren ipsum h Holalala araba aranbd the good dog now. Loren ipsum h Holalala araba aranbd the good dog now. Loren ipsum h Holalala araba aranbd the good dog now. </p> 
 
\t \t <a href="#">Read More</a> 
 
\t </div> 
 
</div> 
 
<div class="blog-card alt"> 
 
\t <div class="photo photo2"></div> 
 
\t <ul class="details"> 
 
\t \t <li class="author"><a href="#">Jane Doe</a></li> 
 
\t \t <li class="date">July. 15, 2015</li> 
 
\t \t <li class="tags"> 
 
\t \t \t <ul> 
 
\t \t \t \t <li><a href="#">Learn</a></li> 
 
\t \t \t \t <li><a href="#">Code</a></li> 
 
\t \t \t \t <li><a href="#">JavaScript</a></li> 
 
\t \t \t </ul> 
 
\t \t </li> 
 
\t </ul> 
 
\t <div class="description"> 
 
\t \t <h1>Mastering the Language</h1> 
 
\t \t <h2>Java is not the same as JavaScript</h2> 
 
\t \t <p class="summary">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ad eum dolorum architecto obcaecati enim dicta praesentium, quam nobis! Neque ad aliquam facilis numquam. Veritatis, sit. Loren ipsum h Holalala araba aranbd the good dog now. <br> <br> Loren ipsum h Holalala araba aranbd the good dog now. Loren ipsum h Holalala araba aranbd the good dog now. Loren ipsum h Holalala araba aranbd the good dog now. Loren ipsum h Holalala araba aranbd the good dog now. </p> 
 
\t \t <a href="#">Read More</a> 
 
\t </div> 
 
</div> 
 

 
\t \t \t  </div> 
 
\t \t \t \t 
 
\t \t \t  <aside class="col span_1_of_3"> 
 
\t \t \t \t  <div class="side-post"> 
 
\t \t \t \t \t   <img src="http://placehold.it/800x400&text=img" alt="img"> 
 
      <p class="side-content">Ut noster tractavissent, summis hic eiusmod te quem. Doctrina velit litteris eu eu fore ingeniis philosophari ne quid o ingeniis ne anim, illum ea iudicem. Pariatur duis dolor hic dolor ad vidisse amet elit ita summis, quo duis te malis.</p> 
 
\t \t \t \t  </div> 
 
\t \t \t \t 
 
\t \t \t \t  <div class="side-post"> 
 
\t \t \t \t \t   <p class="side-content">Ultricies lacus et, non orci gravida purus augue integer, sed turpis. Erat dapibus. \t \t \t \t \t \t Eleifend massa scelerisque, aenean penatibus laoreet ut in.</p> 
 
     \t \t \t \t \t <a href="#" class="button">Subscribe!</a> 
 
\t \t \t \t  </div> 
 
\t \t \t  </aside> 
 
\t \t </div> 
 
\t </div> 
 
</div> 
 

 
</body> 
 
</html>

+0

嗯,它变得明显,低于1200px这种解决方案不再工作。 – sanjihan

+0

我不明白...你可以请更具体 – Geeky

+0

我添加了一张图片。查看主要内容左侧和右侧的间距。它在右侧更大。 – sanjihan

1

删除宽度:15em;从.side-后和间距将等于

+0

不工作:( – sanjihan

+0

它确实在您共享笔。如果没有在您的网站工作或在本地,那么你的代码是不是在笔的代码不同,或者你的CSS缓存。 – Vel

+0

谢谢你帮助我我认为codepen不会缓存,也许我们误解了对方,我试图在主要内容的最左侧(和屏幕边缘)和最右侧(以及屏幕右侧)有相同的间距在大屏幕上,它看起来如此,但在较小的情况下显然有些东西被打破。 – sanjihan

0

更改侧柱的CSS。您的利润率设置正确,但side_post具有固定的宽度。它应该是100%。

老CSS

.side-post { 
    background: #fff; 
    margin: 0 auto 1.5em auto; 
    width: 15em; 
    padding: 20px; 
} 

新的CSS

.side-post { 
    background: #fff; 
    /* margin: 0 auto 1.5em auto; */ 
    width: 100%; 
    padding: 20px; 
    box-sizing: border-box; 
} 
+0

不工作:( – sanjihan

+0

你谈论任何具体的响应状态? –

相关问题