Css 改进的(使用flexbox)旧(mailny使用浮点)网格布局,不使用';在某些浏览器中不起作用:不受尊重
我刚刚用旧技术(浮动和内联元素)创建了一个网格布局。它工作得很好。简单地说,我有一个顶级包装类来集中和限制内容的大小。有两个主要部分,每个部分有一个标题(20%),其余部分(80%)以不同的方式细分。甚至有一个弹性排水沟(在em中)设置了填充物。我在设计布局时考虑到了内容和表示之间的良好分离,以实现高代码可维护性,对于这个rason,有一些冗余标记(特别是div) 代码如下:Css 改进的(使用flexbox)旧(mailny使用浮点)网格布局,不使用';在某些浏览器中不起作用:不受尊重,css,flexbox,cross-browser,grid-layout,gutter,Css,Flexbox,Cross Browser,Grid Layout,Gutter,我刚刚用旧技术(浮动和内联元素)创建了一个网格布局。它工作得很好。简单地说,我有一个顶级包装类来集中和限制内容的大小。有两个主要部分,每个部分有一个标题(20%),其余部分(80%)以不同的方式细分。甚至有一个弹性排水沟(在em中)设置了填充物。我在设计布局时考虑到了内容和表示之间的良好分离,以实现高代码可维护性,对于这个rason,有一些冗余标记(特别是div) 代码如下: <!DOCTYPE html> <html lang="en"> <head>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Float layout plus wrapping rows using inline-block</title>
<!-- the base styles and "housekeeping" styles are in here: -->
<link rel="stylesheet" href="css/grid-base.css">
<!-- the HTML5 shiv, to help older browsers understand styling
on newer HTML5 elements: -->
<script src="js/html5shiv.min.js"></script>
<style>
/* grid styling */
.row {
margin: 0 -.6875em;
padding: 0;
list-style: none;
}
.row:after {
content: '';
display: block;
clear: both;
}
.row-quartet > * {
width: 25%;
}
.row-trio > * {
width: 33.3333%;
}
.col {
float: left;
-moz-box-sizing: border-box;
box-sizing: border-box;
margin: 0;
padding: 0 .6875em 1.375em;
}
.col:last-child {
float: right;
}
.row-wrapping {
font-size: 0;
margin: 0 -11px;
margin: 0 -.6875rem;
}
.row-wrapping > * {
float: none;
vertical-align: top;
display: inline-block;
font-size: 16px;
font-size: 1rem;
}
/* content styling */
.subcategory {
margin-top: 1.5em;
border-bottom: 1px solid #8e3339;
}
.subcategory-featured {
width: 50%;
}
.subcategory-content {
width: 80%;
}
.subcategory-header {
width: 20%;
}
.story {
padding: .6875em;
background-color: #eee;
}
.story + .story {
margin-top: 1.375em;
}
.story img {
width: 100%;
}
</style>
</head>
<body>
<header class="masthead">
<div class="wrapper">
<h1>Important News</h1>
</div>
</header>
<nav role="navigation" class="navbar">
<div class="wrapper">
<ul class="navlist">
<li><a href="#">Home</a></li>
<li><a href="#">World</a></li>
<li><a href="#">Local</a></li>
<li><a href="#">Sports</a></li>
</ul>
</div>
</nav>
<main class="wrapper">
<section class="subcategory">
<div class="row">
<header class="col subcategory-header">
<h2>Lorem ipsum</h2>
</header>
<div class="col subcategory-content">
<div class="row row-quartet">
<div class="col subcategory-featured">
<article class="story">
<img src="http://placehold.it/600x300" alt="Dummy image">
<h3><a href="#">Cras suscipit nec leo id.</a></h3>
<p>Autem repudiandae aliquid tempora quos reprehenderit architecto, sequi repellat.</p>
</article>
</div>
<div class="col">
<article class="story">
<img src="http://placehold.it/600x300" alt="Dummy image">
<h3><a href="#">Perferendis, ipsam!</a></h3>
<p>Neque magnam vero obcaecati facere nobis sint dolore accusamus vitae consequuntur ad necessitatibus, laborum molestiae.</p>
</article>
</div>
<div class="col">
<article class="story">
<img src="http://placehold.it/600x300" alt="Dummy image">
<h3><a href="#">Curabitur mattis purus nec velit.</a></h3>
<p>Neque magnam vero obcaecati facere nobis sint dolore accusamus vitae consequuntur ad necessitatibus, laborum molestiae.</p>
</article>
</div>
</div>
<ul class="row row-quartet row-wrapping">
<li class="col">
<div class="story">
<h3><a href="#">Perferendis, ipsam! Dolor sit amet consectetur</a></h3>
</div>
</li>
<li class="col">
<div class="story">
<h3><a href="#">Aliquam mattis eros id posuere.</a></h3>
</div>
</li>
<li class="col">
<div class="story">
<h3><a href="#">Proin leo felis, semper nec</a></h3>
</div>
</li>
<li class="col">
<div class="story">
<h3><a href="#">Aliquam vitae risus tortor. Sed!</a></h3>
</div>
</li>
<li class="col">
<div class="story">
<h3><a href="#">Perferendis, ipsam!</a></h3>
</div>
</li>
<li class="col">
<div class="story">
<h3><a href="#">Aliquam mattis eros id posuere.</a></h3>
</div>
</li>
<li class="col">
<div class="story">
<h3><a href="#">Proin leo felis, semper nec</a></h3>
</div>
</li>
<li class="col">
<div class="story">
<h3><a href="#">Aliquam vitae risus tortor. Sed!</a></h3>
</div>
</li>
</div>
</div>
</div>
</section>
<section class="subcategory">
<div class="row">
<header class="col subcategory-header">
<h2>Dolor sit amet</h2>
</header>
<div class="col subcategory-content">
<div class="row row-trio">
<div class="col">
<article class="story">
<img src="http://placehold.it/600x300" alt="Dummy image">
<h3><a href="#">Ut sit amet mi massa</a></h3>
<p>Neque magnam vero obcaecati facere nobis sint dolore accusamus vitae consequuntur ad necessitatibus, laborum molestiae.</p>
</article>
</div>
<div class="col">
<article class="story">
<h3><a href="#">Nunc mollis sit amet nunc</a></h3>
<p>Neque magnam vero obcaecati facere nobis sint dolore accusamus vitae consequuntur ad necessitatibus, laborum molestiae.</p>
</article>
<article class="story">
<h3><a href="#">Duis sed ante enim. Cras</a></h3>
<p>Neque magnam vero obcaecati facere nobis sint dolore accusamus vitae consequuntur ad necessitatibus, laborum molestiae.</p>
</article>
</div>
<div class="col">
<article class="story">
<img src="http://placehold.it/600x300" alt="Dummy image">
<h3><a href="#">Animi, explicabo, ipsum</a></h3>
<p>Neque magnam vero obcaecati facere nobis sint dolore accusamus vitae consequuntur ad necessitatibus, laborum molestiae.</p>
</article>
</div>
</div>
</div>
</div>
</section>
</main>
</body>
</html>
为了改进我在第二个时刻引入的代码(一种渐进的增强),flexbox的强大功能,添加了一些装饰,作为具有相同高度的box,这是使用float时需要具备的一个棘手特性(事实上,已经有flexbox用于具有类似float的回退功能的导航栏)
我正在使用Modernizer测试特定的flexbox支持(类flexbox和flexwrap)。我在Firefox中获得了一个非常棒的结果(因为我的经验有限),但当我在Google Chrome中测试代码时,我感到非常惊讶,这是一个视觉错误:第一部分的第二个嵌套行与第一行重叠,我无法理解为什么
代码如下:
您可以在JSFIDLE浏览器中看到相同的问题。
我也很感激你的建议,因为我正处于一条死胡同中,如果有一行代码不清楚,我会很乐意接受。
提前谢谢
这里是问题的截图。
请澄清您的具体问题或添加其他详细信息,以突出显示您所需的内容。正如目前所写的,很难准确地说出你在问什么。@Paulie_D我很难用语言描述这个问题。更简单的是,执行第二个JSFIDLE命令时会出现问题。此外,现在我在Windows操作系统中,我正在观察这个版本的google chrome代码的工作原理。过一会儿,我将发布一个屏幕截图,显示在Ubuntu操作系统下的google chrome版本下发现的问题。@Paulie_D我添加了一个屏幕截图,您可以在其中看到问题:
body {
margin: 0;
line-height: 1.375;
font-family: Georgia, Times New Roman, Times, serif;
}
h1,h2,h3,h4,h5,h6 {
font-family: Avenir Next, Avenir, Franklin Gothic, Trebuchet MS, Arial, sans-serif;
margin-top: 0;
}
a {
color: #8E3339;
text-decoration: none;
}
a:hover,
a:focus {
text-decoration: underline;
}
/* here's our wrapper */
.wrapper {
width: 95%;
max-width: 76em;
margin: 0 auto;
}
/* masthead styling */
.masthead {
background-color: #8E3339;
}
.masthead h1 {
margin: 0;
padding: 0.5em 0;
color: #fff;
text-shadow: -.1em .1em 0 rgba(0,0,0,0.3);
}
/* navbar styling */
.navbar {
background-color: #5E2126;
margin-bottom: 1.375em;
}
nav {
display: block;
}
.navbar ul {
font-family: 'Avenir Next', Avenir, Corbel, 'Franklin Gothic', 'Century Gothic', CenturyGothic, AppleGothic, sans-serif;
list-style: none;
padding: 0;
margin: 0;
background-color: #752A2F;
display: flex;
overflow: hidden;
}
.navbar li {
float: left;
text-transform: uppercase;
text-align: center;
box-sizing: border-box;
flex: 1 1 auto;
border-left: 1px solid #8E3339;
}
.navbar li:first-child {
border-left: 0;
}
.navbar li a {
display: block;
text-decoration: none;
line-height: 1.75em;
padding: 1em 2em;
color: #fff;
}