css - div's layout as a table - html

I am having problems with formatting my html 3x3 gallery created with div's. Here is how it looks like now:
http://codepen.io/makkam121/pen/EisKd
.gallery {
width: auto;
margin: 50px auto;
padding: 10px;
border: 2px solid black;
}
.gallery_row {
margin: 10px 10px 10px 0px;
width: auto;
}
.gallery_image {
width: auto;
display: inline-block;
margin-right: 10px;
}
img {
border: 2px solid black;
padding: 10px;
background-color: #BBAABB;
}
<div class="gallery">
<div class="gallery_row">
<div class="gallery_image">
<img src="http://upload.wikimedia.org/wikipedia/commons/thumb/b/b2/Wilderness_road.jpg/70px-Wilderness_road.jpg" alt="">
</div>
<div class="gallery_image">
<img src="http://upload.wikimedia.org/wikipedia/commons/thumb/b/b2/Wilderness_road.jpg/70px-Wilderness_road.jpg" alt="">
</div>
<div class="gallery_image">
<img src="http://upload.wikimedia.org/wikipedia/commons/thumb/b/b2/Wilderness_road.jpg/70px-Wilderness_road.jpg" alt="">
</div>
</div>
<div class="gallery_row">
<div class="gallery_image">
<img src="http://upload.wikimedia.org/wikipedia/commons/thumb/b/b2/Wilderness_road.jpg/70px-Wilderness_road.jpg" alt="">
</div>
<div class="gallery_image">
<img src="http://upload.wikimedia.org/wikipedia/commons/thumb/b/b2/Wilderness_road.jpg/70px-Wilderness_road.jpg" alt="">
</div>
<div class="gallery_image">
<img src="http://upload.wikimedia.org/wikipedia/commons/thumb/b/b2/Wilderness_road.jpg/70px-Wilderness_road.jpg" alt="">
</div>
</div>
<div class="gallery_row">
<div class="gallery_image">
<img src="http://upload.wikimedia.org/wikipedia/commons/thumb/b/b2/Wilderness_road.jpg/70px-Wilderness_road.jpg" alt="">
</div>
<div class="gallery_image">
<img src="http://upload.wikimedia.org/wikipedia/commons/thumb/b/b2/Wilderness_road.jpg/70px-Wilderness_road.jpg" alt="">
</div>
<div class="gallery_image">
<img src="http://upload.wikimedia.org/wikipedia/commons/thumb/b/b2/Wilderness_road.jpg/70px-Wilderness_road.jpg" alt="">
</div>
</div>
</div>
I want the gallery to align to the center of the page automatically as the number of images in a row may vary. Instead, I am getting a div with a huge right margin reaching to the right edge of the page. And additionally, I want the spacing between the items and the outer border to be equal(they're not...).
What am I doing wrong? I would appreciate any help.

http://codepen.io/anon/pen/mgqeJ
.gallery{
width:auto;
margin: 0auto;
width:100%;
text-align:center;
border:2px solid black;
}
.gallery_row{
margin:2%;
width:auto;
}
.gallery_image{
width:auto;
display:inline-block;
margin:2% 5% 2% 5%
}
img {
border:2px solid black;
padding:20%;
background-color:#BBAABB;
}

Related

Image not being responsive. I have tried both adding img-responsive class and setting height to auto in css

This is my html code.
<div class="column">
<div class="slider" id="main-slider">
<div class="slider-wrapper">
<img src="images/11.jpg" class="slide img-responsive">
</div>
</div>
</div>
This is the css part.
img{
border-color: white; border-radius: 8px;border: 1px solid #ddd;
max-width: 100%;
float: left;
margin: 0 5% 80px 0;
width:100%;
height:auto;
}
The image not being responsive. I have tried both adding img-responsive class and setting height to auto in css. It does not shrink when I reduce the browser size.
Bootstrap 4 use img-fluid instead of img-responsive. Read its documentation here
Try to replace this code
img {
border-color: white;
border-radius: 8px;
border: 1px solid #ddd;
max-width: 100%;
margin: 0 5% 80px 0;
height: auto;
}
I have put your code into JSFiddle with an image without the img-responsive class and everything seems to be working fine?
<div class="column">
<div class="slider" id="main-slider">
<div class="slider-wrapper">
<img src="https://www.gettyimages.co.uk/gi-resources/images/Embed/new/embed2.jpg">
</div>
</div>
</div>
https://jsfiddle.net/zhg95pa8/
Delete the class and see if that works any better.
Add width="100%" to <img> tag and remove width from img css part. That's it :)
img{
border-color: white; border-radius: 8px;border: 1px solid #ddd;
max-width: 100%;
float: left;
margin: 0 5% 80px 0;
/*width:100%;*/
/*height:auto;*/
}
<div class="column">
<div class="slider" id="main-slider">
<div class="slider-wrapper">
<img src="https://cdn.dribbble.com/users/1928643/screenshots/4451111/shot3.jpg" class="slide img-responsive" width="100%">
</div>
</div>
</div>

Center a inline-block div that contains floating items

Sorry if I posted something similar to other questions, but actually I needed solution. Well what I am trying to do is am creating gallery of images. So I have images of 200px, each image is block. So in order to center those image according to screen-sizes I am trying to wrap those images inside other div(i.e. inline-block). But its not ready to move in center.
I also want to mention that I am using this within a container.
.gallery{
display:inline-block; /* I am not sure what to do here */
}
.thumbnail{
width:200px;
height:200px;
border:1px solid #aaa;
border-radius:5px;
display:block;
}
.thumbnail img{
width:100%;
height:100%;
border:5px solid white;
border-radius:5px;
}
.gallery-item{
float:left;
margin:10px;
}
.clearfix:after{
clear:both;
}
.clearfix:after, .clearfix:before{
display:table;
content: " ";
}
.clearfix:after{
content:" ";
height:10px;
}
<div class="gallery">
<div class="thumbnail gallery-item">
<img src="images/slide1.jpg" />
</div>
<div class="thumbnail gallery-item">
<img src="images/slide1.jpg" />
</div>
<div class="thumbnail gallary-item">
<img src="images/slide1.jpg" />
</div>
<div class="thumbnail gallery-item">
<img src="images/slide1.jpg" />
</div>
<span class="clearfix"></span>
</div>
Don't use float property if you want elements to be centered.
.gallery {
font-size: 0; /*fix for white space */
text-align: center;
}
.thumbnail {
display: inline-block;
margin: 10px;
width: 200px;
height: 200px;
border: 1px solid #aaa;
border-radius: 5px;
box-sizing: border-box;
}
.thumbnail img {
max-width: 100%;
height: auto;
border: 5px solid white;
border-radius: 5px;
box-sizing: border-box;
}
<div class="gallery">
<div class="thumbnail">
<img src="http://placehold.it/200x200" />
</div>
<div class="thumbnail">
<img src="http://placehold.it/200x200" />
</div>
<div class="thumbnail">
<img src="http://placehold.it/200x200" />
</div>
<div class="thumbnail">
<img src="http://placehold.it/200x200" />
</div>
</div>
JSFiddle: http://jsfiddle.net/ntbh1rmk/
well since i need 50 reputation to comment (very stupid restriction in my opinion).. i was going to ask why you have 100% for width and height, then add 5px padding to it? isn't that like making it 100% + 10PX?
.thumbnail img{
width:100%;
height:100%;
border:5px solid white;
border-radius:5px;
maybe it's just how i'm being taught... (i'm in CSS class now).. but thats always been a bad thing.

Why is the div not aligning correctly, vertically?

I want to achieve this (link to full size image):
And I have achieved this (link to full size image):
If you notice, the div that is in right to the left navigation, is not displaying at top, but at bottom. It should start displaying right below the top navigation.
Here is the HTML:
<div id="container">
<div id="header">
<div id="logo">
<img src="images/parislane-ebay-listing-template2_02.png" alt="">
</div>
<div id="top-nav">
<img src="images/parislane-ebay-listing-template2_05_01.png" alt="">
<img src="images/parislane-ebay-listing-template2_05_02.png" alt="">
<img src="images/parislane-ebay-listing-template2_05_03.png" alt="">
<img src="images/parislane-ebay-listing-template2_05_04.png" alt="">
<img src="images/parislane-ebay-listing-template2_05_05.png" alt="">
<img src="images/parislane-ebay-listing-template2_05_06.png" alt="">
<img src="images/parislane-ebay-listing-template2_05_07.png" alt="">
</div>
</div>
<div id="content">
<div id="left-nav">
<div id="left-nav-head">STORE CATEGORIES</div>
<div class="left-nav-link">Category Name</div>
<div class="left-nav-link">Category Name</div>
<div class="left-nav-link">Category Name</div>
<div class="left-nav-link">Category Name</div>
<div class="left-nav-link">Category Name</div>
<div class="left-nav-link">Category Name</div>
<div class="left-nav-link">Category Name</div>
<div class="left-nav-link">Category Name</div>
</div>
<div id="content-right">
item title may go here item title may go here
</div>
</div>
</div>
Here is the CSS:
img{ display:block; }
#container { background-color: #000; width: 100%; overflow:hidden; }
#header { width: 1010px; margin:0 auto 65px auto; }
#logo { width: 1010px; margin-bottom: 13px; }
#top-nav img { float:left; }
#content { width: 1010px; margin:0 auto; }
#left-nav { border: solid 1px #e56bae; width: 188px; }
#left-nav-head { background-image:url(images/parislane-ebay-listing-template2_15.png); height: 22px; padding-left:9px; vertical-align:middle; font-family:Arial, Helvetica, sans-serif; font-size: 13px; color:#000; font-weight:bold; padding-top: 10px; }
.left-nav-link { background-color:#292929; border-bottom: solid 1px #4b4b4b; padding:9px 9px 7px 9px; font-family:Arial, Helvetica, sans-serif; font-size: 12px; color:#fff; }
#content-right { width:805px; margin-left:15px; float:right; color:#fff; text-align:center; }
You need to make the divs float left.
#nav-left, #content-right{
float:left;
}
see fiddle: http://jsfiddle.net/3EJ6k/
block elements take up a full row even if 2 in succession have widths that should theoretically fit side by side, they wont do so unless floated.

constructing a gallery with thumbnails issues

This is what I'm trying to achieve. My problems are of course at generating the thumbnails right. What I tried is using a shadow rather than a border for the grey outline and I intended to put a margin for the thumbnails so they get to have the common outline you can probably see. I'm pretty much out of ideas and approaches to getting this to work so I would like to hear your suggestions. Thing is I want this to be responsive so I gave percent dimensions to the thumbnails and all. Here is the code:
<div class="gallery preview">
<div class="main frame">
<img src="images/pic-1.png" class="img-responsive" alt="a">
</div>
<div class="navigation">
<div class="control left">
<i class="fa fa-fw fa-chevron-left"></i>
</div>
<div class="thumb clearfix">
<div class="frame">
<img src="images/pic-1-thumb.png" class="img-responsive" alt="a">
</div>
<div class="frame">
<img src="images/pic-2-thumb.png" class="img-responsive" alt="a">
</div>
<div class="frame">
<img src="images/pic-3-thumb.png" class="img-responsive" alt="a">
</div>
<div class="frame">
<img src="images/pic-1-thumb.png" class="img-responsive" alt="a">
</div>
<div class="frame">
<img src="images/pic-2-thumb.png" class="img-responsive" alt="a">
</div>
<div class="frame">
<img src="images/pic-3-thumb.png" class="img-responsive" alt="a">
</div>
<div class="frame">
<img src="images/pic-1-thumb.png" class="img-responsive" alt="a">
</div>
</div>
<div class="control right">
<i class="fa fa-fw fa-chevron-right"></i>
</div>
</div>
</div>
and the css:
.preview.gallery {
margin: 10px 0;
}
.preview.gallery .frame {
border-radius: 3px;
}
.preview.gallery .thumb {
max-width: 508px;
float: left;
margin: 1px;
}
.preview.gallery .navigation .control {
width: 22px;
display: block;
}
.preview.gallery .navigation .control.left {
float: left;
}
.preview.gallery .navigation .control.right {
float: right;
}
.preview.gallery .thumb .frame {
width: 14.28571428571429%;
display: block;
float: left;
}
.preview.gallery .thumb .frame img {
width: 100%;
}
.preview.gallery .frame {
box-shadow: 0 0 1px 0 rgba(0,0,0,0.5);
}
.preview.gallery .main.frame {
border: 8px solid #fff;
}
.preview.gallery .navigation .control {
background: #fff;
line-height: 74px;
box-shadow: 0 0 1px 0 rgba(0,0,0,0.5);
margin-top: 1px;
border-radius: 3px;
}
1. Set the position of .navigation to relative (so that we can place the two controls on the side of this fluid div):
.navigation {
position:relative;
}
2. Add to .preview.gallery .navigation .control this css code:
.preview.gallery .navigation .control {
position:absolute;
top:0;
}
3. and to the left navigation div:
.preview.gallery .navigation .control.left {
left:0;
}
4. and to the right navigation div:
.preview.gallery .navigation .control.right {
right:0;
}
5. Finally change the margin on .preview.gallery .thumb to:
.preview.gallery .thumb {
margin:0 22px; /* or whatever width you have on the controls */
}
DEMO.
Note
You mentioned wanting some space between the thumbnail and the border. In order for that to work with the percentege values you assigned them, you will want to add this code too:
.preview.gallery .frame {
box-sizing:border-box;
-moz-box-sizing:border-box;
-webkit-box-sizing:border-box;
}

Displaying Image caption with only HTML and CSS

I am trying to display caption on images.
This is my HTML
<div class="image-hover">
<div class="image-block">
<a href="" target="_blank" class="image-overlay">
<div class="details">
<h4>Our philosophy and Vision</h4>
</div>
<div class="image-backdrop">
<img src="http://buildinternet.s3.amazonaws.com/projects/mosaic/omr-office.jpg"/>
</div>
</a>
</div>
<div class="image-block">
<a href="" target="_blank" class="image-overlay">
<div class="details">
<h4>Our philosophy and Vision</h4>
</div>
<div class="image-backdrop">
<img src="http://buildinternet.s3.amazonaws.com/projects/mosaic/omr-office.jpg"/>
</div>
</a>
</div>
<div class="image-block">
<a href="" target="_blank" class="image-overlay">
<div class="details">
<h4>Our philosophy and Vision</h4>
</div>
<div class="image-backdrop">
<img src="http://buildinternet.s3.amazonaws.com/projects/mosaic/omr-office.jpg"/>
</div>
</a>
</div>
<div class="image-block">
<a href="" target="_blank" class="image-overlay">
<div class="details">
<h4>Our philosophy and Vision</h4>
</div>
<div class="image-backdrop">
<img src="http://buildinternet.s3.amazonaws.com/projects/mosaic/omr-office.jpg"/>
</div>
</a>
</div>
</div>
This is my CSS :
.image-hover {
overflow: hidden;
}
.image-hover .image-block {
width: 234px;
height: 100px;
display: inline-block;
border: 1px solid #666666;
}
.image-hover .image-block img {
width: 230px;
height: 100px;
border: 2px solid #fff;
}
.details, .image-backdrop {
float: left;
}
.details h4:after {
display: inline-block;
content:" ";
width: 0;
height: 0;
border-top: 6px solid transparent;
border-bottom: 6px solid transparent;
border-left: 8px solid #666666;
margin: 0 10px;
}
This is my JsFiddel
My problem is how can I get image's caption to above of image?
Any comments are greatly welcome.
Thank you.
you should use position:relative; to the container and position:absolute; to the child container whom you want to on image it is styled as you want
http://jsfiddle.net/ADMvd/2/
Add this to your CSS
.details h4 {
color: white; /* just to make it look pretty */
}
.details {
position: absolute;
}
.image-overlay {
position: relative;
}
DEMO
EDIT
Note that you are using div tag inside your a tag so don't forget to add display: block to your a.image-overlay tag because inline elements can't contain any other type of elements. It does work but will cause many weird problems.
For starters height:100% won't work for div inside a