I'm using Bootstrap 3.0 with below requirements:
Each thumbnail image has fixed known width, let say 200px in this case. There could be multiple columns (if the screen is large, it could have 5-6 columns as needed).
This whole page must be fluid width
The container (.center in this case) must be center of the page
Then within the container (.grid in this case), the thumbnails themselves must be left aligned. For example, if the page fits 3 images per row but the last row only has 2 images, these 2 images must be left aligned.
I am OK to change HTML structure but no JS. Width of page and whole container is unknown.
Example 1: The number of columns is 4 in this case. The images (blue) is left aligned within the gray container which is center of the page (yellow).
Example 2: When the screen width is smaller, the images wrapped down (therefore 3 columns in this case). But the image container is still center and all images are left aligned.
My current code only does left align but the .center class literally has no effect. Somehow I need that .center class (red border) to have the width of the images inside (not full width) and then centered itself.
HTML:
<div class='col-md-12'>
<div class='center'>
<div class='grid'>
<div class='thumbnail'>
<img src='http://placehold.it/200x200' />
<div class='caption'>
<h3>Donec id elit non mi porta gravida at eget metus</h3>
<p>Fusce dapibus tellus ac cursus commodo</p>
</div>
</div>
<div class='thumbnail'>
<img src='http://placehold.it/200x200' />
<div class='caption'>
<h3>Donec id elit non mi porta gravida at eget metus</h3>
<p>Fusce dapibus tellus ac cursus commodo</p>
</div>
</div>
<div class='thumbnail'>
<img src='http://placehold.it/200x200' />
<div class='caption'>
<h3>Donec id elit non mi porta gravida at eget metus</h3>
<p>Fusce dapibus tellus ac cursus commodo</p>
</div>
</div>
<div class='thumbnail'>
<img src='http://placehold.it/200x200' />
<div class='caption'>
<h3>Donec id elit non mi porta gravida at eget metus</h3>
<p>Fusce dapibus tellus ac cursus commodo</p>
</div>
</div>
<div class='thumbnail'>
<img src='http://placehold.it/200x200' />
<div class='caption'>
<h3>Donec id elit non mi porta gravida at eget metus</h3>
<p>Fusce dapibus tellus ac cursus commodo</p>
</div>
</div>
<div class='thumbnail'>
<img src='http://placehold.it/200x200' />
<div class='caption'>
<h3>Donec id elit non mi porta gravida at eget metus</h3>
<p>Fusce dapibus tellus ac cursus commodo</p>
</div>
</div>
<div class='thumbnail'>
<img src='http://placehold.it/200x200' />
<div class='caption'>
<h3>Donec id elit non mi porta gravida at eget metus</h3>
<p>Fusce dapibus tellus ac cursus commodo</p>
</div>
</div>
</div>
</div>
</div>
CSS:
.col-md-12 {
background: yellow;
}
.center {
margin-left: auto;
margin-right: auto;
border: 1px solid red;
}
.grid {
text-align: left;
}
.thumbnail {
display: inline-block;
width: 215px;
max-width: none;
}
Link: http://jsfiddle.net/qhoc/Rp838/
Any help?
UPDATE 1:
Followed Matt's advise to "Wrap the whole thing in a .container". Still didn't work as you see the red border box is not center of the page.
http://jsfiddle.net/qhoc/Rp838/1/
finally solved it after the entire morning of going through stuff.
here is the jsfiddle for it.
http://jsfiddle.net/Rp838/9/
.menu {
display: block;
height: 100%;
max-width: 1000px;
margin-left: auto;
margin-right: auto;
text-align: center;
/*flex-direction: row;
flex-wrap: wrap;
justify-content: space-around;*/
}
.menuItem {
display: inline-block;
position: relative;
margin: 0 5px 20px 5px;
max-width: 320px;
}
.menuItem img {
max-width: 100%;
}
.menuItem h2 {
position: absolute;
bottom: 0;
left: 0;
width: 100%;
margin: 0;
text-align: center;
color: white;
font: bold 1.5em/2em Helvetica, Sans-Serif;
background: rgb(0, 0, 0);
/* fallback color */
background: rgba(0, 0, 0, 0.7);
}
.menuItem h3 {
position: absolute;
bottom: 0;
left: 0;
width: 100%;
margin: 0;
text-align: center;
color: white;
font: bold 1em/1.5em Helvetica, Sans-Serif;
background: rgb(0, 0, 0);
/* fallback color */
background: rgba(0, 0, 0, 0.7);
}
.menu li {
list-style: none;
}
.menu a {
font-weight: normal;
text-decoration: none;
}
.menu a:hover {
text-decoration: underline;
}
.menu a:active {
text-decoration: underline;
}
<div class="menu">
<div class="menuItem">
<a href="history.html"><img src="https://placeholdit.imgix.net/~text?txtsize=19&txt=200%C3%97200&w=200&h=200" alt="History" />
<h2>History</h2>
</a>
</div>
<div class="menuItem">
<a href="photographs.html"><img src="https://placeholdit.imgix.net/~text?txtsize=19&txt=200%C3%97200&w=200&h=200" alt="Photographs" />
<h2>Photographs</h2>
</a>
</div>
<div class="menuItem">
<a href="videos.html"><img src="https://placeholdit.imgix.net/~text?txtsize=19&txt=200%C3%97200&w=200&h=200" alt="Videos" />
<h2>Videos</h2>
</a>
</div>
<div class="menuItem">
<a href="documents.html"><img src="https://placeholdit.imgix.net/~text?txtsize=19&txt=200%C3%97200&w=200&h=200" alt="Documents" />
<h2>Documents</h2>
</a>
</div>
<div class="menuItem">
<a href="maps.html"><img src="https://placeholdit.imgix.net/~text?txtsize=19&txt=200%C3%97200&w=200&h=200" alt="Maps" />
<h2>Maps</h2>
</a>
</div>
<div class="menuItem">
<a href="biographies.html"><img src="https://placeholdit.imgix.net/~text?txtsize=19&txt=200%C3%97200&w=200&h=200" alt="Biographies" />
<h2>Biographies</h2>
</a>
</div>
</div>
ok here we go, you need to restructure your markup to follow bootstrap standards
CSS
.container {
background: yellow;
}
.thumbnail {
width: 200px;
display: inline-block;
}
HTML
<div class="container">
<div class="thumbnail">
<img src="http://placekitten.com/200/200" width="200" height="200" alt="" />
<div class="caption">
<h3>Thumbnail label</h3>
<p>blah blah blah blah blah</p>
</div>
</div>
<div class="thumbnail">
<img src="http://placekitten.com/200/200" width="200" height="200" alt="" />
<div class="caption">
<h3>Thumbnail label</h3>
<p>blah blah blah blah blah</p>
</div>
</div>
<div class="thumbnail">
<img src="http://placekitten.com/200/200" width="200" height="200" alt="" />
<div class="caption">
<h3>Thumbnail label</h3>
<p>blah blah blah blah blah</p>
</div>
</div>
<div class="thumbnail">
<img src="http://placekitten.com/200/200" width="200" height="200" alt="" />
<div class="caption">
<h3>Thumbnail label</h3>
<p>blah blah blah blah blah</p>
</div>
</div>
<div class="thumbnail">
<img src="http://placekitten.com/200/200" width="200" height="200" alt="" />
<div class="caption">
<h3>Thumbnail label</h3>
<p>blah blah blah blah blah</p>
</div>
</div>
<div class="thumbnail">
<img src="http://placekitten.com/200/200" width="200" height="200" alt="" />
<div class="caption">
<h3>Thumbnail label</h3>
<p>blah blah blah blah blah</p>
</div>
</div>
</div>
Here's a fiddle if you want to see it in action. I made the images responsive so make sure you stretch out the window far enough. On a smaller viewport the image will stretch to fit.
Related
I'm a rookie "programing" and asking for help here in stackoverflow.
I'm having a little problem trying to fit an image inside my grid.
For example, when I have an image with a specific size it works but when I have an image a bit larger or in a different format (16:9 instead of 9:16) it show the image not in the full size but not cut it to fit the grid .
What I Want
What I Get
I use the same HTML code and CSS for both grids the only thing that changes it's the image. I'm using Bootstrap with some CSS.
The CSS
.grid {
position: relative;
clear: both;
margin: 0 auto;
max-width: 1000px;
list-style: none;
text-align: center;
}
.grid figure {
position: relative;
overflow: hidden;
margin: 10px 0;
height: auto;
text-align: center;
cursor: pointer;
}
.grid figure img {
position: relative;
display: block;
min-height: 100%;
width: 100%;
opacity: 0.8;
}
<div class="gallery">
<div class="container">
<div class="gallery-grids">
<div class="col-md-4 gallery-grid">
<div class="grid">
<figure class="effect-roxy">
<a class="example-image-link" href="/images/fotos/gal1.jpg" data-lightbox="example-set" data-title="In lacinia pharetra ipsum vel dapibus. Ut vitae tristique nisi, mattis pellentesque elit. Proin mollis sed nisi ac sodales.">
<img src="/images/fotos/gal1.jpg" alt="" />
<figcaption>
<h3>Maecenas <span>lacus</span></h3>
<p> Aenean fermentum nisl ac imperdiet commodo</p>
</figcaption>
</a>
</figure>
</div>
</div>
<div class="clearfix"> </div>
</div>
</div>
</div>
I believe you have 2 options, one is to add images as backround and use cover, or if images comes from img tag then use
img {
object-fit: cover;
object-position: center;
}
Note, this does not work in old ie version
You can try to create a trim class in CSS like this
div.trim {
max-height:292.2px;
max-width: 350px;
overflow: hidden;
}
then add a new out of the image div to lock it
<div class="gallery">
<div class="container">
<div class="gallery-grids">
<div class="col-md-4 gallery-grid">
<div class="grid">
<figure class="effect-roxy">
<div class="trim" >
<a class="example-image-link" href="{$product.image}" data-lightbox="example-set" data-title="">
<img src="{$product.image}" alt="" />
<!--<figcaption>
<h3>Maecenas <span>lacus</span></h3>
<p> Aenean fermentum nisl ac imperdiet commodo</p>-->
</figcaption>
</a></div>
</figure>
</div>
</div>
<div class="clearfix"> </div>
</div>
</div>
</div>
I am currently making a carousel of images. (Carousel is based on a library, not in the scope of this question as i also cannot get it to work outside the carousel).
What i am trying to do is the following: I have a div and within that div i have an image and a caption (just a line of text or 2). I want the image above the caption and as large as possible (taking up all the space the caption does not take up). But the image keeps exceeding the parent div's height. It is never contained in the parent div. And if it is, it loses its ratio (keeps the same width but height is contained which gives a weird result obviously).
I tried a lot with flexbox like this:
<div class="container"> // <---- this wrapper need a specific height depending on screen size.
<img src="/images/thing.png" class="img" alt="pict">
<div class="caption">
<span>Text</span>
</div>
</div>
and the CSS:
.container {
height: 800px;
}
.img {
width: auto;
height: 100%; // this fills the container with the image but i wont see the caption anymore.
// also tried giving this one flex (NOT in combination with above. Just showing all i tried)
flex: 1 1 0%;
}
.caption {
flex: 1 1 0%; // Or 1 1 auto; no difference
}
How do i go about this? Maybe it is just me struggling with flexbox. Maybe i am approaching this wrongly. Any help/tips is appreciated!
/* Horizontal flex: rows
=====================
*/
.row {
display: flex;
}
.item {
flex: 1 1 30%;
padding-left: 1.5rem;
}
.item:first-child {
padding-left: 0;
}
/* Vertical flex: items
===================
*/
.item {
display: flex;
flex-direction: column;
}
.item-heading {
flex: 1;
}
/* Third flex: item heading
========================
*/
.item-heading {
display: flex;
justify-content: center;
flex-direction: column;
}
/* Not so important CSS - base styles:
===================================
*/
body {
margin: 2rem;
}
img {
max-width: 100%;
height: auto;
}
h2,
p {
margin: 0;
padding: 0;
}
.row {
margin-bottom: 1.5rem;
}
.item-heading {
padding: 1rem;
font-size: 1rem;
background: yellow;
text-align: center;
}
.meta {
color: #666;
margin-bottom: 3rem;
}
.meta p {
margin-bottom: .5rem;
}
<div class="meta">
<h1>
Image gallery with a vertically centered captions
</h1>
<p>
Yellow headings we want both vertical and horizontal centered.
</p>
<p>
There are three nested flexbox containers – row, item and item heading.
</p>
</div>
<div class="row">
<div class="item">
<p class="item-image">
<img src="https://parosrentcar.com/wp-content/uploads/2018/05/kawasaki-250-600-200.jpg" alt="Image">
</p>
<h2 class="item-heading">
Lorem ipsum dolor sit amet
</h2>
</div>
<div class="item">
<p class="item-image">
<img src="https://parosrentcar.com/wp-content/uploads/2018/05/kawasaki-250-600-200.jpg" alt="Image">
</p>
<h2 class="item-heading">
Proin pede metus, vulputate nec, fermentum fringilla, vehicula vitae, justo
</h2>
</div>
<div class="item">
<p class="item-image">
<img src="https://parosrentcar.com/wp-content/uploads/2018/05/kawasaki-250-600-200.jpg" alt="Image">
</p>
<h2 class="item-heading">
Consectetuer adipiscing elit
</h2>
</div>
</div>
<div class="row">
<div class="item">
<p class="item-image">
<img src="https://parosrentcar.com/wp-content/uploads/2018/05/kawasaki-250-600-200.jpg" alt="Image">
</p>
<h2 class="item-heading">
Nunc dapibus tortor vel mi dapibus sollicitudin
</h2>
</div>
<div class="item">
<p class="item-image">
<img src="https://parosrentcar.com/wp-content/uploads/2018/05/kawasaki-250-600-200.jpg" alt="Image">
</p>
<h2 class="item-heading">
Mauris elementum mauris vitae tortor
</h2>
</div>
<div class="item">
<p class="item-image">
<img src="https://parosrentcar.com/wp-content/uploads/2018/05/kawasaki-250-600-200.jpg" alt="Image">
</p>
<h2 class="item-heading">
Aliquam ornare wisi eu metus
</h2>
</div>
</div>
codepen : Link
i hope this help you
On my website file I'm trying to display a series of images on the left side of the sight, and have text information on the images stick to the top of the page on the right side. I've tried sticky-top, dataspy="affix", and multiple other things but no dice.
Here is an example of what I mean:
http://imgur.com/T8Vo0JC
<div class="container">
<!-- Example row of columns -->
<div class="row">
<div class="col-md-6 col-sm-9">
<img id="constructedimage" src="images/small1.jpg">
</div>
<div class="col-md-6 col-sm-9">
<p class="pstylefooter">Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac </p>
</div>
</div>
</div>
<div class="container">
<!-- Example row of columns -->
<div class="row">
<div class="col-md-6 col-sm-9">
<p class="pstyle">PROCESS WORK</p>
<img id="constructedimage" src="images/small1.jpg">
</div>
</div>
</div>
You can use position: sticky
* {margin:0;padding:0;}
body {
line-height: 1;
}
.sticky {
position: sticky;
top: 0;
background: rgba(255,255,255,0.5);
margin-left: 50%;
padding-left: 1em;
}
div {
margin: 0 0 2em;
}
img {
max-width: 50%;
}
<div>
<p class="sticky">text</p>
<img id="constructedimage" src="https://previews.123rf.com/images/farang/farang1201/farang120100040/11875191-Amazing-sunset-scene-Long-exposure-shot-vertical-panoramic-composition-Stock-Photo.jpg">
</div>
<div>
<p class="sticky">more text</p>
<img id="constructedimage" src="https://previews.123rf.com/images/farang/farang1201/farang120100040/11875191-Amazing-sunset-scene-Long-exposure-shot-vertical-panoramic-composition-Stock-Photo.jpg">
</div>
I have 4 columns in a row and I cannot get the row centered. It's so weird...
If you look at the pic at the bottom, you can see the row is not centered by looking at the vertical border under the "most read" blue square.
html file:
<div class="block-section">
<div class="sm-section-wrapper">
<div class="row">
<div class="sm-preview-title">
MOST READ
</div>
</div>
<div class="row">
<div class="col-3">
<div class="sm-preview-wrapper">
<h3 class="preview-sm">
hello world
</h3>
<h2 class="preview-sm">
Vestibulum id ligula porta felis euismod semper.
</h2>
</div>
</div>
<div class="col-3">
<div class="sm-preview-wrapper">
<h3 class="preview-sm">
hello world
</h3>
<h2 class="preview-sm">
Vestibulum id ligula porta felis euismod semper.
</h2>
</div>
</div>
<div class="col-3">
<div class="sm-preview-wrapper">
<h3 class="preview-sm">
hello world
</h3>
<h2 class="preview-sm">
Vestibulum id ligula porta felis euismod semper.
</h2>
</div>
</div>
<div class="col-3">
<div class="sm-preview-wrapper">
<h3 class="preview-sm">
hello world
</h3>
<h2 class="preview-sm">
Vestibulum id ligula porta felis euismod semper.
</h2>
</div>
</div>
</div>
</div>
</div>
and here is my scss file:
.sm-preview-wrapper{
text-align: center;
border-right: 1px solid $light-gray;
padding: 0 35px;
}
.sm-section-wrapper{
#include clearfix();
.col-3{
margin: 0;
&:last-child{
.sm-preview-wrapper{
border-right: none;
}
}
}
padding-top: 50px;
padding-bottom: 36px;
.sm-preview-title{
padding-top: 6px;
text-align: center;
height: 30px;
width: 165px;
margin: 0 auto;
background: $blue;
font-family: $montserrat;
font-weight: bold;
color: white;
font-size: 14px;
}
}
Check out this fiddle: http://jsfiddle.net/9v98r58s/
You are using the border for .sm-preview-wrapper and not its parent .col-sm-3 which has a padding of 15px.
A solution is to use :after for the border
.sm-preview-wrapper:after{
position:absolute;
right:-15px;
width:1px;
top:0;
bottom:0;
content:'';
background:red;
}
I had to add a percentage margin to the first and last child to take up the entire width and center it.
I'm trying to align a figure caption centered and underneath the Featurette images in Twitter Bootstrap's Carousel Template:
http://getbootstrap.com/2.3.2/examples/carousel.html
Does anyone know how this can be done and have it still work responsively? I tried adding this HTML:
<figure>
<img class="featurette-image pull-right image-responsive" src="../images/file.jpg">
<figcaption>Caption here</figcaption>
</figure>
and this CSS:
figure {
display:inline-block;
margin:10px;
vertical-align:top;
}
figure img {
display:block;
margin:0 auto;
}
figcaption {
display:block;
padding:8px;
}
...to the template's existing code but that wasn't even close. Is there a simple solution to this that works within the Carousel Template's HTML/CSS?
This is the general featurette section HTML:
<div class="featurette">
<a href="#" target="_blank">
<figure>
<img class="featurette-image pull-right image-responsive" data-toggle="tooltip" title="title" src="../images/image.jpg">
<figcaption>test</figcaption>
</figure>
</a>
<h2 class="featurette-heading">Text: <span class="muted">Text</span></h2>
<p class="lead">Some text.</p>
</div>
A centered caption under the three large browser icon images to be specific!
http://getbootstrap.com/2.3.2/examples/carousel.html
add text-align: center
<figure>
<img src="http://24.media.tumblr.com/5b3863c2aa84715bec39a06b7b4fa63b/tumblr_mytjrmq67H1rnq2uxo5_400.png" />
<figcaption>Caption here</figcaption>
</figure>
figure {
display:inline-block;
margin:10px;
vertical-align:top;
text-align: center ;
}
JSFIDDLE DEMO
CSS UPDATED:
.carousel-caption {
background-color: transparent;
position: static;
max-width: 550px;
padding: 0 20px;
margin-top: 200px;
text-align: center;
margin: 200px auto;
}
this is your solution have fun!
<div class="featurette">
<figure class="row">
<img class="featurette-image pull-right" src="http://getbootstrap.com/2.3.2/assets/img/examples/browser-icon-chrome.png">
<figcaption></figcaption>
</figure>
<h2 class="featurette-heading text-center">First featurette headling. <span class="muted">It'll blow your mind.</span></h2>
<p class="lead text-center">Donec ullamcorper nulla non metus auctor fringilla. Vestibulum id ligula porta felis euismod semper. Praesent commodo cursus magna, vel scelerisque nisl consectetur. Fusce dapibus, tellus ac cursus commodo.</p>
</div>
JSFIDDLE DEMO SMALL SCREEN
JSFIDDLE FULL SCREEN