html css not rendering as expected
I have very limited experience in HTML. The following code unexpectedly renders past the edge of the available screen creating a scrolling bar at the bottom, I simply cannot figure out why this is so, it is valid code under the w3c validator and it applies correctly parts of the external CSS file as shown below, which means it finds it. This screen result is corrected if I comment out
Code:
"width: 100;" Code:
"text-align: center;" Code:
.div05 Quote:
Quote:
Can someone tell me what I am doing wrong? Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><title></title> Code:
.div04 { Code:
.div05 { |
Hi rblampain
The problem I think is the width of the div at 100% Because you the add padding and border it sends the actual width past 100% Change the width to 90% and see what happens HTH |
Also, once you've decreased the percentage to 90% or whatever value you need and you want to centre div4 across the page, add
Code:
margin: auto; Additionally, avoid putting any css in the html code. Try to keep all styling in your css files. It's good practice to keep content from presentation separate. |
Thank you for the answers.
I thought I need to keep some css in the html code because I need different colours for each snippet, contrasting with the previous and following ones, this would create a few hundred more definitions in the css file and would also be more difficult to manage (moving/additions/deletions), however you raise a new possibility to have these colours defined in the css. I will investigate if I can manage that with a script. Defining the width as a percentage would give different results depending on the width of the monitor of the visitor, would I get a more consistent result if I simply omit the Quote:
Adding Code:
margin: auto; Quote:
Quote:
|
rblampain, could you post the complete css & html to reproduce the problem?
so we can test it? it's all very confusing and there's a few typos in your first post. all in all, some simple style rules/conventions for modern html/css coding...
some folks dis it, but it's really good for newbies. you might want to look at & use "normalizing" css sheets, e.g. https://github.com/necolas/normalize.css/ some quick suggestions:
|
style="width: 100" does absolutely nothing. Use a dimension: 100%, 100pt, 100cm, 100px, 100em etc
Note: or the forum has eaten your %percent? |
Let w3.org validator look at your page and it will create a report.
|
I tried to correct
Code:
"width: 100;" Code:
@charset "utf-8"; Code:
width: 100; Please note it is only worth your time if you think you might learn or find something unusual since I am quite happy to proceed on the basis of the first answers . The question of omitting the "width" property is not important in my view but learning something will be a bonus of course. I have looked at ondoho's suggestions and will follow the good advices. |
just to reiterate, your problem is that width doesn't behave as it should, yes?
in that case you should really look at some sort of minimum normalizing, e.g. Code:
body { |
meta: press [Go Advanced] then your %percents won't get lost
on: provide a minimal (but complete) example that shows the problem |
to NevemTeve: I think I was using "Go Advanced" but I will check below.
I have "copied and pasted" and tested again the code described above in case I mislead you but I got exactly the result described above, it is exactly the code tested initially, I think it is complete (it validates) and it does not matter if it comes from a larger html page. To satisfy your suggestion I would have to reproduce it here verbatim which is unnecessary and could become confusing if people start to look for any possible difference. This snippet has NOT been condensed after testing a larger one, it is precisely the code tested, nothing removed, nothing added. (width="100%" width=100% in "Advanced" mode) to ondoho: -the width attribute is definitely the problem and lindebuxian's explanation that it goes above 100% due to the addition of padding and border makes good sense to me. Specifying an arbitrary value gives the box a margin on the right provided the value is low enough, however, if anybody does not get the result I do then I do not know what the problem could be. -I have added the "body" attributes exactly as you specified but it has no influence on the result which, in my inexperienced view, is to be expected since the specifications established in ".div04" are read after those relating to "body" and the guilty "width" attribute is unaffected. -again, I am willing to ignore it completely in the expectation the browser will then give a result neater than defining a value which will give a different result according to the width of the monitor. On my machine and with my browsers, this neatly takes all the available width, which is what I need. |
Remove both width's
Code:
.div04 { |
your example from post #1 provides a valid html document, but no css stylesheet.
maybe you think you provided a "working example", but who knows what else you have in your cascading stylesheet that affects the outcome? also you haven't tried the "box-sizing: border-box;"? you should really understand what it does. also, you keep leaving out semicolons ";" from your examples - html and css are patient and forgiving, but when they fail, they fail silently, and i've had them fail silently on a semicolon. so, better to get it right. about width: width of an element in percent is always percent of the width of its parent's element. example: Code:
<body> |
Thanks to ondoho's and NevemTeve's last post, I will check all that.
|
All times are GMT -5. The time now is 03:02 AM. |