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>
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
Using Twitter-Bootstrap, I have a section of a page that includes a sidebar (which does not take up the whole page, just spans down to the bottom of this section). I have several sections to the right of the sidebar, each of which contain an image on one side, some text on the other, and require a bottom-border.
I'm having trouble with the bottom-border. Since each section is contained in a div, and everything's floated using Bootstrap columns, the divs are 0 height and the borders all float to the top.
EDITED for clarification: I need two distinct columns in this section - a left-hand one (spanning 3 columns) that contains only the sidebar (and takes up the 3 columns all the way to the bottom, leaving blank space after the list), and one (spanning the remaining 9 columns) that contains the story-sections but that stays on the right-hand side of the page.
EDITED to include image (grey lines are included for reference and will not show up on the page, black lines are the borders I'm trying to apply)
Attempted solutions:
Bottom-border on individual elements: I need one solid line across the bottom of each section, so I can't apply bottom-border to both the image and the text.
Clearfix: Since I have this sidebar, I can't use a clearfix, because it pushes everything down past the sidebar.
Overflow: Using overflow causes the images to shrink (which I don't quite understand, but it doesn't help with the border either).
How can I create bottom borders for each of these sections?
<section class="stories">
<div class="container">
<h2>Section header</h2>
<div class="col-sm-3 sidebar">
<h6>list of stories</h6>
<ul>
<li>list-item</li>
<li>list-item</li>
<li>list-item</li>
<li>list-item</li>
</ul>
</div>
<section class="story-section">
<div class="col-sm-3">
<img src="http://placehold.it/330x220">
</div>
<div class="col-sm-6">
<h6>keyword</h6>
<h3>Header of section</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras eleifend dictum neque sed laoreet ...</p>
</div>
</section>
// (there are three more sections with the same class of "story-sections", plus other code on the page, but I've tried to simplify it as much as possible here.)
</div>
</section>
css:
html, body {
height: 100vh;
}
.stories {
.sidebar {
height: 100vh;
}
.story-section {
border-bottom: 1px solid $grey;
}
}
I'm still fairly new with Bootstrap, so there may be a very simple solution, but I haven't been able to track it down. Any help is very welcome!
if you want to have a sidebar with 3 columns + a left section with the remaining 9 columns, then you need to set col-*-9 in your story-section
Note: in bootstrap, you need to have .row right below .container or between nested col-*
html,
body {
height: 100vh;
}
.sidebar {
height: 100vh;
background: lightblue
}
.story-section {
border-bottom: 1px solid grey;
}
img {
margin-top: 10px
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<section class="stories">
<div class="container">
<div class="row">
<h2>Section header</h2>
<div class="col-xs-3 col-sm-3 sidebar">
<h6>list of stories</h6>
<ul>
<li>list-item</li>
<li>list-item</li>
<li>list-item</li>
<li>list-item</li>
</ul>
</div>
<section class="story-section col-xs-9 col-sm-9">
<div class="row">
<div class="col-xs-6 col-sm-6">
<img class="img-responsive" src="http://placehold.it/330x220">
</div>
<div class="col-xs-6 col-sm-6">
<h6>keyword</h6>
<h3>Header of section</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras eleifend dictum neque sed laoreet ...</p>
</div>
</div>
</section>
<section class="story-section col-xs-9 col-sm-9">
<div class="row">
<div class="col-xs-6 col-sm-6">
<img class="img-responsive" src="http://placehold.it/330x220">
</div>
<div class="col-xs-6 col-sm-6">
<h6>keyword</h6>
<h3>Header of section</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras eleifend dictum neque sed laoreet ...</p>
</div>
</div>
</section>
</div>
</div>
</section>
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 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.