I am attempting to create a pattern of two divs, side by side, repeating vertically. One side is to contain an image (which I've done using CSS background image) and the other text. The side which contains the image alternates each row.
The divs use the Bootstrap grid's col-sm-6 class. It looks great on desktop but I'm having trouble getting it to look good on smaller devices.
The issue is that because of the order in which the code is written, when it collapses down to 100% width on mobile it goes:
image
text
text
image
image
text
instead of:
image
text
image
text
image
text
The only workaround I've thought of so far is to have two of each image div, one before and one after the text div, and to hide or display them based on the size of the screen. Not a great solution though. Any thoughts?
put your content like following
<div col-sm-6>Image</div>
<div col-sm-6>text</div>
<div class="clearfix visible-xs-block"></div>
<div col-sm-6>Image</div>
<div col-sm-6>text</div>
<div class="clearfix visible-xs-block"></div>
<div col-sm-6>Image</div>
<div col-sm-6>text</div>
<div class="clearfix visible-xs-block"></div>
This will give you what you want
In the end I put them all in the same order and then went with this:
.campaign-idea:nth-child(odd) {
.image {
float: right;
}
}
Related
I have the following basic layout, in which to show a flash-card - the detail-card:
<div class="col-md-4"></div>
<div id="cardContainer" class="col-md-4 text-center detail-card-container">
#Html.Partial("_DetailCard", cardModel)
</div>
<div class="col-md-4"></div>
I know I could just use col-offset but I have plans for the other two columns.
My vision here was to divide the page into three columns, give the middle one, detail-card-container, class text-center so that the content of that div should be horizontally centered inside it.
Yet when I start up the app, I get a display as follows:
The blue is the available space in the detail-card-container for the 'detail-card, outlined in red. The detail card is fixed width 200, and the available space is about 400+ .This is displaying at the left of its available space, not in the centre as intended. The empty spaces to the left and right of the green in the image are the emptycol-md-4` divs.
What am I doing wrong?
Maybe you could give a specific width, display: block, plus margin-left: auto, margin-right: auto.
Use
<div class="col-md-4" align="center">
I'm trying to model the following design with Bootstrap.
Currently I've found a method to do this using "carousel-caption" class from bootstrap CSS but it doesn't seem to working as expected.
The html looks like this:
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<img src="http://placehold.it/1000x550" alt="test" class="img-responsive">
<div class="carousel-caption">
<h1>Text word1 word2 superlative.</h1>
</div>
</div>
</div>
</div>
You can see an example of on https://jsfiddle.net/3vf5gog4/2/
This produces a single title but the image doesn't stretch and the title is not vertically centered and I can't figure out how I should be adding another title beneath the current carousel title
This is one of those things with bootstrap that can trip you up. So the .container-fluid class has a padding around it and so to the other grid elements so thats causing the issues with the stretch. Vertically centred elements in CSS can be a pain there is one good method I've seen on it but I typically just eye ball the percent and add some precent
I've edited your fiddle to take out the bootstrap padding and centre that text.
https://jsfiddle.net/3vf5gog4/5/
Try this :
.carousel-caption{
postion:absolute;
top : 20%;
}
I have done some digging on SO and have found a a variety of resources regarding printing and bootstrap.css, but I have not seen a solution to this particular problem.
Lets say I have a setup like seen in this Plnkr: http://plnkr.co/edit/7ETXQyEvY7S16JTU9wYB?p=preview
and HTML like this:
<div class="col-xs-6 red">
testing
</div>
<div class="col-xs-6 blue hidden">
123
</div>
The CSS states that during printing the column will be hidden (on my real page the stle is not hidden but hidden-print), which is expected, but is there anyway to now have the col-xs-6 red now take up the empty space left by the hidden blue column.
I know you could override the style col-xs-6 to be width:100%, but that would affect other columns on the page that need to be left at width: 50%.
Has anyone had this problem before, if so how did you address it?
For Bootstrap 4 you need to do a modification from #Lance's answer.
#media print {
.col-print-12 {
max-width: 100%;
flex: 0 0 100%;
}
}
With the same HTML
<div class="col-xs-6 col-print-12 bg-danger">
Red Column is full width for print
</div>
<div class="col-xs-6 hidden-print bg-primary">
Blue Column is hidden for print
</div>
I suggest something like:
#media print {
.col-print-12{
width:100% !important;
}
}
Then your HTML can be:
<div class="col-xs-6 col-print-12 bg-danger">
Red Column is full width for print
</div>
<div class="col-xs-6 hidden-print bg-primary">
Blue Column is hidden for print
</div>
!important is needed to override the regular col widths since at least one set will also apply at print width.
I updated your plunk using xs as a proxy for the print view here to demonstrate the concept. One red column in mobile, Red and Blue columns in tablet or bigger.
Edit: if you want to do it with CSS only you would have to use the flex property. Take a look at this pen. Change display: flex to display: none on any column and see how they stretch to fit the available space (this renders bootstrap useless).
Create a div container inside the bootstrap column and apply visibility: hidden to it. You want to hide without removing it, meaning the browser will still show the space that the element occupies.
It's a good practice not to add your own classes to bootstrap columns but instead create a container inside it so you can apply your classes to.
display: none gets rid of the element entirely and affects the positioning of the other elements that were around it.
I'm using Bootstrap 3.
I have a series of rows with two columns. The first column displays text and the second column has an image. I want to vertically centre the text in the first column relative to the row it's in so it aligns nicely with the adjacent image.
Example HTML:
<div class="container">
<div class="row">
<div class="col-sm-6">
<h2>Some heading</h2>
<p>I want all this text centred relative to the image next door</p>
</div>
<div class="col-sm-6 image">
<img class="img-responsive" src="http://i.imgur.com/cztLHHo.png"/>
</div>
</div>
</div>
Note that I'm using the Bootstrap img-responsive class to correctly resize images for mobile devices.
JSFiddle
What I'm seeing is this:
What I want to achieve is this:
I'm sure this is a commonly performed bit of CSS ninja action but I can't find a good example of it. Can anybody help? I would prefer a CSS solution.
Take a look at this fiddle link
i have used the following property in css
.row
{
display: flex;
align-items: center;
}
Im using the newest twitter bootstrap to construct a responsive grid website. i have three divs across a responsive grid like so:
<div class="row-fluid">
<div class="span4">...</div>
<div class="span4">...</div>
<div class="span4">...</div>
</div>
...and this works as intended via the bootsrap documentation. However I have a separate background color on these divs from the html body background color, and when i drag the browser window to a smaller width to "collapse" the divs to show on top of each other, the gutter space between them disappears (creating a look of one big div versus three separate ones) is there anything i can do to create some gutter space between the divs when the width gets small enough to cause them to stack vertically?
You have a couple options...
(1) You could define a class and apply it to any divs you want to have a bottom margin.
In your application.css (or similar):
.mb10 {margin-bottom:10px;}
In your html page:
<div class="row-fluid">
<div class="span4 mb10">....</div>
<div class="span4 mb10">....</div>
<div class="span4 mb10">....</div>
</div>
OR
(2) You could make sure you wrap your div.span4 content in <p></p> tags.
<div class="row-fluid">
<div class="span4"><p>....</p></div>
<div class="span4"><p>....</p></div>
<div class="span4"><p>....</p></div>
</div>
From the Bootstrap - Typography section:
http://twitter.github.io/bootstrap/base-css.html#typography
In addition,
<p> (paragraphs) receive a bottom margin of half their line-height
(10px by default).