- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有 3 列包含文本(紫色)。每列包含标题(蓝色)、内容(绿色)和链接(黄色)。但是,根据列的不同,文本或多或少会更长。
但是,我希望内容的每个部分都进行某种水平对齐,即每个标题都在同一水平“行”上开始,每个内容都在同一水平“行”上等等......同时,我不希望在移动 View 上出现这种情况,我希望文本没有额外的垂直空间(因为水平对齐在智能手机上没有意义)。
我找不到如何使用 Boostrap 3 解决这个问题。一方面,我可以同步列(简单),但我不知道如何同步水平内容。
<div class="container">
<div class="row">
<div class="col-xs-12 col-sm-4">
<div class="text-center">
<h2>Title</h2>
</div>
<div class="text-justify">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras non
</p>
<p>
<ul class="list-inline center-block text-center">
<li>A</li>
<li>B</li>
<li>C</li>
</ul>
</p>
</div>
</div>
<div class="col-xs-12 col-sm-4">
<div class="text-center">
<h2>Title</h2>
</div>
<div class="text-justify">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras non </p>
<p>
<ul class="list-inline center-block text-center">
<li>A</li>
<li>B</li>
<li>C</li>
</ul>
</p>
</div>
</div>
<div class="col-xs-12 col-sm-4">
<div class="text-center">
<h2>Very long long long long long long long Title</h2>
</div>
<div class="text-justify">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras non </p>
<p>
<ul class="list-inline center-block text-center">
<li>A</li>
<li>B</li>
<li>C</li>
</ul>
</p>
</div>
</div>
</div>
</div>
最佳答案
如果你愿意使用一些js,你可以这样做,就像这样:
这里有一个 JSFiddle 示例:http://jsfiddle.net/Yandy_Viera/wk9esdgq/
function setHeight(objSize){
var $window = $(window);
var header = $('.header');
var content = $('.wrapper-content');
if($window.width() < 768){ /*to avoid extra vertical spaces on mobile view*/
header.css('height', 'auto');
content.css('height', 'auto');
return;
}
if($window.width() > objSize.windowCurrentWidth){ /*resetting the max height when the window is expanding to allow the heigth decrease*/
objSize.headerMaxHeight = 0;
objSize.contentMaxHeight = 0;
}
header.each(function (index)
{
header.css('height', 'auto'); /*setting to auto to allow the elemelent's height change*/
if($(this).outerHeight() > objSize.headerMaxHeight){ /*setting "headerMaxHeight" equal to max height of header elements*/
objSize.headerMaxHeight = $(this).outerHeight();
}
});
content.each(function (index)
{
content.css('height', 'auto');
if($(this).outerHeight() > objSize.contentMaxHeight){
objSize.contentMaxHeight = $(this).outerHeight();
}
});
header.css('height', objSize.headerMaxHeight); /*applying the resulting max height to the element*/
content.css('height', objSize.contentMaxHeight);
objSize.windowCurrentWidth = $(window).width(); /*updating the current width of the window*/
}
$(document).ready(function() {
var objSize = {
headerMaxHeight : 0,
contentMaxHeight : 0,
windowCurrentWidth : $(window).width()
}
setHeight(objSize);
$(window).resize(function(){
setHeight(objSize);
})
})
.wrapper-content, .header, .link{
margin-bottom: 10px;
}
.header p{
background: deepskyblue;
}
.content{
background: green;
}
#content-1{
height: 150px;
}
#content-2{
height: 250px;
}
#content-3{
height: 100px;
}
.link{
height: 150px;
background: yellow;
}
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="row">
<div class="col-xs-12 col-sm-4 blue">
<div class="header">
<p>fajdklfa kajsdf lakjdfadlsfk jalfdsj lasf asd asdf as</p>
</div>
<div class="wrapper-content">
<div id="content-1" class="content"></div>
</div>
<div class="link"></div>
</div>
<div class="col-xs-12 col-sm-4">
<div class="header">
<p>fajdklfa kajsdf lakjdfadlsfk jalfdsj lasf asdadlsfk jalfdsj lasf asd asdf adlsfk jalfdsj lasf asd asdf adlsfk jalfdsj lasf asd asdf adlsfk jalfdsj lasf asd asdf adlsfk jalfdsj lasf asd asdf adlsfk jalfdsj lasf asd asdf adlsfk jalfdsj lasf asd asdf adlsfk jalfdsj lasf asd asdf adlsfk jalfdsj lasf asd asdf adlsfk jalfdsj lasf asd asdf adlsfk jalfdsj lasf asd asdf asdf as</p>
</div>
<div class="wrapper-content">
<div id="content-2" class="content"></div>
</div>
<div class="link"></div>
</div>
<div class="col-xs-12 col-sm-4">
<div class="header">
<p>fajdklfa kajsdf lakjdfadlsfk jalfdsj lasf asdadlsfk jalfdsj lasf asd asdf adlsfk jalfdsj lasf asd asdf adlsfk jalfdsj lasf asd asdf adlsfk jalfdsj lasf asd asdf adlsfk jalfdsj lasf asd asdf asdf as</p>
</div>
<div class="wrapper-content">
<div id="content-3" class="content"></div>
</div>
<div class="link"></div>
</div>
</div>
如果你只想使用纯CSS恐怕你做不到(当然更不用说你可以为元素设置固定高度),至少不能同时使用两者(对齐和响应式)时间 。因为html中的方式是有效的,当你有2个元素a
,b
到2个不同的容器中时,a
的高度不会影响a
的高度b
,因此它们下面的元素不会对齐,最好的办法是使用像这样的 flexbox :
.col-sm-4{
display: flex;
flex-direction: column;
}
.wrapper{
min-height: 415px;
display: flex;
flex-direction: column;
}
.content-wrap, p{
flex-grow: 1;
}
p{
margin-bottom: 30px;
background: deepskyblue;
}
.content{
background: green;
}
#content-1{
height: 150px;
}
#content-2{
height: 250px;
}
#content-3{
height: 100px;
}
.link{
height: 150px;
background: yellow;
}
@media (min-width: 768px) {
.row{
display: flex;
margin: 0;
}
}
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row">
<div class="col-xs-12 col-sm-4">
<p>fajdklfa kajsdf lakjdfadlsfk jalfdsj lasf asd asdf as</p>
<div class="wrapper">
<div class="content-wrap">
<div id="content-1" class="content"></div>
</div>
<div class="link"></div>
</div>
</div>
<div class="col-xs-12 col-sm-4">
<p>fajdklfa kajsdf lakjdfadlsfk jalfdsj lasf asdadlsfk jalfdsj lasf asd asdf adlsfk jalfdsj lasf asd asdf adlsfk jalfdsj lasf asd asdf adlsfk jalfdsj lasf asd asdf adlsfk jalfdsj lasf asd asdf adlsfk jalfdsj lasf asd asdf adlsfk jalfdsj lasf asd asdf adlsfk jalfdsj lasf asd asdf adlsfk jalfdsj lasf asd asdf adlsfk jalfdsj lasf asd asdf adlsfk jalfdsj lasf asd asdf asdf as</p>
<div class="wrapper">
<div class="content-wrap">
<div id="content-2" class="content"></div>
</div>
<div class="link"></div>
</div>
</div>
<div class="col-xs-12 col-sm-4">
<p>fajdklfa kajsdf lakjdfadlsfk jalfdsj lasf asdadlsfk jalfdsj lasf asd asdf adlsfk jalfdsj lasf asd asdf adlsfk jalfdsj lasf asd asdf adlsfk jalfdsj lasf asd asdf adlsfk jalfdsj lasf asd asdf asdf as</p>
<div class="wrapper">
<div class="content-wrap">
<div id="content-3" class="content"></div>
</div>
<div class="link"></div>
</div>
</div>
</div>
但是无论如何,您必须为 .wrapper
、.link
等多个元素设置固定高度,如果您知道高度,那么您很幸运,但请记住内容的高度可能会根据分辨率而变化。
无论如何我真的推荐你使用js来实现你想要的。
关于javascript - Bootstrap : Horizontal text alignement between columns,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31895653/
一个屏幕上有多个横向的Recyclerview。我想在第一个水平 Recyclerview 的第一个项目上执行 espresso click 事件。请告诉我如何实现它。 onView(withId(
我目前正在为一个网站开发移动样式表,但我遇到了一个我无法解释的奇怪问题: 即使我的样式表中不再有“宽度”定义,Android 浏览器会在右侧留下大量空白区域,导致出现滚动条。 我不知道是什么原因导致的
我有一个由 graphviz 工具制作的无向图(现在我正在使用 sfdp ): digraph structs { node [shape=Mrecord, URL="index_ne
关闭。这个问题需要details or clarity .它目前不接受答案。 想改善这个问题吗?通过 editing this post 添加详细信息并澄清问题. 8年前关闭。 Improve thi
假设我有一行单元格,其中包含以下值: B2: "banana" C2: "orange" D2: "apple" 我把这个范围变成一个二维数组。我的主要代码在Word文档中: dim MySheet
我正在创建一个基于位置的提醒,EKReminder。 对于坐标,我使用 CLGeocoder 将地址转换为 CLLocation。 就提醒本身而言,我认为有两个因素决定了提醒将触发的“区域”(半径/圆
我有一个问题可以用一个很像 SO 的系统来模拟:帖子和标签。要获得我的帖子,我可能会这样做: SELECT title, body, author FROM posts WHERE id = ? 然后
我希望将结果生成到水平联合中。我能够组合在一起并生成结果。但是,我需要以预期结果格式显示结果。 SQL (SELECT kpa_id AS 'KPA', SUM(weightage) AS '
我正在研究 CMS 模板,并尝试找出这是否可行。我在网上找不到任何东西,也许我只是使用了错误的关键字。 给出这个模型: http://img833.imageshack.us/img833/4979/
我有一个 LTR 方向的 Bootstrap v4.0.0 模板,我想将整个模板更改为 RTL 方向,我使用了以下这些方法: body { direction:rtl; } html { dire
嗯,几秒钟前还好,但现在当我指向“水平”时,它总是说“水平无法解析或不是一个字段”。我已经删除了旧项目并创建了一个新项目,但仍然遇到这个问题。有人能告诉我发生了什么事吗?谢谢。我正在使用 eclips
我正在寻找一种仅在 html 表格 View 中水平或垂直滚动同时保持始终可见的标题和行的方法。最好我想要类似于 this 的东西但在没有 ember 或 coffeescript 的纯 Java
每当我需要定位某些东西使其垂直和/或水平时,我通常会求助于 flexbox,如果那不是解决方案,我会使用 position: absolute 和 top:50%; 和/或 left:50%; 与 t
我想创建一个从右向左滚动然后从左侧消失并再次从右侧重新出现的 TextView。我可以使用动画??谢谢 最佳答案 我相信您希望您的 TextView 成为选取框。如果是这样,我就是这样做的: 在 XM
我只需要在屏幕上平行放置两个按钮(每个按钮的宽度为 50dp)。第一个应该有 margin left 10dp 并且放置没问题。 但是第二个按钮应该放置在屏幕中,并在中间(水平)向左留出 30dp 的
新的Bootstrap 三个文档explains the grid behaviour作为超小型设备的“始终水平”。这是什么意思?在小型设备上,所有列肯定会垂直堆叠在一起吗?在这里让我失望的是我(缺乏
我需要一些帮助来隐藏我的水平滚动条并仍然能够滚动。我使用过 webkit,但在 IE 和 firefox 中不起作用。我看到很多关于垂直滚动条的帮助,但不适用于水平滚动条。有帮助吗? 更新:我创建了一
为什么不支持水平滚动?
在 examples page当您搜索(CTRL+F)图片库并单击第一张图片时,您可以使用下一个/上一个箭头浏览此图片库。它们之间的动画是垂直的——图像垂直飞行。如何让它们水平飞行? 在我找到的帮助中
我在移动网站上使用 Owl Carousel。 当用户水平滚动然后停止时,内容立即停止移动(或停止后不久)。 是否可以添加一些惯性? 我尝试了文档中公开的不同选项,例如 smartSpeed , fl
我是一名优秀的程序员,十分优秀!