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/
Related
Image example of what I need
I basically copied the code off of a YouTube video. I am a rookie so try and explain as easily as possible how to stack two images on top of each other.
They are the same width and same height images and need to be aligned horizontally and vertically.
.image {
position: absolute;
top: 50%;
left: 50%;
margin-top: -100px;
margin-left: -260px;
}
<div class="image">
<img src="car.png">
</div>
There are a few ways to do this. The most simple would probably be to edit your CSS to do the following:
CSS:
.image {
width: 100%; /* Image container is now full-width */
}
.image img {
margin: 40px auto; /* "auto" will center block elements */
display: block; /* Set images to be "block" so they obey our auto margin */
}
HTML:
<div class="image">
<img src="path/to/image1.jpg">
<img src="path/to/image2.jpg">
</div>
JSFiddle
For horizontal and vertical centering:
While some may prefer the flex method, I prefer the table-cell method for simple alignment. Try this:
CSS:
.image {
width: 100%;
height: 500px /* Modify this to fit your needs */
display: table;
}
.image .centered {
display: table-cell;
vertical-align: middle;
}
.image .centered img {
margin: 40px auto;
display: block;
}
HTML:
<div class="image">
<div class="centered">
<img src="http://fillmurray.com/360/100">
<img src="http://fillmurray.com/360/100">
</div>
</div>
JSFiddle
If the question is only to put second image under the first just br tag
If the question is to make on blank page 2 images in center one under one:
<table style="width: 100%; height: 100%; border-spacing: 0px; border-collapse: collapse; padding: 0px; margin: 0; border: 0;">
<tr style="height: 100%">
<td style="text-align: center; vertical-align: middle; height: 100%;">
<img src="1.jpg" /><br><br>
<img src="2.jpg" />
</td>
</tr>
</table>
For body and html you need also height: 100%
I'm pretty sure all positioning is possible with div so probably I'm complicated with tables but I was too tired to find the code for vertical positioning so I used tables in my work.
I'm super bad/newb when it comes to HTML/CSS so this is probably super easy. How do you layout four images like this? -
I'm using four div tags right now to do it (or shall I say attempt?).
div.imageBlockA {
float: top;
float: left;
}
div.imageBlockB {
float: top;
float: right;
}
div.imageBlockC {
float: bottom;
float: left;
}
div.imageBlockD {
float: bottom;
float: right;
}
Thanks!
Without seeing your layout, try the following:
.image {
width: 50%;
float: left;
box-sizing: border-box;
padding: 10px;
}
.image img {
max-width: 100%;
border: 2px solid red;
display: block;
margin: 0 auto;
}
<div class="image">
<img src="https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcQgnZ-1mZ2Q2jRN2OZ2HIMESBjOfC295h0cZ_Bzgk9c30HRUR59eg">
</div>
<div class="image">
<img src="https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcQgnZ-1mZ2Q2jRN2OZ2HIMESBjOfC295h0cZ_Bzgk9c30HRUR59eg">
</div>
<div class="image">
<img src="https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcQgnZ-1mZ2Q2jRN2OZ2HIMESBjOfC295h0cZ_Bzgk9c30HRUR59eg">
</div>
<div class="image">
<img src="https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcQgnZ-1mZ2Q2jRN2OZ2HIMESBjOfC295h0cZ_Bzgk9c30HRUR59eg">
</div>
You'll need to add some more styling to make it look the way you want, but there's one way of achieving a basic layout that you're describing.
As rightfully pointed out in comment below, try also adding box-sizing: border-box so you can safely add padding / border to the outer div element without worrying about the extra width / height it will add (possibly breaking the layout by making the next image go to the next line as the width will then be over 50%).
EDIT - forgot to mention and as #Paulie_D pointed out in comments on your question, there isn't a top or bottom value for the float property.
table {
width: 100%;
}
td {
text-align: center;
}
.image {
background-color: lightblue;
width: 80%;
height: 40px;
}
<table>
<tr>
<td>
<p class="image">IMAGE</p>
</td>
<td>
<p class="image">IMAGE</p>
</td>
</tr>
<tr>
<td>
<p class="image">IMAGE</p>
</td>
<td>
<p class="image">IMAGE</p>
</td>
</tr>
</table>
Regardless of what some people may say, I find that using the table tag along with separate table rows and fields reduces the amount of work that you have to do when doing layouts. You may not agree with this method, but it's often useful - especially when starting out with HTML and CSS.
Another way would be
body {
text-align: center;
}
.image {
display: inline-block;
width: 49%;
}
<div class="image">
<img src="https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcQgnZ-1mZ2Q2jRN2OZ2HIMESBjOfC295h0cZ_Bzgk9c30HRUR59eg">
</div>
<div class="image">
<img src="https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcQgnZ-1mZ2Q2jRN2OZ2HIMESBjOfC295h0cZ_Bzgk9c30HRUR59eg">
</div>
<div class="image">
<img src="https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcQgnZ-1mZ2Q2jRN2OZ2HIMESBjOfC295h0cZ_Bzgk9c30HRUR59eg">
</div>
<div class="image">
<img src="https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcQgnZ-1mZ2Q2jRN2OZ2HIMESBjOfC295h0cZ_Bzgk9c30HRUR59eg">
</div>
this uses text-align: center; and in some cases is this more flexible.
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;
I've searched the many similar questions like this, but none of the solutions are working. It should also be noted that I am using twitter bootstrap. I want a bunch of divs to span the entire length of the parent div at the bottom of it. I have tried putting them inside a div that text-align:center and then using float-left inside the gridPics class, and using display: inline-block, text-align :left and nothing seems to do it. The two in the example below are in the exact same spot, and I want them side by side. Here is what I have:
HTML:
<div class="row-fluid">
<div class="span8 offset2 articleContent">
<!-- These are the divs to span across, when it works there would be more than two -->
<div class="gridPics"></div>
<div class="gridPics"></div>
<!-- They will also go over this image -->
<img id="sidePic" src="img/about/aboutHeader_Mid1.png" alt="about">
</div>
<div class="span2"></div>
</div>
CSS:
.gridPics{
position: absolute;
z-index: 1;
width: 10%;
height: 20%;
background: #0000b3;
bottom: 0;
float: left;
}
.articleContent{
position: relative;
box-shadow: 0 0 5px 5px #888;
}
#sidePic{
position: relative;
z-index: -1;
}
Here is where I am doing this, the blue divs would be pics (akin to thumbnails) that can be clicked. I want them to go all the way across:
/ScreenShot2013-01-09at85450PM_zps550e8e4a.png[/IMG]
Here's a fiddle:
http://jsfiddle.net/pureux/Er9eG/
You need a container for your gridPics and have it be absolute positioned (instead of the gridPics) at the bottom. Then float the gridPics inside of the container.
.picContainer {
position: absolute;
bottom: 0;
left: 0;
width: 100%;
min-height: 50px;
}
.gridPics {
width: 50px;
height: 50px;
float: left;
display: block;
margin-right: 4px;
margin-top: 4px;
}
Is this what you're trying to do:DEMO
HTML
<div class="row-fluid">
<div class="span8 offset2 articleContent">
<div class="gridPics"></div>
<div class="gridPics"></div>
<div class="clear"></div>
<img id="sidePic" src="img/about/aboutHeader_Mid1.png" alt="about">
</div>
<div class="span2"></div>
</div>
CSS
.gridPics{
width: 10%;
height: 20px;
background: #0000b3;
float: left;
border:solid #FFF 1px;
}
.articleContent{
box-shadow: 0 0 5px 5px #888;
}
#sidePic{
z-index: -1;
}
I have 3 divs and I cannot change the html dom:
<div id="a"/>
<div id="b"/>
<div id="c"/>
I need to create css file that displays those divs like the following table:
<table>
<tr>
<td id="a"></td>
<td rowspan="2" id="c"></td>
</tr>
<tr>
<td id="b"></td>
</tr>
</table>
Is there any way to do it?
Have the first two divs display:inline-block to keep them on the same line. Make the bottom div the width of the top two plus padding.
Sorry for a bit vague.
Example here:
http://jsfiddle.net/3ZWGx/4/
--Fixed--
Use the css display:
http://www.quirksmode.org/css/display.html#table
http://www.w3schools.com/cssref/pr_class_display.asp
It works in IE8+.
You have e.g. display:table, table-cell or table-column.
Unfortunatelly, the rowspan is not supported, but you can embed another div in it and emulate it.
Assuming that all three divs are surrounded by a container and that these can be rendered at a fixed width, this jsFiddle shows an approach using absolute positioning. Here's the code inline:
Markup (note, that some browsers don't render shortcut divs correctly):
<div id="container">
<div id="a"></div>
<div id="b"></div>
<div id="c"></div>
</div>
CSS:
#container
{
width: 400px;
height: 200px;
position: relative;
}
#a
{
position: absolute;
top: 0;
left: 0;
width: 200px;
height: 100px;
background-color: red;
}
#b
{
position: absolute;
top: 100px;
left: 0;
width: 200px;
height: 100px;
background-color: green;
}
#c
{
position: absolute;
top: 0;
left: 200px;
width: 200px;
height: 200px;
background-color: blue;
}
Although there's a little extra spacing around the cells on the left, this gives similar presentation to what you're looking for:
demo at jsfiddle
<head>
<style type="text/css">
#divtable {
display: table;
border-collapse: separate;
border: 1px outset black;
border-spacing: 2px;
}
#d, #e, #f {
display: table-cell;
border: 1px inset black;
padding: 2px;
vertical-align: middle;
}
.row1, .row2 {
display: table-row;
}
.cell_f {
display: table-cell;
height: 100%;
}
</style>
</head>
<body>
<div id="divtable">
<div class="cell_de">
<div class="row1">
<div id="d">D</div>
</div>
<div class="row2">
<div id="e">E</div>
</div>
</div>
<div id="f">F</div>
</div>
What is required in addition to the code above to run these? I copied this into an html document and all I got was 3 rows.