Extra spacing below my in-line images - html

Background
I am creating a video gallery using the ShadowBox jQuery plugin. To do this, I am creating rows of inline images using display:inline-block. The user will be able to upload a video as well as thumbnail images to accompany the video. The thumbnail's max size is 240x160 pixels.
What I want to do is have a black border around each gallery thumbnail "slot" with the user's uploaded thumbnail residing inside of that "slot", so if the user uploads a 240x160 thumbnail, the thumbnail will fill up the "slot" completely, and if they upload a smaller image, the thumbnail will still be in the "slot" with some extra spacing around it.
Here's an example of where I am right now: http://jsfiddle.net/shaunp/HvZ5p/
The problem is that there is extra spacing below my thumbnails and I'm not sure why. If you inspect the code you will see that there is an extra 5 pixels lurking below the image and I'm not sure where it's coming from. The grey part below the image should be directly BEHIND the image so that in the case the user uploads a smaller thumbnail, there will be grey-background space around it, but for some reason it is too tall. Any suggestions?
HTML
<div class="inline">
<div class="bg-thumb">
<div class="cell-thumb">
<a href="#" rev="#nvcCaption#" class="shadow">
<img src="http://farm9.staticflickr.com/8330/8135703920_f2302b8415_m.jpg" class="thumbImg" alt="Thumb" />
</a>
</div>
</div>
<div class="vcCaption">Caption</div>
</div>
<div class="inline">
<div class="bg-thumb">
<div class="cell-thumb">
<a href="#" rev="#nvcCaption#" class="shadow">
<img src="http://farm9.staticflickr.com/8330/8135703920_f2302b8415_m.jpg" class="thumbImg" alt="Thumb" />
</a>
</div>
</div>
<div class="vcCaption">Caption</div>
</div>
CSS
body {
overflow:hidden;
margin:0 50px 0 50px;
}
.vcCaption {
text-align:center;
font-family:"HelveticaNeue-Light","Helvetica Neue",Helvetica,Arial,sans-serif;
font-size:14px;
color:#000;
margin-bottom:5px;
}
.inline {
display:inline-block;
}
.bg-thumb {
width:250px;
height:170px;
}
.bg-thumb {
text-align:center;
display:table;
margin-bottom:5px;
}
.cell-thumb {
display:table-cell;
vertical-align:middle;
border:5px solid #000;
background-color:#7f7f7f;
}
.thumbImg {
max-width:240px;
max-height:160px;
}

Add vertical-align:top to your thumbnails:
.thumbImg {
max-width:240px;
max-height:160px;
vertical-align:top;
}
jsFiddle example
The default value of vertical-align is baseline, but for your needs you'll want the images to align to the top.
Another option would be to set the font size to zero on the containing div like:
.cell-thumb {
display:table-cell;
vertical-align:middle;
border:5px solid #000;
background-color:#7f7f7f;
font-size:0;
}
jsFiddle example

Adding vertical-align: middle; to your image will solve that.
.thumbImg {
vertical-align: middle;
max-width:240px;
max-height:160px;
}

the anchor tag is by default an inline element which gives it extra spacing, set it to a block element and give it some width and height!
.cell-thumb a {
display: block;
width: 240px;
height: 160px;
}

Images will by default display as inline-block (http://dev.w3.org/html5/markup/img.html#img-display) meaning that they will sits on an inline level block - or text line if you prefer.
Either set the font-size and/or line-height to 0 or in this case simply set the image to display at block level (display: block;).

Related

how to hide the border of <img> tag (when the img load error)

while there is no "src" attribute in the tag or the "src" linked to a resource which dose not existed,there'll display a border out of the tag.
just like this
//html code:
<div class="example" style="height:70px;width:100px">
<img src="404error.html">
</div>
//↑↑↑ in firefox
//↑↑↑ in chrome
// css code
.example img{
display:inline-block
height:30px;
margin:20px;
}
how can I hide this border // border:none; is useless
besides,there is another stange phenomenon.
That is,when I set "line-height" to a tag,the border of img which i said will move down,so it looks not around the picture at all.
and it just appear in chrome,but not in firefox.
like this.
//↑↑↑ in firefox
//↑↑↑ in chrome
//css code
.example img{
display:inline-block
height:30px;
margin:20px;
line-height:70px; //this is the difference
}
p.s. i use the "line-height" just for the words not the imgs.when i set .img{line-height:0;}it returns.i just want to know why.and how to hide the border.
thanks.
https://jsfiddle.net/s3Lvr9bs/1/
<div class="example">
<object data="https://developers.google.com/+/images/branding/button-gplus.png" type="image/jpg">
<img src="404error.html" alt="" />
</object>
</div>
.example {
display:inline-block;
background:#444;
border-radius: 5px;
padding:5px;
min-width:30px; min-height:30px;
}
object {display:block;}
You need:
img alt="" (hides in Firefox)
object data (gets the url for image)
object display block, to remove margins.

How to get picture to align with the left set of paragraphs/go to right of?

Here is a prototype of what I am trying to implement
Here is what I currently have : JsFiddle
I am trying to get the picture of the guy on the laptop to align correctly with and to the right of the paragraph components - Business Traveller, Office Supply Purchases, etc...
What I've tried is using Align attribute, changing my img src code to
<img id="laptop" align="middle" src="zoom-39988392-3.JPG" height = "90" width ="90" />
but that didn't have any effect.
I also tried Float but that messed up my margins and the organization of my left components.
Is there a way I can do this without floating?
See the fiddle
The HTML and CSS that i've used is as follows. Used float:left
HTML
<div class="container">
<div id="choices">
<p class="choice">Business Traveller</p>
<p class="choice">Office Supply Purchases</p>
<p class="choice">Stay at home parent</p>
<p class="choice">Entertainment</p>
<p class="choice">Profile 6</p>
</div>
<div class="image"></div>
</div>
CSS
html, body, .container {
height:100%;
}
#choices {
width:30%;
float:left;
}
.choice {
margin-top:0px;
margin-left:20px;
text-align:center;
width:100%;
background-image: url("http://i.imgur.com/H43sVoi.png");
padding-top:15px;
padding-bottom:15px;
}
.image {
height:100%;
width:65%;
background-color:red;
float:left;
}
You will have to work with the height and width of each divs. I just made it roughly.
You have to create two columns. 1 column for the menu and the second column for the image. If you do this, you wont have trouble floating.

Keep images from breaking to next line without float

I have a footer with social media icons. I want the icons arranged in a 3 x 3 grid
like below.
# # #
# # #
# # #
I also want it centered in a div. The issue that I'm running into, is that when I float the elements left to keep them on the same line my
margin-left:auto;
margin-right:auto;
Doesnt work, and they just align left. I need a solution that will work for mobile since my whole site is responsive.
Here is the HTML
<div class="d-all m-all" id="mainFooter">
<div class="d1-d4 m-all" id="socialMedia">
<div id="centerIcons">
<img src="images/fb_icon_vi.png"><img src="images/tw_icon_vi.png"><img src="images/in_icon_vi.png">
</div>
</div>
<div class="d5-d8 m-all" id="contact">
Contact
</div>
<div class="d9-d12 m-all" id="awards">
awards
</div>
</div>
And here is the CSS
#mainFooter{
background-color:black;
height:250px;
}
#socialMedia{
background-color:green;
}
#socialMedia img{
display:block;
}
#centerIcons{
background-color:yellow;
width:50%;
margin-left:auto;
margin-right:auto;
height:75px;
}
#centerIcons img{
margin-left:auto;
margin-right:auto;
}
The whole site can be seen HERE
I guess you want to something like this, right?
#socialMedia img {
display: inline-block;
}
#centerIcons{
background-color:yellow;
width:50%;
height:75px;
max-width: 171px;
margin: 0 auto;
}
#centerIcons img{
/* nothing is needed */
}
Explanation:
display: inline-block; will keep as block but not opening a new line
since #centerIcons is a DIV element, it is a block element, to make use of centering effect with margin: 0 auto; a width control is needed
so max-width: 171px; will constraint its width to a maximum of 171px (icon width 57px * 3), you may adjust as you need
Note:
About display property, please refer to W3C's visual formatting model.
About box model specification, you may refer to W3C's box model.
Depends on your browser compatibility plan, max-width does not supported in IE8 below and IE8 have some bugs. For details, you may refer to online compatibility chart like this.
If you are using jQuery and really mean to support IE6-8, you may consider using polyfill such as Scott Jehl's Respond.js
Edit: I think #Matt Smith's answer is what you want, I may have misinterpreted your meaning. Anyway, for your reference.
<img> is a replaced inline element (by default). The image elements sit beside each other like words. Therefore there's no need to change their display type to block (as you have done in the live demo).
I want the icons arranged in a 3 x 3 grid
In order to achieve that, you could wrap each 3 images by a wrapper, and add text-align: center to that element to align the inline images horizontally.
EXAMPLE HERE.
<div id="centerIcons">
<div class="wrapper">
<img src="images/1.png">
<img src="images/2.png">
<img src="images/3.png">
</div>
<div class="wrapper">
<img src="images/4.png">
<img src="images/5.png">
<img src="images/6.png">
</div>
<div class="wrapper">
<img src="images/7.png">
<img src="images/8.png">
<img src="images/9.png">
</div>
</div>
.wrapper {
text-align: center;
}
Add text-align: center to the #centerIcons {} rule and display: inline-block to your #centerIcons img {} rule:
#centerIcons img {
text-align: center;
}
#centerIcons img {
display: inline-block;
}

Fixing my gallery shortcode in wordpress

I have been trying to figure out on how to fix my gallery shortcode in wordpress. Basically the objective is that user can place any size of images inside the shortcode and will not look stretch or distorted when viewed.
This is what is supposed to look like
http://i255.photobucket.com/albums/hh140/testament1234/Thumb_zpsf57e544b.jpg
This is what i have came up with when i coded it.
http://s255.photobucket.com/user/testament1234/media/thumbnail_zpsd95f993d.jpg.html?sort=3&o=0
If you notice the first image is missing a 5px margin at bottom. The 2nd and 3rd image is not touching the bottom of the div.
Here is the code for the function.ph
//Gallery Shortcode 2
function short_gallery($atts, $content = null) {
extract(shortcode_atts(array(), $atts));
return '<div class=" gallery_box"><div class="inner_gallery"><a class="fancybox" href="'.$content.'"><img src="'.$content.'"/></a></div></div>';
}
add_shortcode("gallery", "short_gallery");
And here is the code for my styling.
.gallery_box{background-color:#E8ECEF; float:left; margin:0px 20px 10px 0px; width:250px; height:200px; overflow:hidden }
.inner_gallery{margin:10px; margin:5px}
.inner_gallery img{max-width:100%; }
Been researching for hours on how i can achieve my desired results. It's ok if the image is crop as long it fits the container and the quality is not distored
Change your styles to match these:
-add border property to the gallery_box
.gallery_box{
background-color:#E8ECEF;
float:left;
margin:0px 20px 10px 0px;
width:250px;
height:200px;
overflow:hidden;
border:5px solid #E8ECEF;
}
-remove the ".inner_gallery{margin:10px; margin:5px}" class
-change .inner_gallery img to:
.inner_gallery img{
max-width : 400px;
max-height : 400px;
}
It's a quick shortcut solution but it gets the job done. As long as you're ok with cropping.
My suggestion would be to set the image as the background image of its container (or the background image of the img tag, and set the src to a blank image for proper scaling):
<figure>
<img src="BLANK_IMAGE_WITH_YOUR_TARGET_SIZE" style="background-image:url('URL')" alt="My Image" />
</figure>
Then set the background-size to cover:
figure { width:250px; border:solid 5px #666; margin:0 20px 10px 0; }
figure img { width:100%; background-size:cover; background-position:center center; background-repeat:no-repeat; }

Why aren't my divs aligning?

Morning,
I have the following HTML:
<div id="sah_padding">
<div id="sah_holder">
<div id="sah_name">Hello [agent_name]</div>
<div id="sah_logout">✖</div>
</div>
You are working with [customer_name]
</div>
and I have the following CSS:
#sah_padding{
padding:10px 10px 10px 10px;
}
#sah_holder{
padding-bottom:10px;
clear:both;
}
#sah_name{
float:left;
width:50%;
}
#sah_logout{
text-align:right;
}
#logout_link{
color:#fff;
text-decoration:none;
font-weight:bold;
}
However my login link and Hello message aren't aligning correctly, the logout link is a few pixels below the hello message and I need them to be on the same horizontal line. What am I doing wrong?
if you set line-height :1 to #logout_link element, it should correct the alignment
(of course feel free to choose a different value to adjust it)
Give float to your #sah_logout also. Write like this:
#sah_logout{
float: left;
text-align:right;
}
Check this http://jsfiddle.net/QUNT2/
Check the line-height of your elements!!!
You need to set a float to #sah_logout as well:
#sah_logout{
float: left;
text-align:right;
}
You can even make it say, float: right. It's entirely your choice. Doing only a text-align: right will modify how the inner contents of the container behave, not how the div behaves within the flow.
Also, you might have a few problems with the parent div not wrapping correctly around the children divs (as all children now have float properties), so you might need to add another div, with clear: both set in its style:
<div id="sah_holder">
<div id="sah_name">Hello [agent_name]</div>
<div id="sah_logout">✖</div>
<div style="clear: both"></div>
</div>
Instead of wasting time with block level elements why don't you simply use inline elements for both the "Hello" text and the logout link? That's what inline elements are supposed to do - stay in line with each other.
<div id="sah_padding">
<div id="sah_holder">
<span id="sah_name">Hello [agent_name]</span>✖
</div>
<span>You are working with [customer_name]</span>
</div>
Its is highly unlikely that you would need any of the CSS code you previously used for elements inside sah_holder unless you want to style them differently.
check it your updated html :-
<div id="sah_padding">
<div id="sah_holder">
<div id="sah_name">Hello [agent_name]</div>
<div id="sah_logout">You are working with [customer_name]</div>
</div>
</div>
your updated css:-
#sah_padding{
padding:10px 10px 10px 10px;
}
#sah_holder{
padding-bottom:10px;
border:1px solid red;
overflow:hidden;
}
#sah_name{
float:left;
width:50%;
}
#sah_logout{
float:right;
}
.logout_link{
color:black;
text-decoration:none;
font-weight:bold;
}
or you can see the demo:- http://jsfiddle.net/WnecH/11/