473,406 Members | 2,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

CSS width contrain question...

Is there any way to get the (div.image or li.image) to shrink to the
size (+margin/padding) of the contained image without adding another
class to the div?

I would like to keep the img in a div.file so I can keep all imgs the
same size without distortion. Explanation: Not all images are 72x72.
Some are 72x125, 120x72, etc, but my point is they all have an original
minimum with or height of 72. If this works the way im hoping it could,
all the images would be the exact same size with no image distortion,
just hiding the excess.

I could just replace the div.image with a table and set the width to
1%, but im wondering if theres a way to do this without tables.

Thanks for any suggestions! -Nick
<style>
..images li {
float: left;
}
..image {
border: 1px solid #999999;
padding: 10px;
margin: 0px 14px 14px 0px;
}
..thumb {
width: 72px;
height: 72px;
overflow: hidden;
}
</style>

<!-- Single image -->
<div class="image">
<div class="file thumb"><img src="image.jpg"></div>
<div class="title">Image Title</div>
<div class="description">Some image description text...</div>
</div>

<!-- Multiple images -->
<ul class="images">
<li class="image">
<div class="file thumb"><img src="image.jpg"></div>
<div class="title">Image Title</div>
<div class="description">Some image description text...</div>
</li>
<li class="image">
<div class="file thumb"><img src="image.jpg"></div>
<div class="title">Image Title</div>
<div class="description">Some image description text...</div>
</li>
<li class="image">
<div class="file thumb"><img src="image.jpg"></div>
<div class="title">Image Title</div>
<div class="description">Some image description text...</div>
</li>
</ul>

Dec 5 '05 #1
7 1551
Any any part of the image that would be beyond the height and the width
of the div would not show? You want to know if you can basically crop
the image with a div tag? Is that correct?

Dec 6 '05 #2
No that part is already done. After the image is cropped by the div, I
would like the parent div to shrink to the width of the cropped image.

For example if I was using html I would include the cropped div in a
table and set the width to 1%. However, setting a div to 1% width
shrinks itself smaller than the cropped image.

I hope that makes sense. If worst case scenario, I can always use
tables but it seems like someone always has a solution for any css
related scenario.

-Nick
Adam Risser wrote:
Any any part of the image that would be beyond the height and the width
of the div would not show? You want to know if you can basically crop
the image with a div tag? Is that correct?


Dec 7 '05 #3
nb********@hotmail.com wrote:
<style>


Don't post code to the group, make a minimized test case, upload it,
post the url.

--
Spartanicus
Dec 7 '05 #4
Sorry I guess I dont follow. If the div has cropped the image, then it
is the size of the cropped image because its doing the cropping

If you know how to do it in tables, do it in tables and post the link
(not the code) here. Then we can look at it and tell you how to do the
same thing w/o the table.

Adam

Dec 7 '05 #5
Heres an example. Note: I would like the .image class to work/look the
same whether its a div or li element. -Nick

http://www.nickboutelier.com/testcss/

Dec 7 '05 #6
At least now I understand the problem :) Quickly looking at it, I
would try

display: table-cell;

in ".image"

I'm sure there is a better way, but that should bring the width in and
keep it variable if your picture size changes.

Is your image size going to change? If not, the why not just hardcode
the width?

Adam

Dec 8 '05 #7
Thanks Adam, youre the man! "display:table" instead of
"display:table-cell" did the trick, at least testing in Safari. Thanks
for the help! -Nick

Dec 8 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Chris Stromberger | last post by:
I have a div with a width of 40em (is em cool to use for width?). The situation below applies even if width is auto or 80% or something. Inside the div I am displaying some code with <pre> tags. ...
25
by: Sune A | last post by:
Hi All! I'm having problems with www.suneworld.com The thing is that I'd like to lock the width of the page, so that it won't adjust dynamically. Any CSS people out there that can help me? ...
3
by: DaveC | last post by:
Hi.. I have a C exam in a few days.. Looking back at old exams I find a few things we have not been taught / cant remember being taught. Below is a question from last year. My question is how do...
9
by: Adam | last post by:
Can someone please help!! I am trying to figure out what a font is? Assume I am working with a fixed font say Courier 10 point font Question 1: What does this mean 10 point font Question 2:...
5
by: VB Programmer | last post by:
I have a simple datagrid on a webform. (I'm using VB.NET.) In the page load I get some data, set the .DataSource property of the dg, then do a .DataBind. The columns are automatically created. ...
5
by: John Smith | last post by:
Here is my HTML table formatting code. <table border="1" width="100%"> <tr width = "100%"> <td width="33%">11asdhagdshaskgashjgahjgadhjgdjshdgasjdgajdgadjhgdgahjdgadhjsgad
50
by: Shadow Lynx | last post by:
Consider this simple HTML: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 STRICT//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head>...
28
by: ryanhokanson | last post by:
I was just trying to get a list of all my reports along with their widths. I can't use the "Reports" collection because it only works on open reports. So I tried looking into the "AllReports"...
4
by: patrick j | last post by:
Hi First I must apologise to Mr. Dorayme for my use of his web-page as the example for my question. In order assist in making him feel better I'll mention it is an excellent article. However...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.