基于CSS网格和元素间边框的报纸版面设计技术

我最近不得不设计一个类似报纸的设计,它的特点是多行和多列跨距之间有分隔线。看看这里的模型图,看看它是否让你汗流浃背。如果你和我一样,你已经有一段时间了,你知道用旧的版面设计技术会有多困难。 报纸设计,在单元格之间使用分格器 这个项目有一些要求: - 显示网格的轮廓 - 列可以更宽,也可以更长,在不同的块之间必须显示分隔线,这意味着元素在水平轴或垂直轴上流动,因此教给旧的布局新技巧可能会引起头痛,因为每天CSS都是一维的,这意味着元素在水平轴或垂直轴上流动。即使是现代的flexbox布局仍然是单向的。对于这样的布局,我们几乎需要好的ol\"HTML表曾经提供的属性:行和列跨度之类的东西可以将单元格向各个方向拉伸。我们还需要现代CSS的好处,它具有所有的响应能力和灵活的方框,这些方框可以增长以填充可用空间。CSS grid将最好的表与最好的灵活方框结合起来。事实上,grid更好,因为它提供了grid-gap属性,可以在单元格之间创建排水沟,同时考虑可用空间。尽管这可能很强大,但我们如何才能在这些排水沟的正中间创建分隔线呢?让我们看看实现这一目标的三种技术。首先,我们将构建一个简化版的报纸设计,它将帮助说明我们将要介绍的三种不同技术的关键。一个看似简单的设计,我们可以说。。如果需要,水平分隔带应涂漆。\"伪\"列是使用网格容器中的伪选择器创建的。Setting up the lines between the columnsLet\"s create a three-column container using display: grid和伪选择器(:before和:after)创建两个填充容器100%高度的列。.frontpage {position: relative;display: grid;/* Three columns */grid-template-columns: 1fr 1fr 1fr;grid-column-gap: 32px;border: 1px solid transparent;border-top: 1px solid #DADCE0;border-bottom: 1px solid #DADCE0;overflow: hidden;}/* Two faux columns */.frontpage:before,.frontpage:after {position: absolute;top: 0;height: 100%;content: \"\";width: calc(33.3% - 4px);}.frontpage:before {left: 0;border-right: 1px solid #DADCE0;}.frontpage:after {right: 0;border-left: 1px solid #DADCE0;}注意:容器的33%不考虑槽宽,因此,您必须进行相应的补偿。这是这样计算的:33% minus (gutter-width divided by (amount of gutters times amount of gutters)) divided by amount of gutters)或者,用实际数字:33% - (32 / (2* 2)) />We could use one pseudo-selector instead:.frontpage {position: relative;display: grid;grid-template-columns: 1fr 1fr 1fr;grid-column-gap: 32px;border: 1px solid transparent;border-top: 1px solid #DADCE0;border-bottom: 1px solid #DADCE0;overflow: hidden;}.frontpage:before {box-sizing: border-box;position: absolute;top: 0;height: 100%;content: \"\";left: calc(33.3% - 5.3px);width: calc(33.3% + 10.7px);border-left: 1px solid #DADCE0;border-right: 1px solid #DADCE0;}注意:当只使用一个伪选择器时,需要进行不同的计算:一个用于定位,宽度为1。宽度计算为:33% plus (amount of gutters times gutter-width) / (amount of gutters times amount of columns),实际数字为:33% + (2 * 32) / (2 *>The position is calculated as:33% minus (amount of gutters times gutter-width) / (amount of gutters times amount of columns) divided by 2)制作网格设计由四个内容块组成。我们将把它们放在容器中,并给它们一个修饰符类以供将来参考,同时确保它们的z-index高于网格的伪选择器。Now let\"s set the background color for the cells (.fp-cell)变为白色。这样,垂直线就不会显示出来。我们还可以将单元格的垂直填充设置为16px,以匹配半个边距。第一个和第二个内容块应具有自己独特的跨距,如设计所示。第一个块一直向下延伸,第二个块横跨第二列和第三列。.fp-cell {position: relative;z-index: 2;padding: 16px 0;background-color: #fff;}/* Span all the way down! */.fp-cell--1 {grid-row: 1 / span 2;}/* Span the second and third columns */.fp-cell--2 {grid-column: 2 / span 2;}垂直线分割器如果您查看设计,只有最后两个单元格需要水平边框。我们可以给\"em\"一个甜美的修饰类。.fp-cell--border-top:before {content: \"\";position: absolute;top: 0;left: -16px;right: -16px;border-top: 1px solid #DADCE0;}负边距是边沟宽度的一半。技术2:使用背景色创建分隔符的另一种方法是利用grid-gap属性。这个解决方案不一定能在单元格之间建立一个\"真实\"的距离,而是在网格的background-color可以穿透的地方留下一些空白。边距宽度指定给网格单元格内的填充。.container {overflow-x: hidden;border-top: 1px solid #DADCE0;border-bottom: 1px solid #DADCE0;}.frontpage {position: relative;display: grid;grid-template-columns: 1fr 1fr 1fr;grid-gap: 1px;margin: 0 -16px;background-color: #DADCE0;}.fp-cell {background-color: #fff;padding: 16px;}.fp-cell--1 {grid-row: 1 / span 2;}.fp-cell--2 {grid-column: 2 / span 2;}.fp-cell--3 {grid-column: 2;}.fp-item {background-color: #efefef;display: flex;align-items: center;justify-content: center;min-height: 200px;height: 100%;}由于所有单元格都有额外的16px水平填充,因此网格需要偏移同样多。包装容器将处理溢出。.container {border-top: 1px solid #DADCE0;border-bottom: 1px solid #DADCE0;overflow-x: hidden;}.frontpage {position: relative;display: grid;grid-template-columns: 1fr 1fr 1fr;grid-gap: 1px;background-color: #DADCE0;margin: 0 -16px;}技术3:创建单元格边框此解决方案将右边框和下边框附加到每个单元格。与上一个示例一样,通过向单元格内容添加填充来模拟grid-gap。这意味着它还需要用一个额外的容器包装。.container {border-top: 1px solid #DADCE0;overflow-x: hidden;}.frontpage {margin: 0 -17px 0 -16px;position: relative;display: grid;grid-template-columns: 1fr 1fr 1fr;}.fp-cell {padding: 16px;background-color: #fff;border-right: 1px solid #DADCE0;border-bottom: 1px solid #DADCE0;}.fp-cell--1 {grid-row: 1 / span 2;}.fp-cell--2 {grid-column: 2 / span 2;}.fp-cell--3 {grid-column: 2;}.fp-item {background-color: #efefef;display: flex;align-items: center;justify-content: center;min-height: 200px;height: 100%;}如上所述,每个单元格的右边和底部都有一个边框。这里的主要技巧是在网格上使用(不对称的)负边距。这是为了补偿单元格的右边框而需要的。.frontpage {margin: 0 -17px 0 -16px;position: relative;display: grid;grid-template-columns: 1fr 1fr 1fr;}结论Occam的剃刀规定最简单的解决方案获胜。在我们的情况下,这是不可能的二号技术。不过,其他解决方案也有很多优点,例如,如果无法访问DOM,那么它们可能会很有用。所有这些技术都会奏效。选择正确的方法取决于您的用例。第一种方法使用实际的***20***属性来创建间隙,但是其他的方法可能更容易一眼就理解…也可能更容易维护

admin_action_{$_REQUEST[‘action’]}

do_action( "admin_action_{$_REQUEST[‘action’]}" )动作钩子::在发送“Action”请求变量时激发。Action Hook: Fires when an ‘action’ request variable is sent.目录锚点:#说明#源码说明(Description)钩子名称的动态部分$_REQUEST['action']引用从GET或POST请求派生的操作。源码(Source)更新版本源码位置使用被使用2.6.0 wp-admin/admin.php:...

日期:2020-09-02 17:44:16 浏览:1127

admin_footer-{$GLOBALS[‘hook_suffix’]}

do_action( "admin_footer-{$GLOBALS[‘hook_suffix’]}", string $hook_suffix )操作挂钩:在默认页脚脚本之后打印脚本或数据。Action Hook: Print scripts or data after the default footer scripts.目录锚点:#说明#参数#源码说明(Description)钩子名的动态部分,$GLOBALS['hook_suffix']引用当前页的全局钩子后缀。参数(Parameters)参数类...

日期:2020-09-02 17:44:20 浏览:1032

customize_save_{$this->id_data[‘base’]}

do_action( "customize_save_{$this->id_data[‘base’]}", WP_Customize_Setting $this )动作钩子::在调用WP_Customize_Setting::save()方法时激发。Action Hook: Fires when the WP_Customize_Setting::save() method is called.目录锚点:#说明#参数#源码说明(Description)钩子名称的动态部分,$this->id_data...

日期:2020-08-15 15:47:24 浏览:775

customize_value_{$this->id_data[‘base’]}

apply_filters( "customize_value_{$this->id_data[‘base’]}", mixed $default )过滤器::过滤未作为主题模式或选项处理的自定义设置值。Filter Hook: Filter a Customize setting value not handled as a theme_mod or option.目录锚点:#说明#参数#源码说明(Description)钩子名称的动态部分,$this->id_date['base'],指的是设置...

日期:2020-08-15 15:47:24 浏览:866

get_comment_author_url

过滤钩子:过滤评论作者的URL。Filter Hook: Filters the comment author’s URL.目录锚点:#源码源码(Source)更新版本源码位置使用被使用 wp-includes/comment-template.php:32610...

日期:2020-08-10 23:06:14 浏览:903

network_admin_edit_{$_GET[‘action’]}

do_action( "network_admin_edit_{$_GET[‘action’]}" )操作挂钩:启动请求的处理程序操作。Action Hook: Fires the requested handler action.目录锚点:#说明#源码说明(Description)钩子名称的动态部分$u GET['action']引用请求的操作的名称。源码(Source)更新版本源码位置使用被使用3.1.0 wp-admin/network/edit.php:3600...

日期:2020-08-02 09:56:09 浏览:848

network_sites_updated_message_{$_GET[‘updated’]}

apply_filters( "network_sites_updated_message_{$_GET[‘updated’]}", string $msg )筛选器挂钩:在网络管理中筛选特定的非默认站点更新消息。Filter Hook: Filters a specific, non-default site-updated message in the Network admin.目录锚点:#说明#参数#源码说明(Description)钩子名称的动态部分$_GET['updated']引用了非默认的...

日期:2020-08-02 09:56:03 浏览:834

pre_wp_is_site_initialized

过滤器::过滤在访问数据库之前是否初始化站点的检查。Filter Hook: Filters the check for whether a site is initialized before the database is accessed.目录锚点:#源码源码(Source)更新版本源码位置使用被使用 wp-includes/ms-site.php:93910...

日期:2020-07-29 10:15:38 浏览:809

WordPress 的SEO 教学:如何在网站中加入关键字(Meta Keywords)与Meta 描述(Meta Description)?

你想在WordPress 中添加关键字和meta 描述吗?关键字和meta 描述使你能够提高网站的SEO。在本文中,我们将向你展示如何在WordPress 中正确添加关键字和meta 描述。为什么要在WordPress 中添加关键字和Meta 描述?关键字和说明让搜寻引擎更了解您的帖子和页面的内容。关键词是人们寻找您发布的内容时,可能会搜索的重要词语或片语。而Meta Description则是对你的页面和文章的简要描述。如果你想要了解更多关于中继标签的资讯,可以参考Google的说明。Meta 关键字和描...

日期:2020-10-03 21:18:25 浏览:1620

谷歌的SEO是什么

SEO (Search Engine Optimization)中文是搜寻引擎最佳化,意思近于「关键字自然排序」、「网站排名优化」。简言之,SEO是以搜索引擎(如Google、Bing)为曝光媒体的行销手法。例如搜寻「wordpress教学」,会看到本站的「WordPress教学:12个课程…」排行Google第一:关键字:wordpress教学、wordpress课程…若搜寻「网站架设」,则会看到另一个网页排名第1:关键字:网站架设、架站…以上两个网页,每月从搜寻引擎导入自然流量,达2万4千:每月「有机搜...

日期:2020-10-30 17:23:57 浏览:1264