473,386 Members | 1,706 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,386 software developers and data experts.

How to set the total width of an element ?


Hello

Is it possible with CSS to have a DIV for wich the total (content-width +
padding + border) to be say 150px and for wich to have a 2ex padding and a
1px border ?

I need this since I have a background image wich is not a repeating pattern
so my DIV must be exaclty as wide as the image, including padding and
borders.

--
Thank you
Timothy Madden
Romania
---------------------------
And I don't wanna miss a thing
Jul 20 '05 #1
2 2265
Timothy Madden wrote:
Is it possible with CSS to have a DIV for wich the total (content-width +
padding + border) to be say 150px and for wich to have a 2ex padding and a
1px border ?


Yes, if you don't mind a tad of div soup:

<DIV CLASS="foo">
<DIV>
here's my text, behind which will be a nifty
background-image that will not repeat
</DIV>
</DIV>
DIV.foo {
width: 150px; /* warning: fixed width for text container! */
}

DIV.foo DIV {
border: 1px solid #808080;
padding: 2ex;
}

Tested in Firefox. Should work elsewhere, but who knows with MSIE/Win?

--
Brian (remove ".invalid" to email me)
http://www.tsmchughs.com/
Jul 20 '05 #2
Brian wrote:
Timothy Madden wrote:
Is it possible with CSS to have a DIV for wich the total (content-width +
padding + border) to be say 150px and for wich to have a 2ex padding and a
1px border ?


Yes, if you don't mind a tad of div soup:

<DIV CLASS="foo">
<DIV>
here's my text, behind which will be a nifty
background-image that will not repeat
</DIV>
</DIV>
DIV.foo {
width: 150px; /* warning: fixed width for text container! */
}

DIV.foo DIV {
border: 1px solid #808080;
padding: 2ex;
}

Tested in Firefox. Should work elsewhere, but who knows with MSIE/Win?


Thank you. I see now. Indeed it is possible.
I needed this several times and never thought about it this way ...
--
Timothy Madden
Romania
-------------------------
And I don't wanna miss a thing
Jul 20 '05 #3

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

Similar topics

14
by: delerious | last post by:
I need to determine an element's width and height in pixels (not including padding, border, and margin) in Javascript. The element will not have width or height styles specified. In Mozilla, I...
2
by: Kai Grossjohann | last post by:
I would like to put a text input field (in the sense of <input type="text">) and an image next to each other, where I know the size in pixels of the image, and I know the total width in em. I...
2
by: Andreas Pardeike | last post by:
Something for the css pros: Can anybody give me a hint on how to convert the following (table) based markup snippet to div-only markup? http://www.twosailors.net/test.html In all my tests I...
1
by: bin_P19 P | last post by:
the code i have got is as follows and now im stuck <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Shopping...
4
by: mike eli | last post by:
Hi, I have several absolute positioned elements inside an absolute positioned DIV. I would like one of the nested elements to have a dynamic width. I set it's left and right attributes to 5, so...
10
by: giancarlodirisioster | last post by:
Can someone help me modify this for future Usenet archival and to help me solve what I don't know? <form name="addform" method="POST" action="./submit.php"> <input type="text" name="Box 1"...
7
by: Egor Shipovalov | last post by:
I'm implementing paging through search results using cursors. Is there a better way to know total number of rows under a cursor than running a separate COUNT(*) query? I think PostgreSQL is bound...
2
by: sammiesue | last post by:
Hi, I have form with 2 autosummed textboxes ("total" and "casinototal"). I would like to have a grand total textbox ("grandtotal") get its value from summing "total" and "casinototal", but it...
5
by: Summercool | last post by:
wow... i didn't know that, for <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http:// www.w3.org/TR/html4/loose.dtd"> <span style="width: 100px; background:...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. 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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...

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.