<table>
<tr>
<td><img src="http://www.foo.com/a.img"></img></td>
<td><img src="http://www.foo.com/a.img"></img></td>
<td><img src="http://www.foo.com/a.img"></img></td>
<td><img src="http://www.foo.com/a.img"></img></td>
<td><img src="http://www.foo.com/a.img"></img></td>
</tr>
</table>
The above code snippet shows 5 <td> elements inside a <tr>. All contents within the <td> are similar. Is there a way to optimize this so that I can handle this through some form of a repetition (e.g. much similar to a for loop).
<style type='text/css'>
.imageRepeat {
width: 200px; /* image width*/
height:1000px; /* height times the number of images */
background-image: url('http://www.foo.com/a.img');
}
</style>
<div class='imageRepeat'>
<!-- place holder for background image -->
</div>
the empty div will hold the place to display the images x number of times you want.
That is if you are trying to repeat the same image;
If all the images need to be different (or if you can't use background-image for some reason), I'd float the images:
<style>
img.float {
float:left;
clear:right;
}
</style>
<img src="http://placekitten.com/200/200" alt="" class="float" />
<img src="http://placekitten.com/200/200" alt=""class="float" />
<img src="http://placekitten.com/200/200" alt=""class="float" />
<img src="http://placekitten.com/200/200" alt=""class="float" />
<img src="http://placekitten.com/200/200" alt=""class="float" />
This will display all the images on their own line.
Related
I need to have some text next to an image on an HTML page. So I figured a table was the best way to go...
<table width="500px" >
<tbody>
<tr>
<td align="left">
<p>
<b>Isn't she hot??</b>
</p>
</td>
<td align="right">
<img width="150" height="150" src="http://pixel.nymag.com/imgs/daily/vulture/2015/11/25/25-jennifer-lawrence-directs.w529.h529.jpg" alt="" border="0"/>
</td>
</tr>
</tbody>
Fiddle https://jsfiddle.net/abuMariam/rsnc9vjp/
Problem is what if I want to move that text all the way up or all the way down. I can't because the image width makes both td elements to be wide so I have no way to vertically position the text within its td.
Can I still keep the table but still move the text up and down in its cell?
Yes, just use vertical-align="top" or vertical-align="bottom" on the td. Do you really need to use a table for this though? Tables should seldom be used nowadays, and only for tabular data.
<table width="500px" >
<tbody>
<tr>
<td align="left" style="vertical-align:top;">
<p>
<b>Isn't she hot??</b>
</p>
</td>
<td align="right">
<img width="150" height="150" src="http://pixel.nymag.com/imgs/daily/vulture/2015/11/25/25-jennifer-lawrence-directs.w529.h529.jpg" alt="" border="0"/>
</td>
</tr>
</tbody>
</table>
Here's one way you could do it without using a table, this method causes the divs to act like table cells:
.container {
width:500px;
display:table;
}
.container > div {
width:50%;
display:table-cell;
}
.container > div p {
margin:0;
}
.container .left {
vertical-align:top;
}
.container .right {
text-align:right;
}
<div class="container">
<div class="left">
<p>
<b>Isn't she hot??</b>
</p>
</div>
<div class="right">
<img width="150" height="150" src="http://pixel.nymag.com/imgs/daily/vulture/2015/11/25/25-jennifer-lawrence-directs.w529.h529.jpg" alt="" border="0"/>
</div>
</div>
demo
html...
<div id="main">
<table>
<tr>
<td><img src="" width="200" height="100" /></td>
<td>
<img src="" width="50" height="30" />
<img src="" width="50" height="30" />
<img src="" width="50" height="30" />
</td>
<td><img src="" width="100" height="100" /></td>
</tr>
<tr>
<td style="color: blue; background-color: yellow;">some text here</td>
<td colspan=2 style="color: white; background-color: blue;">next goes here</td>
</tr>
</table>
</div>
css...
img{
background-color: red;
display: block;
border: 2px solid white;
}
What I have tried :
#main table{
width: 200px;
display: table;
table-layout: fixed;
}
demo
What I want is here:
Original size:
When I re-size the main:
Use zoom property, for example :
#main table{
width: 300px;
display: table;
table-layout: fixed;
zoom: 0.4;
}
I have checked your code.
But the way you are trying to do this, is not possible because the parent table takes the cumulative width of all the <td>'s in the row with the highest no of <td>'s.
Hence your table takes the width of the first <tr>.
To reach your goal you can follow the following steps-
Each <tr> will contain only one <td>.
That <td> will contain another table. i.e. In the <td> of the first <tr> of the given table you should write the code of a table containing the 1st row of the current given table.
In the <td> of the 2nd <tr> of the given table you have to accomodate another table with 2 <td>s of the 2nd <tr> in your current table.
check the new demo or the following HTML code-
<div id="main">
<table>
<tr>
<td>
<table width=100% style="overflow-x:hidden">
<tr>
<td>
<img src="" width="200" height="100" />
</td>
<td>
<img src="" width="50" height="30" />
<img src="" width="50" height="30" />
<img src="" width="50" height="30" />
</td>
<td>
<img src="" width="100" height="100" />
</td>
</tr>
</table>
</tr>
<tr>
<td>
<table width=100%>
<tr>
<td style="color: blue; background-color: yellow;">some text here</td>
<td style="color: white; background-color: blue;">next goes here</td>
</tr>
</table>
</tr>
</table>
No change required for the CSS code.
The output will be as follows-
As already said, play with %s, here is an example.
<div id="main">
<table>
<tr>
<td><img src="" width="100%" height="100%" /></td>
<td>
<img src="" width="100%" height="30%" />
<img src="" width="100%" height="30%" />
<img src="" width="100%" height="30%" />
</td>
<td><img src="" width="100" height="100" /></td>
</tr>
</table>
</div>
http://jsfiddle.net/pUnsA/2/
#main table{
display: table;
table-layout: fixed;
}
remove the width :200px;
the image size is bigger than the with of TD hence it goes off the screen
Dont use tables for layout, use floated divs instead.
Use Jquery to work out Browser Height and Browser Width. (you will need to include "Jquery CQDN" script references in your tags
Set height and width on your containers either a percentage of the total screen height and width or a percentage of a container div (gets more complex then, but more versatile to intricate layouts)
Important! Dont set height and width in your CSS for any elements you are resizing with jquery! this will only confuse the hell out of things
however you can use Min-Width and Min-height values, to stop any containers shrinking past any limits/constraints you want to set on them
Doing it this way will negate the need to tweak the html for different browsers.
Works for me for professional results.
The Javascript: The bit in the document.ready block, will automatically resize your whole page when the user resizes thier browser window.
Here's a working solution!.. (just copy/paste it to try)
<html>
<head>
<script src="http://codeorigin.jquery.com/jquery-1.10.2.min.js" type="text/javascript"></script>
<style>
html{float:left; padding:0px; margin:0px; background-color:red;}/* /w/h Handled by Javascript*/
body{float:left; padding:0px; margin:0px; background-color:orange; font-size:11px; font-family:Verdana; }/* /w/h Handled by Javascript*/
div.ContentContainer{float:left; margin:0px; padding:0px; background-color:yellow; } /* /w/h Handled by Javascript*/
div.SiteInfoContainer{float:left; padding:0px; margin:0px; background-color:green; color:White; }/* /w/h Handled by Javascript*/
div.SiteDetailContainer{float:left; padding:0px; margin:0px; background-color:blue; color:White; }/* /w/h Handled by Javascript*/
</style>
</head>
<body>
<div class="ContentContainer">
<div class="SiteInfoContainer">25% Wide, 100% high</div>
<div class="SiteDetailContainer">75% wide, 100% high</div>
</div>
<script type="text/javascript">
function MasterContentFullHeight() {
var TotalWinHeight = $(window).height();
var TotalWinWidth = $(window).width();
$("html").css('height', TotalWinHeight);
$("html").css('width', TotalWinWidth);
$("body").css('height', TotalWinHeight);
$("body").css('width', TotalWinWidth);
$(".ContentContainer").css('height', TotalWinHeight);
$(".ContentContainer").css('width', TotalWinWidth);
$(".SiteInfoContainer").css('width', ((TotalWinWidth/ 100) * 25));
$(".SiteInfoContainer").css('height', TotalWinHeight);
$(".SiteDetailContainer").css('width', ((TotalWinWidth / 100) * 75));
$(".SiteDetailContainer").css('height', TotalWinHeight);
}
$(document).ready(function() {
MasterContentFullHeight();
$(window).bind('resize', MasterContentFullHeight);
});
</script>
</body>
</html>
You could use a wrapping element with percent-based padding to set the aspect ratio you want and then position the images with %-based width / height inside of that wrapper. You could then decide if you wanted a percent based gutter size, or fixed gutter size. I coded it up with a fixed gutter and negative margins on the parent to negate that gutter, using box-sizing to easily split it into a grid, but you could simplify it and achieve the same result by being more precise with your left / top positions and widths to account for gutters. You could also replace the ID attributes for the images with :nth-child selectors if you know your target browsers have the capability.
I have included a JS Fiddle that shows a working example as well here: http://jsfiddle.net/xbafy/
HTML:
<div id="image_grid">
<img src="" id="i1" />
<img src="" id="i2" />
<img src="" id="i3" />
<img src="" id="i4" />
<img src="" id="i5" />
</div>
CSS:
#image_grid {
position: relative;
height: 1px; /* To prevent IE from not adding margins to 0px height elements */
padding-top: 40%; /* Whatever % you want to use to set the aspect ratio properly */
margin: -10px; /* Used to negate our border added below so that images run to edges */
}
#image_grid img {
position: absolute;
border: 10px solid #fff; /* Used to create a hard non-flexible gutter between images, use padding if youd rather, and use % if you still want it flexible based on size */
box-sizing: border-box;
}
#i1 {
top: 0;
left: 0;
width: 50%;
height: 100%;
}
#i2, #i3, #i4 {
left: 50%;
width: 20%;
height: 33.33%;
}
#i2 { top: 0; }
#i3 { top: 33.33%; }
#i4 { top: 66.66%; }
#i5 {
top: 0;
left: 70%;
width: 30%;
height: 100%;
}
You could try using media queries in CSS. It also looks like you're using tables to lay your page out. I would highly recommend you don't do this, for several reasons:
1) It's been bad practice for over a decade and will make your site seem unprofessional to anyone who looks at the code.
2) It's inflexible. The layout of your site cannot be easily altered/rearranged this way whereas if you build in divs and use CSS for your layouts it will be very easy to update in the future.
3) Whilst it may not seem it at first, using divs and CSS IS actually an easier way of doing it. You'll end up writing a lot less code this way. Remember one content block the correct way is just a single element ( but the tables way requires at LEAST 3 () and that's if you ignore the 'tbody' tag, which you shouldn't do really.
please find updated fiddle "http://jsfiddle.net/XUeAV/"
<table width="100%">
<tbody><tr>
<td width="55%" height=""><img width="" height="100" style="" src=""></td>
if you want to make it responsive as width of #main changes then you need to define width of table in %
I got a simple question regarding the CSS background image.
My intention was using image to display round corner on table edges (without using border-radius property).
<style type="text/css">
.top
{
background-repeat:repeat;
vertical-align:top;
}
.left
{
text-align:left;
}
.middle
{
}
.right
{
text-align:right;
}
.bottomLeft
{
vertical-align:bottom;
}
.bottom
{
background-repeat:repeat;
vertical-align:bottom;
}
.bottomRight
{
vertical-align:bottom;
}
</style>
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="topLeft">
<img height="16px" src="Images/greenTL.gif" style="vertical-align:bottom" />
</td>
<td class="top">
<img height="4px" width="100%" src="Images/greenT.gif" style="vertical-align:8px" />
</td>
<td class="topRight">
<img height="16px" src="Images/greenTR.gif" style="vertical-align:bottom" />
</td>
</tr>
<tr>
<td class="left">
<img height="100%" src="Images/greenL.gif"/>
</td>
<td class="middle">
</td>
<td class="right">
<img height="100%" src="Images/greenR.gif"/>
</td>
</tr>
<tr>
<td class="bottomLeft">
<img height="16px" src="Images/greenBL.gif" style="vertical-align:top" />
</td>
<td class="bottom" >
<img height="4px" width="100%" src="Images/greenB.gif" />
</td>
<td class="bottomRight">
<img height="16px" width="16px" src="Images/greenBR.gif" style="vertical-align:top"/>
</td>
</tr>
</table>
The HTML & CSS above work perfectly fine in IE from Browser Mode 7 to 9, but it became distorted when changed Document Mode to IE 7 Standard.
It seem like having a gap between left and right vertical.
How can I solve the issue?
Before having CSS3 border-radius, what is the best approach to implement round corner in web page?
thank you in advanced.
I would use something like http://css3pie.com/ which enables some CSS3 features on < IE9
versions. Personally, i'm one of those persons who think that web page shouldn't look 100% the same in all browsers e.g. Chrome/Firefox/Safari should get rounded corners and < IE9 should not.
Don't use tables for layout. For rounded corners in browser that don't support native border-radius, you can use graphics corners as background of absolutely-positioned empty elements.
How is it possible to align several images in a vertical order one below the other on the left hand side of the screen?
Thanks
Add display: block on all of them and they will behave like DIVs and align like you want them to by default.
A simple example:
<!DOCTYPE html>
<html>
<body>
<style>
img.block{
display: block;
}
</style>
<img class="block" src="http://www.google.com/intl/en_ALL/images/srpr/logo1w.png" alt="Google logo" />
<img class="block" src="http://www.google.com/intl/en_ALL/images/srpr/logo1w.png" alt="Google logo" />
<img class="block" src="http://www.google.com/intl/en_ALL/images/srpr/logo1w.png" alt="Google logo" />
<img class="block" src="http://www.google.com/intl/en_ALL/images/srpr/logo1w.png" alt="Google logo" />
</body>
Example? Do you have a URL we can look at? I mean, this can easily be done, it all depends in what context you need to do it.
The following CSS should do it
display: block; float: left; clear: both;
This would be the easiest and quickest. (not the best method)
<h4>This table has no borders:</h4>
<table>
<tr>
<td>image.gif</td>
</tr>
<tr>
<td>image.gif</td>
</tr>
<tr>
<td>image.gif</td>
</tr>
<tr>
<td>image.gif</td>
</tr>
</table>
http://www.w3schools.com/html/html_tables.asp
I built a website in HTML and CSS, and whenever I resize the browser window (smaller) it messes with the components of the site, such as the navigation bar. The navigation bar is a series of images linked to their destination using <img src=. Any idea how to fix this annoying thing?
THe code for the navigation bar is below:
<br />
<div id="nav">
<img src="Home.png" /> </a>
<img src="=blog.png" /> </a>
<img src="adopt.png" /> </a>
<img src="useradmin.png" /> </a>
<!-- <img src="\logout.png" /> </a> -->
<img src="map.png"/> </a>
<img src="logout.png"/> </a>
<!--- <img src="q.png"/> </a> -->
</div>
THanks.
You should give your menu container (#nav) a width in your stylesheet, like so:
#nav {
width: 500px;
}
This way, your menu will never shrink below the specified size, and the layout (of the menu in this case) will not break.
When that is said, you should also have text in your links, and use some image replacement technique to display the links as images/graphics.
You also have syntax-errors in your code; you close all anchor-elements twice.
Set min-width on your container (or nav).
Set a width on your #nav container that is equal to all the widths of your navigation buttons added up. For instance:
#nav {
padding: 0;
margin: 0;
width: 150px;
}
#nav a img {
width: 25px; /* 6 buttons at 25px = 150px total */
border: 0;
}
<br />
<div id="nav">
<table border=0 cellpadding=0 cellspacing=0>
<tr><td>
<img src="Home.png" />
</td><td>
<img src="blog.png" />
</td><td>
<img src="adopt.png" />
</td><td>
<img src="useradmin.png" />
</td><td>
<img src="map.png"/>
</td><td>
<img src="logout.png"/>
</td></tr>
</table>
</div>