twitter-bootstrap 使用 bootstrap 3 的文章推/拉对齐
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19046787/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Article push/pull alignment using bootstrap 3
提问by alienlebarge
I'm using bootstrap 3 and I try to have a specific grid alignment for article on desktop.
我正在使用引导程序 3,并且我尝试为桌面上的文章设置特定的网格对齐方式。
On mobile I want to order content of the article like that :
在移动设备上,我想像这样订购文章的内容:
- Title
- Image
- Content
- 标题
- 图片
- 内容
On desktop, I want the image on the left and the title and content on the right.
在桌面上,我想要左边的图像和右边的标题和内容。
Here is my code
这是我的代码
<article class="row">
<header class="col-md-8 col-md-push-4">
<a href="#">
<h2>Title</h2>
</a>
</header>
<div class="col-md-4 col-md-pull-8">
<figure>
<a class="thumbnail" href="#">
<img src="..." alt="4x3 Image" class="img-responsive">
<figcaption>Caption</figcaption>
</a>
</figure>
</div>
<div class="col-md-8 col-md-push-4">
<p>Content</p>
</div>
</article>
But with this code, the content is on the right but under the image.
但是使用此代码,内容在右侧但在图像下方。
Is there a simple way to get what I want ?
有没有一种简单的方法可以得到我想要的东西?
采纳答案by Bass Jobsen
Based on Possible to achieve this Mobile/Desktop layout using Bootstrap? (or other grid)
基于是否可以使用 Bootstrap 实现此移动/桌面布局?(或其他网格)
css:
css:
.floatright{float:right;}
@media (max-width: 768px)
{
.floatright{float:none;}
}
html:
html:
<div class="container" style="background-color:green">
<article class="row">
<header class="col-md-8 floatright">
<a href="#">
<h2>Title</h2>
</a>
</header>
<div class="col-md-4">
<figure>
<a class="thumbnail" href="#">
<img src="..." alt="4x3 Image" class="img-responsive">
<figcaption>Caption</figcaption>
</a>
</figure>
</div>
<div class="col-md-8 floatright">
<p>Content</p>
</div>
</article>
</div>
回答by juicided
it's your columns class:
这是你的列类:
md:
4 (image) - 8 (title) => 1st row (max 12 columns)
8 (content) => new row
md:4(图像)- 8(标题)=> 第一行(最多 12 列)
8(内容)=> 新行
that's will make a new row, the 2nd row placed below image/title column
so you must use this columns setting (using hidden class) like this:
这将创建一个新行,第二行位于图像/标题列下方,
因此您必须使用此列设置(使用隐藏类),如下所示:
md:
2 (image) - 5 (title) - 5 (hidden-xs hidden-sm)
5 (content)
md: 2 (image) - 5 (title) - 5 (hidden-xs hidden-sm)
5 (content)
just try this code:
试试这个代码:
CSS:
CSS:
<style>
.col-md-2{
height: 300px;
background-color: blue;
color: white;
border: 2px solid red;
}
.col-md-4{
height: 100px;
}
.col-md-5{
height: 100px;
background-color: red;
color: white;
border: 2px solid black;
}
</style>
HTML:
HTML:
<article class="row">
<header class="col-md-5 col-md-push-2">
<a href="#">
<h2>Title</h2>
</a>
</header>
<div class="col-md-2 col-md-pull-5">
<figure>
<a class="thumbnail" href="#">
<img src="" alt="4x3 Image" class="img-responsive">
<figcaption>Caption</figcaption>
</a>
</figure>
</div>
<div class="hidden-xs hidden-sm">
<div class="col-md-4"></div>
</div>
<div class="col-md-5 col-md-pull-5">
<p>Content</p>
</div>
</article>
maybe it's not solve the problem. but you can use this trick.
sorry for my bad english
也许它不能解决问题。但你可以使用这个技巧。
对不起,我的英语不好
回答by Mandeep
Use a bigger div with col-md-8 class and place title and text inside it and use bootstrap's col-md-12 class on both of them to stack over one another
使用带有 col-md-8 类的更大的 div 并将标题和文本放入其中,并在它们两个上使用引导程序的 col-md-12 类来相互堆叠
回答by alienlebarge
Here's how fix the problem
以下是解决问题的方法
<article class="row">
<header class="col-md-8 pull-right">
<a href="#">
<h2>Title</h2>
</a>
</header>
<div class="col-md-4 pull-left">
<figure>
<a class="thumbnail" href="#">
<img src="..." alt="4x3 Image" class="img-responsive">
<figcaption>...</figcaption>
</a>
</figure> </div>
<div class="col-md-8 pull-right">
<p>content</p>
</div>
</article>


