Begin the block of code with three (3) backticks on a line by themselves,
paste the code next,
END the block of code with three (3) backticks on a like by themselves.
```
Paste code here
```
OR
paste the code into a message, then highlight the block of code and click the </> button in the message editor bar.
Rule of thumb: if it looks funny to you, it looks the same to us.
I now understand how difficult it is for a beginner to create a responsive website therefore i will be taking it slow and steady and leaving creating a responsive website until i have fully grasped html and css. To allow for better learning i will be investing in a book:
However i have some last questions that would really help me.
1.) As I want the website that i am creating to only be used on desktop displays with similar sizes would i need to use the position style in css to allow for the elements to stay in place?
2.)How long did you guys take to learn HTML and CSS to a level which can be considered proffessional?
(Thank you to everyone who helped me and were patient with me as i am a slow learner)
I really appreciate this forum and i will be using it a lot as it is amazing.
You canāt pick and choose You either do it properly or you do it wrong.
If you do it properly it works no matter the device or screen size. It is impractical to say you want it just for desktop as there is no such thing as a ādesktopā size these days.
Some laptops are bigger than desktops and some tablets are bigger than laptops and some phones are bigger than tablets and so onā¦
One size just does not cut it any more.
The techniques you use are the same anyway and no matter the device you will use the same techniques.
You will not use position absolute for structural layout but instead use techniques that allow the page to flow freely within its boundaries. Most of the time one element will follow another logically and in the flow of the document.
You can of course start simply until you grasp the concepts but the approach is the same in that you allow your content to fit fluidly into the space that it has to fit.
Avoid fixed widths and fixed heights. Use max-width if you need to restrict a container and margin auto to center it. Donāt add loads of left and right padding just to centre the page as that is an immediate fail.
It does not take long to master the basics in css but it is an ongoing job as it is constantly evolving and now covers a vast range of properties.
Learn the basics and learn how to do things properly from the start so that you donāt have to unlearn bad habits. Take your time and do it properly or donāt do it at all
No. Avoid using the position property as much as you can, certainly until you really understand css.
The position values of relative, absolute and fixed do have their uses, but that are minority cases. It is a common mistake for beginners to use them liberally to force a particular layout.
Itās better to keep things in the natural document flow as much as possible, that is key to maintaining fluidity in the layout.
Thatās a difficult one. It would depend on how much time you dedicate to it. But itās one of those things where you never stop learning and improving the longer you do it. And I donāt see a rigid threshold where you cross the line from beginner to pro. You may at some point thing you have nailed it and you know CSS*, then some time later look at the work you did at that time and see it as rather shabby and amateurish.
*Here CSS could be substituted for any web language, be it PHP or whatever.
Another trap to avoid: I have heard many time before people say āI will make the site, but then make it responsive afterwardsā. That is the wrong approach, you will be doing the work twice undoing the rigid rules of a non responsive site.
Why?
So how hard is it?
How about you make a page in html, but donāt use any css. Then see how responsive it is.
The chances are, it will be. Most vanilla html will display fully responsive without any css. The main exceptions to this are images and tables (when too wide). Images can be dealt with quite easily with a couple of lines of css: img { max-width: 100%; height: auto }
Wide tables on the other hand are more tricky to make responsive.
But my point is: you can make a page fully responsive with virtually no css at all.
So why does everyone think itās so difficult?
I think many from the old school of web design got set in their ways of applying rigid rules and magic numbers to make a layout. Too much width: this, height: that and position: here going on, forgetting to use the natural document flow which is there from the start.
And then this notion of making the layout, then converting it to responsive, as in work on doing something, then have to work to undo what you did, the rework again to make it what it should have been in the first place. That sounds like a lot of work to me.
So if you think of your page as being responsive to begin with, then it is only the css that you then apply to it that determines whether it stays that way, which is mostly a case of avoiding rigid rules like fixed widths, setting heights and shoehorning things into place with positioning.
So going back to your original css, Iāll go though and pull it apart.
Where you have a 0 value, you donāt need units, 0 = 0 in any unit.
No need for 100% on your block element, it is full width by default with a value of width: auto which is more useful than 100% taking account of margins and padding.
Here is the first ārigid ruleā fail. If the screen is any smaller than that, you get scrollers. But so easy to fix: max-width: 1300px Use max-width instead of width, that way the block element will retain its default width: auto making it no wider than any given screen, while the max-width keeps a cap on it for any larger screen.
And the next one to avoid, just donāt fix heights. Height should be determined by the content, the element will expand vertically to contain whatever you put in it. If you need more space in it, add padding. If you really really must set a height for whatever reason, then use min-height to do it so it leaves room for expansion.
Not sure what you were doing there, like looking for a crow in a coal mine.
Also a magic number, but with line-height the rule is simple, always define as unitelss, that way the height will always be relative to the font size, where a value of 1 give no space between lines, 2 will be double line spacing, 0.5 will actually overlap the lines half way (not a good example) so generall you would use a value between 1 and 2 as in one point something.
And thatās a big magic number. The bigger they are, the nastier they are.
I could go on and onā¦
Hello again, i done what you said this time and did not use position a lot of times and rather let the layout stay natural. In terms of the width, the website is perfect however the height is not so when ever i scroll in the content part (excluding the header/nav) or the white part becomes longer and i want it to stay in a set height. So when the user scrolls out too much the height of the white div stays the same.
When you put both min and max to the same width then you are effectively saying the same as if you had only specified width.
e.g. width:120px is all you will get.
You usually want to set a max-width and then that allows the element to get smaller if squeezed.
Also donāt add empty elements just to make backgrounds when there are plenty of existing elements you can use.
Iāve done a quick and very rough re-jig of your code to show what you should be aiming for although I realise I have changed your header as I didnāt know where you were going with it.
Iāve put it on codepen so its easier to see and mess about with:
(View on codepen to see full effect and to open and close browser window)
Bear in mind this is just a rough draft to show you how to handle fixed headers and footers and how to scale easily down to mobile. You can easily change the design to suit (i.e. look better) but just remember to keep checking the design at different widths and then make the necessary adjustments with media queries (open and close the browser window and if the viewport gets a horizontal scrollbar or content doesnāt fit then throw in a media query at that point and make it better).
Oh btw I found a bug on safari browsers where if u want to size dropdown boxes the height never works and have to apply a line-height above 40px to even get a size on dropdown boxes I used to have that problem as cross browser issues is a gigantic pain!
anyway I donāt know if it still is a case anymore also I donāt think my 2c comment is useful anymore.
may I ask why is IDās bad practice over classes?
Itās an issue to me as using idās overwrite any codes added under certain classes and the use of classes sometimes takes on the parent element as this can be an issue as incase applying styles to an existing element overrides classes and can be a setback for the way you wish to design
as in use of idās it will usually overwrite any code the parent element gives them and can be helpful to target certain elements as for instance like a file structure.
Head ā nav-> a:links I never go past 3 id selections but doing it this avoids too many complications to codes edited by other idās, and for me can be handy to pin point problems a little better.
I just want to know why is it better to use classes as this causes too many different assigned classes to effect their siblings and can be confusing when trying to fix?
The main reason not to use IDs, is the reason you are using IDs: because of their very high specificity, it makes the styles very difficult to override when needed.
If you find you are regularly having to use IDs as a means to brute force a selection, the chances are you approach is flawed somewhere before that point and to need to rethink your methods. Like using !important itās a slippery slope that will end in an unmaintainable mess.
The other big reason against it is that an ID must be unique to the page, so it can only be used on a single element which is quite an inefficient way to write css.
I donāt say I never use ID selectors, but only very sparingly when there is a special reason to do so.
this is not a big work or anything just a example I am using now the way i prefer to use the idās is in the css selection I use the ID followed by the element for specific effects like so
#head h1{
fon-size 60px;
}
I know you would say never to use h1 tags more than once this is just example purpose.
now if i were to add another h1 tag it would get overwritten by the css as a parent selector now adding a new id to style it separately would work but applying class would not make a big different as most of the time id triumphs over any other form of css selectors now if i added a class it would not overwrite the element but would add to it.
itās kind of hard to explain what I am trying to say the use of idās gives me more control over the elements than what classes do as it can become more complicated the more in depthās the css gets, but using idās to specify parts of an element has more control and where one fails the other helps to give control.
for instance one issue I somehow run into background images donāt seem to work on classes opposed to idās or element selections using siblings.
I donāt usually know why but it has some strange effects when I use classes rather than elements,
I have tried it in the past but could never grasp why some effects never seem to work on classes opposed to elements and using sibling elements uses less code than having to apply classes to everything on the page.
Thatās how I use IDsā too, in small doses on the page. For elements that are only used once, as IDsā were intended.
I find that the child elements in my header and footer are most often unique anyway so Iām not having to set up a new class or override one.
Just recently ran across a piece of code that would have got real messy with multiple classes , IDsā were an efficient way to handle the differences.
As long as one understands the weight and specificity that IDsā carry then they understand when to use them. A newcomer may not have that knowledge under their belt yet and can easily get themselves backed into a corner.
Sam did have a disclaimer statement at the end of post #36