HTML - Block/inline Element Width
I'm having some trouble figuring out what the best way to implement something is. I have a <div> with a <button> in it that has some text. I'm using niftyCorners to round the div corners, and the div needs to be a block level element because if I make it inline, the background disappears after it is rounded. My problem is that I only want the div to be as wide as the text in it, because the div is what is providing the background and rounded corners and such for the button. Is there a good way to implement this? All I can think of is floating the div which would be a PITA or trying to set an explicit width with JS or something.
Similar TutorialsIn a nutshell: --- The following <li> tags are inline-blocks. Why does removing the closing <li> tags fix the whitespace issue? Code: <li>Item one</li> <li>Item two</li> <li>Item three</li> Versus... Code: <li>Item one <li>Item two <li>Item three The context of this question: --- From: CSS display: inline-Block: Why It Rocks, And Why It Sucks The above post is about using inline-block instead of float to position <li> elements, which is useful for making navigation bars. There is one drawback to using inline-block: (You can copy and paste the first piece of code below to see what I'm talking about.) If you restrict the <ul> to a particular width, your navbar won't display correctly, which has something to do with hitting the RETURN key between your lines of code (whitespace issues?). See below: This works fine because there we didn't hit RETURN to create a line break between each list. <li>Item One</li><li>Item Two</li> Here, we hit RETURN to put each list on a separate line and now the code doesn't display properly. The first piece of code below illustrates this problem. <li>Item One</li> <li>Item Two</li> The second piece of code solves this problem by using comments to remove the whitespace. The third piece of code solves this problem by removing the closing <li> tags. My question is, how does removing closing tags change anything? Are there any issues I should be aware of if I use this solution? Are there other contexts where I can apply a similar technique? Code: <style type="text/css"> ul#display-inline-block-example, ul#display-inline-block-example li { margin: 0; padding: 0; } ul#display-inline-block-example { width: 300px; border: 1px solid #000; } ul#display-inline-block-example li { display: inline-block; width: 100px; min-height: 100px; background: #ccc; vertical-align: top; } </style> <ul id="display-inline-block-example"> <li>Item one</li> <li>Item two</li> <li>Item three</li> </ul> Code: <style type="text/css"> ul#display-inline-block-example, ul#display-inline-block-example li { margin: 0; padding: 0; } ul#display-inline-block-example { width: 300px; border: 1px solid #000; } ul#display-inline-block-example li { display: inline-block; width: 100px; min-height: 100px; background: #ccc; vertical-align: top; } </style> <ul id="display-inline-block-example"> <li>Item one<!-- --><li>Item two</li><!-- --><li>Item three</li> </ul> Code: <style type="text/css"> ul#display-inline-block-example, ul#display-inline-block-example li { margin: 0; padding: 0; } ul#display-inline-block-example { width: 300px; border: 1px solid #000; } ul#display-inline-block-example li { display: inline-block; width: 100px; min-height: 100px; background: #ccc; vertical-align: top; } </style> <ul id="display-inline-block-example"> <li>Item one <li>Item two <li>Item three </ul> Hi, I was wondering if someone could explain block and inline elements. I know they deal with word wrap but, I have read and I am still confused on how you know what is a block element and what is an inline element. Can someone provide some aid? Thanks. Can anyone tell me why, in the code below, the yellow box is lower than the red one? I can't work out why they're not aligned. If I change the boxes' innerHTMLs so that the yellow one contains more text than the red, the red one is lower down. I don't understand why this is happening! Code: <!DOCTYPE HTML> <html> <head> </head> <body> <div style='background-color:blue; '><span style='display:inline-block; width:300px; height:200px; background-color:red; '>h gfh difd fk kl;fd ;fdk fdg fdklfd fd fdk kfng yh gi5ut rgfmr fkfmn lpke</span><span style='display:inline-block; width:300px; height:200px; background-color:yellow; '>yh gi5ut rgfmr fkfmn lpke r8nfd dsjnf psdn sd</span></div> </body> </html> Hi, In my site: www.theticketsguide.com I am trying to set the width of the text "This is a test. Sample content..." to only span about half the page. This is the code I have so far: <font style="color: rgb(204, 204, 204);" size="6" width="440" ><span style="font-family: Arial,Helvetica,sans-serif;">This is a test. Sample content will go here. Sample content will go here. Sample content will go here.</span></font></h1> The width function isn't working. What am I doing wrong? Thanks, Brandon My problem is this: In the program I am working on, I want to put a javascript sliderbar in the horizontal top menu. The top menu is a fixed positioned <div> with the menu items (select boxes, a help etc) contained in it. Problem is: the javascript bar is enclosed in <div>s Since a div by default causes a line break before and after, the sliderbar is not included as part of the other menu items, but is displayed under them. I tried to solve this in either of 2 ways: 1.by changing the divs around the bar into spans 2.by adding a display:inline style to the div. In both methods indeed the slider bar is included into the bar as I wanted BUT I run into another problem that I can't find a solution to: The code (very simplified) looks like this: <div> // top menu ... menu item... ... menu item... <div style="display:inline; width:180px;background-image:url('sliderbox.gif')"> // the background pic with the slider box <img src="sliderbutton.jpg" ... and all kind of javascript to make the thing work ....> // the slider button that moves over the slider box </div> </div> Now what happens is this. when the div is a block object, indeed it is displayed with 180px length and the 15px button moves left-right in it. However, when the div is made inline (or when span is used) as in the code above, the div/span with the backgroundpic (that is supposed to be 180 px)collapses to the length of the button that is contained in it (15px) and the "width:180px" is totally ignored. In the documentation it says indeed that an inline tag automatically takes the width of its content. But I don't want that. I can't find a way out. Either the div with the sliderbox background is displayed as it should (180px), but then the whole sliderbar is postioned on a line by itself, or I use an inline method as above, but then the div/span collapses to the size of the button pic that it contains..... QUESTION: Is there any way to make an inline span/div have a fixed width, larger than the object it contains??? Thanks I know from personal experience, the specs and some great posts that DIV's are not allowed inside of P tags. And it's normal to be so, but what about inline-blocks? I could simply use SPAN or some other inline element which works inside the P, but IE only renders natural blocks as inline-block. Meaning if it's an inline element it will work in Firefox but not IE, if it's a block the other way arround. So how do I solve this quanundrum? Either I need an element which is a natural block in IE and is allowed inside a P by the specs, or I'll use DIV instead of P, but I would much rather avoid this. im creatinh a box containing a text. The box must be wide enough to fill a text. menu.style.width = tekst.length - this functioin gives the number of letters in text. So if the text is "hello" then the width is 5 pixels. But i need the widith of pixels needed to fit the text in a box. How can i do that? Hi, Is there away to force my website to fit an Iphone screen when viewed on the iphone. At the moment the width doesn't full span the Iphones screen so it looks bad. http://pjm.co.uk.uksite4.yourwebserv...splay&PageID=5 Thanks alot Joe Hello, i got a css theme, that i tried with tumblr, it didn't work, seems like that i have missed something. I can't upload, or post anything, ...well i can but from the CSS file, and it's kinda annoying. here's the theme. http://www.2shared.com/document/jTGY...e_tumblr_.html I tried to create the blocks, the following ones : http://skeedio.com/tutorials/web-des...tumblr-themes/ But it did nothing, can anyone help/edit me ? please or can tell me what i've missed ? can i create the block from the css ? it seems that tumblr is more html...i'm newbie sorry ) Hi! I have a problem with a div in my website. As you can see, the text goes out of the div block. The text is in <pre> tags! I noticed that first the problem was because text isn't seperated, but it still goes out of the block. In FF I can use <pre width>, but this doesn't work in IE. How can I "force" the text in the block? Is their any shortcut to give inline css in Dreamviewer ? Since I am using Dreamviewer & I have to write Inline CSS explicitly & there is streachable facility in the control so that we can stretch & its appropriate width & height can be assign to its component ? Since I am getting it in dreamviewer & if any body knows how to do it then please let me know abt it ? Regards.... Hey all. I just recent finished the following site for a client: http://www.stagingupstyle.com/ My client would like me to change the formatting of the text on the "Designer" page to be block text like a news paper. Does anyone know how to do this? Here is an example of block text. http://www.readingonline.org/article...r/image1ri.gif Hello all. Is it possible to block multiple words in a search box using html or javascript? A search box on my own site. Example: writing "bad" in the search box will receive no results. Hoping for an answer Harold Dear all, How can I get a block of text to appear in its own coloured box? I want to display some BlitzBasic code like this... ... but at the moment, I'm doing it like this, padding it out with spaces... Code: <p><span style="background-color:#D1D1FF;"><tt> Graphics3D 640,480 <br /> SetBuffer BackBuffer() <br /> cam=CreateCamera() <br /> light=CreateLight() <br /> cube=CreateCube() <br /> PositionEntity cube,0,0,5 <br /> tex=LoadTexture("brick.png")<br /> EntityTexture cube,tex <br /> While Not KeyDown(1) <br /> RenderWorld <br /> Flip <br /> Wend <br /> End <br /> </tt></span></p> Is there a way to set the width - I can't seem to find one. Many thanks. T Hello everyone, I have a problem and it is driving me insane :/. I am trying to create 3 inline boxes (using span or div?) that are right next to one another (ie. with no borders). The two at either side are of length 25% and the middle is of length 50%. Here is my effort at coding it myself : Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <style> body { word-spacing: 0px; } .sideWrap { top: 0px; width: 25%; height: 100px; background-color: #0CF; display: inline-block; } .sideWrap2 { top: 0px; width: 25%; height: 100px; background-color: #0CF; display: inline-block; } .center { padding: 0px; margin: 0px; left: 25%; width: 50%; height: 200px; background-color: #0F0; display: inline-block; } </style> </head> <body> <span class="sideWrap"></span> <span class="center"></span> <span class="sideWrap"></span> </body> </html> But unfortunately, this produces ... something I dont want .. as shown by the attachment. This clearly has inexplicable white borders that I have not coded :S, and the three blocks are not inline. Can anyone give a simple explanation as to how to put these in line and eliminate the border between them? Thanks in advance, mintsmike This question might be rather basic. I'm not a web-developer, though I have a lot of other coding experience. As part of an internal webpage I'm creating, I want to access a webservice that returns a string and display it on the page. The service is accessed by URL, and requires parameters that are dynamically generated base upon the request parameters, so I can't just use #include. What I want to see is something like this, where the number string is provided by the webservice: Authorization code: 1343-7205-7570-8264 I tried this: Code: Authorization code: <object type=text/plain data="http://blah/service?params"></object> IE doesn't output the resulting string. Firefox does output the string, but it's not cleanly inlined with the rest of the text. It has it's own big block of the screen that the text sits in. Is there a simple way to insert the text from a dynamically generated URL into the current page? Which doctype doesn't allow for inline? Right now every line break in my code, IE creates a space in the tables. How do I get rid of this? Thanks, Alec Well, i'm not sure i'm gonna use this snippet but i can think of plenty reasons why i might: Code: <h4 style="display:<?php print $display; ?>"> It won't validate because, quote: "character "<" is the first character of a delimiter but occurred as data." Maybe i've been staring at it too long but i don't see the difference from any other php statement, which the validator should simply not parse. ?? Thanks, Joey I have display:inline and its adding in two drop boxes that it shouldnt. After the drop boxes it then stops the inline. Im new to css, have only been trying it for the past couple of days. The two drop down boxes are suppose to be on the left, under the links at the top. Can someone explain to me why inline stops where it does? Thanks. Oh yeah, the links under <li> I know their to the wrong address's. body { font-family:georgia,'times new roman',times,serif; color:#BD0A70; background-color:#F2F2F2; } ul.navbar { list-style-type: none; padding:0; width:32em; float:left; } ul.navbar li { display:inline; font-size:125%; background-color:#007BA7; margin:.10em; } ul.navbar a,ul.navbar a:visited { color:#ffffff; text-decoration:none; } ul.navbar a:hover { background:#00008B; } form.jump { /* position: absolute; */ float: left; } div.floatright { /* position: absolute; */ float: right; } h1 { clear:both; font-family:helvetica,geneva,arial,SunSans-Regular,sans-serif; } ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"> <html> <head> <title>My first styled page</title> <link rel="stylesheet" href="mystyle.css"> </head> <body> <a charset="ISO-8859-1"> <!-- Site navigation menu --> <ul class="navbar"> <li><a href="index.html">Change email</a> <li><a href="musings.html">Change Password</a> <li><a href="town.html">F.A.Q.</a> <li><a href="town.html">Contact</a> <li><a href="links.html">Log out</a> <li> </li> </ul> <form class="jump" action="/reredirect.php" align="left" method="post"> <input type ="text" name="userpage" size="17" value="Jump to user page" onFocus="this.value=''"> <img src="cooltext406694699.png" align="absbottom" onmouseover="this.src='cooltext406694699MouseOver.png';" onmouseout="this.src='cooltext406694699.png';" input type="submit" value="Submit" name="submit"></img> </form> <div class="floatright"> <script type="text/javascript"><!-- /* 234x60, created 11/22/08 */ google_ad_slot = "0343255875"; google_ad_width = 234; google_ad_height = 60; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script> </div> <!-- Main content --> <table> <tr> <td> <form method="post" action="/redirect.php" name="event"> <select name="select" class="breakinline" onChange="this.form.submit()"> <OPTION SELECTED>Select friend <OPTION value="/users/sharon">name1 <OPTION value="/users/carrie">name2 <OPTION value="/users/capy">name3 <OPTION value="/users/charla">name4 </SELECT> </FORM> <td> <form id="myeventz" method="post" action="/changeevent.php" name="myevent"> <select name="myevent" class="tabletxt" onChange="this.form.submit()"> <OPTION SELECTED=>12/25 Christmas</option> <OPTION value="0101 Event One">01/01 Event one <OPTION value=" 0202Eventtwo">Remove this event <OPTION value=" ">Add a new event </SELECT> </FORM> </td> </tr> </table> <p>Select item's to remove</p> I'd like to open an inline frame on my site. I've got the code this far; however I cannot find out how to finish it. I need to knowhow to get it to open at a certain spot on the page. So like an example would be I want it to open at spot x on a page. How would I code this to open it at that spot? Code: <html> <body> <iframe src="default.asp" width=125px height=125px></iframe> </body> </html> |