Unwanted space inside of DIVs - html

I´m trying to place a slided image in the center if the page. I have it almost done, the thing is that inner each piece of the image I have a small space, like if it has some little padding (which it hasn't), does anybody sees something wrong in the code?
<style type="text/css">
html, body, #wrapper, images {
height: 100%;
width: 100%;
margin: 0px;
padding: 0px;
border: 0px;
background-color: #000;
}
img {
margin: 0px;
padding: 0px;
border: 0px;
}
.center {
width: 800px;
height: 600px;
position: absolute;
left: 50%;
top: 50%;
margin-left: -400px;
margin-top: -300px;
}
.center_mini {
margin: 0px;
padding: 0px;
border: 0px;
}
.center_mini_float {
float: left;
margin: 0px;
padding: 0px;
border: 0px;
}
</style>
<div class="center">
<div class="center_mini">
<img src="images/background_01.png" width="800" height="144" alt="bg">
<div class="center_mini">
<div class="center_mini_float">
<img src="images/background_02.png" width="503" height="456" alt="bg">
</div>
<div class="center_mini_float">
<div class="center_mini">
<div class="center_mini">
<img src="images/background_03.png" width="246" height="89" alt="bg">
</div>
<div class="center_mini">
<img src="images/background_05.png" width="246" height="106" alt="bg">
</div>
<div class="center_mini">
<img src="images/background_06.png" width="246" height="102" alt="bg">
</div>
<div class="center_mini">
<img src="images/background_07.png" width="246" height="159" alt="bg">
</div>
</div>
</div>
<div class="center_mini_float">
<img src="images/background_04.png" width="51" height="456" alt="bg">
</div>
</div>
</div>
<!--<img src="images/background.jpg" width="800" height="600" alt="bg">-->
</div>

Try adding:
img { display: block; }

The problem is that IMG tags have a natural DISPLAY value of "INLINE". This causes extra whitespace to appear around the image in certain situations.
Depending on your layout needs, try
img { display: block; }
or
img { display:inline-block; }
If your images are otherwise working the way you want, inline-block will cause the least amount of thrash.
More info:
http://www.w3schools.com/cssref/pr_class_display.asp
http://www.tequilafish.com/2009/04/29/css-removing-extra-space-underneath-an-image/

I think the better solution will be using
img { vertical-align: middle; }
This way you won't alternate the default browser image display. Also, make sure the image container has line-height: 100%, that could be causing problems too.

Images have display:inline; by default, that's what's causing the whitespace between your images. You can do three things to prevent this:
float:left;
or
display:inline-block;
or
display:block;

Related

Two images side by side and responsive

I'm trying to put two images side by side and make them responsive. The problem now is, that the second image wraps first and then reacts to the size of the browser.
I want them to stay on the same line (level) and change their size automatically and wrap at a certain point (this part isn't the problem)....
The html:
<div id="wrapper">
<div id="outer">
<div class="itemwrapper">
<img src="item2.jpg" alt="bag" />
</div>
<div class="itemwrapper">
<img src="item3.jpg" alt="pen" />
</div>
</div>
</div>
The css:
#wrapper {
max-width: 1050px;
margin: 60px auto 60px auto;
background-color: #DDD
}
.itemwrapper {
display: inline;
}
img {
max-width: 100%;
height: auto;
}
use display table to set it side by side and keep it side by side and responsive.
display: table; with table-layout: fixed; will create a fluid layout for child elements with display: table-cell;
this will not only keep them the same width but also keep the containers the same height.
vertical-align: top; will keep them aligned to the top alternatively you can change the vertical position to middle and bottom plus some others.
Any questions just fire away.
#wrapper {
max-width: 1050px;
margin: 60px auto 60px auto;
background-color: #DDD
}
#outer {
display: table;
width: 100%;
table-layout: fixed;
}
.itemwrapper {
display: table-cell;
vertical-align: top;
width: 100%;
}
img {
max-width: 100%;
height: auto;
}
<div id="wrapper">
<div id="outer">
<div class="itemwrapper">
<img src="item2.jpg" alt="bag" />
</div>
<div class="itemwrapper">
<img src="item3.jpg" alt="pen" />
</div>
</div>
</div>
if image are same size or same ratio, you may use flex , width and min-width to set a break point:
#outer {
width:70%;/* demo*/
margin:auto;/* demo*/
display:flex;
flex-wrap:wrap;
}
#outer>div {flex:1;}
#outer>div>img {
width:100%;
min-width:200px;/* demo*/
}
<div id="wrapper">
<div id="outer">
<div class="itemwrapper">
<img src="http://lorempixel.com/200/100" alt="bag" />
</div>
<div class="itemwrapper">
<img src="http://lorempixel.com/400/200" alt="pen" />
</div>
</div>
</div>
remove or reset to your needs the rules commented with demo.
Thanks for the help, but I'm doing it with a different solution now, whicha friend suggested:
#outer {
position: relative;
width: 50%;
height: 0;
margin: 30px auto 0 auto;
padding-top: 25%;
background-color: #999;
}
.itemwrapper {
position: absolute;
width: 50%;
height: 100%;
top: 0;
}
.item2 {
left: 50%;
}
#outer img {
height: 100%;
max-width: 100%;
}
<div id="wrapper">
<div id="outer">
<div class="itemwrapper">
<img src="http://lorempixel.com/200/100" alt="bag" />
</div>
<div class="itemwrapper item2">
<img src="http://lorempixel.com/400/200" alt="pen" />
</div>
</div>
</div>
This evokes another problem though. The images arent filling the itemwrappers. I think i need to write some js for this :S.

Align two images side by side

I want to arrange the two images in my HTML page side by side.
I want the images to stay side by side even if the page size changes.
I also want the second image to span the entire header of the page ie. all the space left after the first image. The images here are of different size.
For now, I have arranged two images side by side, but when I change the size of the page, the image wraps and comes in the next line after the first image.
Here is my code sample and the CSS:
.header {
display: inline-block;
margin-left: auto;
margin-right: auto;
height: 120px;
}
<img class="header" src="http://www.placehold.it/160X120" style="float: left;" alt="CCM Logo">
<img class="header" src="http://www.placehold.it/543X120/0000FF" alt="CCM Banner">
Here is a Fiddle.
Use white-space: nowrap to prevent wrapping.
.header {
margin: 0 auto; max-width: 800px; /*centering header*/
height: 120px; position: relative; /*scale header images to 120px*/
white-space: nowrap; /*keep one-line*/
overflow: hidden; /*hide excess images parts on small screens*/
}
.header>img { height: 100%;}
<body>
<div class="header">
<img src="http://www.www8-hp.com/in/en/images/T-GE-healthcare-logo__153x115--C-tcm188-1616301--CT-tcm188-1237012-32.jpg" alt="CCM Logo">
<img src="http://blu-alliance.com/wp-content/uploads/2013/10/healthcare-banner2.jpg" alt="CCM Banner">
</div>
</body>
.header {
display: inline-block;
margin-left: auto;
margin-right: auto;
max-width: 50%;
height:120px;
}
HTML:
<body>
<img class="header" src="http://www.www8-hp.com/in/en/images/T-GE-healthcare-logo__153x115--C-tcm188-1616301--CT-tcm188-1237012-32.jpg" style="float: left;" alt="CCM Logo">
<img class="header" src="http://blu-alliance.com/wp-content/uploads/2013/10/healthcare-banner2.jpg" alt="CCM Banner">
</body>
Give style
.header {
display: block;
float:left;
height: 120px;
}
to both images
Apply below style:
.header {
display: inline-block;
height: 120px;
width: 50%;
}
Try with max-width Demo
.header {
max-width:50%;
}
Try this -
<div class="imgclass">
<div class="img1">
your img here
</div>
</div>
<div class="imgclass">
<div class="img2">
your img here
</div>
</div>
On your css file or between <style>here</style> this -
.imgclass {
display: table-cell;
}

CSS Div Boxes that are centred and arrange according to browser window size

I am trying to make a web page that has multiple amount of Div (.collectionbox) boxes that are identical to each other and 'float' next to each other as much as they can until they hit the side of the window then start a new line. So if i was to create a PHP loops it will all still look centered and the mroe divs the longer the bage would become.
Within each div (.collectionbox) is another div (.addtobasket) box that needs to sit at the bottom of the div (.collectionbox).
All of these sit inside of one main div (#mainbody)
Ive managed to get everything i want working individually, but getting it all working together is causing me head aches.
Currently my code below will center the page as needed, now i would just like the .collectionbox divs to have the same effect a float: left. would have without actually being to the left and for the .addtobasket div to be at the bottom of the .collectionbox regardless of the contents.
My CSS:
<style type="text/css">
#mainbody {
width: 100%;
margin-left: auto;
margin-right: auto;
height: auto;
text-align: center;
}
.collectionbox {
height: 295px;
width: 295px;
background-image: url(collectionbox.png);
background-repeat: no-repeat;
margin-right: auto;
margin-left: auto;
text-align: left;
position: relative;
float: none;
}
.addtobasket {
width: 266px;
text-align: center;
height: 57px;
position: relative;
left: 16px;
top: 50px;
}
</style>
My Html:
<div id="mainbody">
<div class="collectionbox">
<div class=".collectionboxtitle"><img src="title-verybritish.png" width="295" height="49" /></div>
<div class="addtobasket"><img src="price-4-99.png" width="174" height="57" border="0"/></div>
<p>Test</p>
</div>
<div class="collectionbox">
<div class=".collectionboxtitle"><img src="title-verybritish.png" width="295" height="49" /></div>
<div class="addtobasket"><img src="price-4-99.png" width="174" height="57" border="0"/></div>
<p>Test </p>
</div>
<div class="collectionbox">
<div class=".collectionboxtitle"><img src="title-verybritish.png" width="295" height="49" /></div>
<div class="addtobasket"><img src="price-4-99.png" width="174" height="57" border="0"/></div>
<p>Test</p>
</div>
<div class="collectionbox">
<div class=".collectionboxtitle"><img src="title-verybritish.png" width="295" height="49" /></div>
<div class="addtobasket"><img src="price-4-99.png" width="174" height="57" border="0"/></div>
<p>Test </p>
</div>
</div>
Thanks for any help in advance!
Paul.
To get the boxes (collectionbox) centered and still displayed in a row next to eachother you can use display: inline-block instead of float: left.
.collectionbox {
height: 295px;
width: 295px;
background-image: url(collectionbox.png);
background-repeat: no-repeat;
margin-right: auto;
margin-left: auto;
text-align: left;
position: relative;
display:inline-block;
vertical-align: top;
}
As for the addtobasket div you should absolute position it to make it stay att the bottom of it's parent at all times.
.addtobasket {
width: 266px;
text-align: center;
height: 57px;
position: absolute;
left: 16px;
bottom: 0px;
}
JsFiddle here

how to space 4 images equally within a div?

i have 4 social media buttons in a div and i want to space them equally but i can't figure out how to?
CSS
.socialbuttonstop {
height: 150px;
width: 35px;
margin-left: 915px;
position: absolute;
}
HTML
<div class="header">
<div class="headercontent">
<div class="socialbuttonstop">
<img src="Images/facebooksmall.png" />
<img src="Images/twittersmall.png" />
<img src="Images/googlesmall.png" />
<img src="Images/linkedinsmall.png" />
</div>
</div>
</div>
I would place a div around the images and place the height of the divs to 25%.
HTML
<div class="header">
<div class="headercontent">
<div class="socialbuttonstop">
<div class="social_btn">
<img src="Images/facebooksmall.png"/>
</div>
<div class="social_btn">
<img src="Images/twittersmall.png"/>
</div>
<div class="social_btn">
<img src="Images/googlesmall.png"/>
</div>
<div class="social_btn">
<img src="Images/linkedinsmall.png"/>
</div>
</div>
</div>
</div>
CSS
.socialbuttonstop {
height: 150px;
width: 35px;
margin-left: 915px;
position: absolute;
}
.social_btn {
height: 25%;
}
If your container div is a fixed width here's what I usually do, assuming 48x48 icons:
HTML
<div id="social">
<img id="twitter" />
<img id="facebook" />
<img id="linkedin" />
</div>
CSS
#social {
width: 154px;
height: 48px;
}
#social img {
width: 48px;
height: 48px;
float: left;
margin-right: 5px;
background-image: url('icons.png');
background-position: 0px 0px;
}
#social img:last-child{
margin-right: 0px;
}
#social img#twitter {
background-position: -48px 0px;
}
#social img#facebook {
background-position: -96px 0px;
}
Then make a PNG file with just the icons without any padding
I only can think of the use of padding:
HTML:
<div>
<img class="imagePadding" src="Images/twittersmall.png"/>
<img class="imagePadding" src="Images/twittersmall.png"/>
<img class="imagePadding" src="Images/googlesmall.png"/>
<img class="imagePadding" src="Images/linkedinsmall.png"/>
</div>
CSS:
.imagePadding
{
padding: 10px;
}
For vertically centering the block please check the following fiddle http://jsfiddle.net/L4su9/3/
.socialbuttonstop
{
height: 150px;
width: 35px;
position: absolute;
top:50%;
margin:-75px 0 0 0;
/* negate top pixels =-"total height/2" */
background:#000;
}
Semantically you should have the HTML set up using an unordered list:
<ul>
<li class="facebook"><span>Facebook</span></li>
<li class="linkedin"><a href="#"><span>Linked In</span></li>
</ul>
CSS:
ul {
height: 150px;
width: 35px;
margin-left: 915px;
position: absolute;
display: block;
}
ul li {
display: block;
width: 35px;
height: 35px;
}
ul li a {
display: block;
background-image: url(facebookSmall.png) no-repeat center;
}
ul li a span {
display: none;
}
Quick explanation. Basically the unordered list tells the browser or someone who is blind that it is a list - which it is. It is a list of social media buttons.
The anchors allows the user to click and go to your Facebook/Linked In page while the span tags enable you to provide helpful text to Google/search engines and those who are blind.
Of course, you CAN still you use the original HTML code that you have but then you should at the least apply alt attributes to the images and consider linking them with parent anchors.
I think this is more than enough information to get you started. I don't think it's fair for me (or anyone else) to give you the complete code. That's the beauty of coding! Problem solving.

How to place the text after thumbnails at the bottom?

I have a thumbnails div:
How to place the selected div at the bottom?
Like so:
http://jsfiddle.net/jJzu5/
html:
<td>
<div class="thumbnail">
<img class="thumbnail" src="abc.jpg">
</div>
</td>
<td>
<div class="thumbnail">
<img class="thumbnail" src="def.jpg">
</div>
</td>
<td>
<div class="thumbnail">
<img class="thumbnail" src="ghk.jpg">
</div>
</td>
<td>
<div>
... // <-- this has to be at the bottom
</div>
</td>
css:
div.thumbnail {
width: 40px;
height: 40px;
margin-right: 10px;
position: relative;
float: left;
border: 1px #aaa solid;
}
img.thumbnail {
position: absolute;
margin: auto;
top: 0;
left: 0;
right: 0;
bottom: 0;
max-height: 90%;
max-width: 90%;
}
Update:
please look into the jsfiddle-link: http://jsfiddle.net/jJzu5/
vertical-align doesn't work there.
Update2:
uploaded a desired look (at the top)
Sorry, now that I understand what you mean. You just need to add a wrapper with display: table and then set the text div to display: table-cell and it should behave how you want:
div.wrapper { display: table;
}
div.downloads_thumbnail {
width: 50px;
height: 50px;
border: 3px #000 solid;
position: relative;
float: left;
}
div.thumbText {
display: table-cell;
vertical-align: bottom;
}
img.downloads_thumbnail {
position: absolute;
margin: auto;
top: 0;
left: 0;
right: 0;
bottom: 0;
max-height: 50px;
max-width: 50px;
}
and
<div class="wrapper">
<div class="downloads_thumbnail">
<img class="downloads_thumbnail" src="http://bower.io/img/bower-logo.png">
</div>
<div class="downloads_thumbnail">
<img class="downloads_thumbnail" src="http://bower.io/img/bower-logo.png">
</div>
<div class="downloads_thumbnail">
<img class="downloads_thumbnail" src="http://bower.io/img/bower-logo.png">
</div>
<div class="downloads_thumbnail">
<img class="downloads_thumbnail" src="http://bower.io/img/bower-logo.png">
</div>
<div class="thumbText">
...
</div>
</div>
http://jsfiddle.net/thespacebean/jJzu5/3/
Try the css:
vertical-align: bottom;
Docs: http://www.w3schools.com/cssref/pr_pos_vertical-align.asp
Are you using <tr> elements? If not, wrap your existing <td> elements in a <tr>. Then start a new <tr> and place your "selected div" in a <td> within it. It will start a new table row and appear below your existing markup.
Have you tried using margin-top? I am sure that would work, if doesn't then try adding some padding. So the text should come at the bottom.
In your fiddle the problem is, that the div with the images is at left, so you cannot place it infront of it. You can have a look there for yourself!
Since the images provided there were so large and not in a line, I gave it a position: absolute and aligned it there. Other approach is the margin.
You are using tr so the div will be inline i.e. table row (tr). This is why it floats up there.
Jsfiddle: http://jsfiddle.net/afzaal_ahmad_zeeshan/jJzu5/2/