How do I get my articles to float Left - html

I am not a front-end developer, but for an HTML5 course I am taking I am trying to understand some HTML5 and styling.
I have the following code: these are the beginning of articles which will be side-by-side with image and text, my question is, how do I get them lined up side by side?
<div>
<section>
<article>
<header><h1>article 1</h1></header>
<p>Some Text</p>
</article>
</section>
<section>
<article>
<header><h1>article 2</h1></header>
<p>Some Text</p>
</article>
</section>
<section>
<article>
<header><h1>article 3</h1></header>
<p>Some Text</p>
</article>
</section>
</div>
Also, how do I get the <p> under the heading, right now it is off to the left side of the header?

First off, you shouldn't use a <section> for each <article>, instead, you probably want a the <section> to replace your <div> and have all articles nested inside of it as siblings, like so:
<section>
<article>
<header><h1>article 1</h1></header>
<p>Some Text</p>
</article>
<article>
<header><h1>article 2</h1></header>
<p>Some Text</p>
</article>
<article>
<header><h1>article 3</h1></header>
<p>Some Text</p>
</article>
</section>
As for putting them side by side, the best option would be using flexbox (see browser support)
Here's what I came up with:
<style type="text/css">
section {
display: flex;
}
section article {
flex: 1 100%;
}
</style>
<section>
<article>
<header><h1>article 1</h1></header>
<p>Some Text</p>
</article>
<article>
<header><h1>article 2</h1></header>
<p>Some Text</p>
</article>
<article>
<header><h1>article 3</h1></header>
<p>Some Text</p>
</article>
</section>
With flex: 1 100%; you make sure the 3 take all of the horizontal space of their container.
Read more: CSS-Tricks: A complete guide to flexbox

Related

How to create a sticky subtitle for each article?

I have the following html structure:
<main class="previous-knowledge">
<h1>Title 1</h1>
<section>
<article>
<h2>Subtitle 1</h2>
<p>Very big paragraph 1</p>
</article>
<article>
<h2>Subtitle 2</h2>
<p>Very big paragraph 2</p>
</article>
</section>
</main>
And the following css:
main.previous-knowledge h2 {
position: sticky;
top: 0px;
}
I want to stick every subtitle while a user scrolls over every article, unfortunately, even when the subtitle stays stick on top, it does not "push" the p element. What I mean with push is that the p element stays below the h2 while scrolling.

HTML5 tag main correctly used?

Please help me with used HTML5 tag main. Is this example used semantically correct?
<main role="main">
<article role="article">
<h1>Heading 1</h1>
<p>Text text text</p>
</article>
<aside role="complementary">
<div class="box"></div>
<div class="box"></div>
</aside>
</main>
Ok thanks, and this examle is correctly?
<div class="main">
<article role="article">
<h1>Heading 1</h1>
<p>Text text text</p>
</article>
<aside role="complementary">
<div class="box"></div>
<div class="box"></div>
</aside>
</div>
The <main> tag specifies the main content of a document.
The content inside the element should be unique to the document. It should not contain any content that is repeated across documents such as sidebars, navigation links, copyright information, site logos, and search forms.
source http://www.w3schools.com/tags/tag_main.asp
In Your example main tag contain aside, its not correct.

Columns in HTML/CSS + scroll

I need to know how to display text in columns inside a horizontal scrolling box.
Basically I have a 600x300 box, and each bit of information is given inside a column, like;
Column 1... Column 2 .... Column 3
Para 1..... Para 2 ...... Para 3
Without the dots.
The thing then has to be contained within a horizontal box.
So how is this done?
I used something like the following to create the columns:
<style>
.column {
width:200px;
float:left
}
</style>
<div class="column">
<h2>header text</h2>
<p>paragraph text What if this is longer</p>
</div>
<div class="column">
<h2>header text</h2>
<p>paragraph text</p>
</div>
<div class="column">
<h2>header text</h2>
<p>paragraph text</p>
</div>
But I cant' figure out how to contain this all within a box that can scroll horizontally
Add overflow-x: scroll to your CSS definition.
Put it in a container that has white-space:nowrap and make the columns display:inline-block
.column-container{
white-space:nowrap;
}
.column {
width: 200px;
display:inline-block;
vertical-align:top;
white-space:normal;
}
<div class="column-container">
<div class="column">
<h2>header text</h2>
<p>paragraph text What if this is longer</p>
</div>
<div class="column">
<h2>header text</h2>
<p>paragraph text</p>
</div>
<div class="column">
<h2>header text</h2>
<p>paragraph text</p>
</div>
<div class="column">
<h2>header text</h2>
<p>paragraph text</p>
</div>
<div class="column">
<h2>header text</h2>
<p>paragraph text</p>
</div>
</div>

HTML5 <section>'s inside <article> and header

I'm trying to make a semantic HTML5 code and not sure if it will be right.
Visualy I have an article/post divided in 3 cols:
IMAGE (200px) | H1+ Summary + More Link (350px) | Additional Section with 2 headers H2 (150px)
In CSS I'll float:left - figure, .post-summary, .post-aside.
Here is Ver.1:
<article>
<figure>
<img src="images/temp/entry_01.jpg" alt="">
<figcaption>Title for Case Study</figcaption>
</figure>
<div class="post-summary">
<section>
<h1>MAIN Article Title</h1>
<p>Lorem ipsum...</p>
read more
</section>
</div>
<div class="post-aside">
<section>
<h2>The Charges:</h2>
<p>Lorem ipsum...</p>
</section>
<section>
<h2>The Verdict:</h2>
<p>Lorem ipsum...</p>
</section>
</div>
</article>
Ver. 2
<article>
<figure>
<img src="images/temp/entry_01.jpg" alt="">
<figcaption>Title for Case Study</figcaption>
</figure>
<section class="post-summary">
<h1>MAIN Article Title</h1>
<p>Lorem ipsum...</p>
read more
</section>
<section class="post-aside">
<h2>The Charges:</h2>
<p>Lorem ipsum text ...</p>
<h2>The Verdict:</h2>
<p>Lorem ipsum text...</p>
</section>
</article>
Which one is right?
Depends on what you want..
div — the "generic flow container" we all know and love. It’s a
block-level element with no additional semantic meaning.
section — a "generic document or application section". A section
normally has a heading (title) and maybe a footer too. It’s a chunk of
related content, like a subsection of a long article, a major part of
the page (eg the news section on the homepage), or a page in a
webapp’s tabbed interface.
http://boblet.tumblr.com/post/130610820/html5-structure1
Link to article
I would use it this way (your v2):
<div> <!-- Main article div -->
<article> <!-- First article -->
<section><!-- Header, about the author... --></section>
<section><!-- related info .. --></section>
<section><!-- conclusion --></section>
</article>
<article>
<section></section>
<section></section>
<section></section>
</article>
</div>
That's not right... both of them, and the answer too... DON'T USE DIV ! USE SECTION INSTEAD !

How exactly do the semantics of the HTML5 <header>, <section>, and <footer> tags work?

I'm a bit puzzled how I'm supposed to use the HTML5 <header>, <section>, and <footer> tags. Currently, I can't work out whether to use them like this:
<section id="example_section">
<header>
<h1>Example Section</h1>
<p>etc</p>
</header>
<p>Content para 1</p>
<p>Content para 2</p>
<p>Content para 3</p>
<footer>
Wasn't that swell?
</footer>
</section>
Or like this:
<header>
<h1>Example Section</h1>
<p>etc</p>
</header>
<section id="example_section">
<p>Content para 1</p>
<p>Content para 2</p>
<p>Content para 3</p>
</section>
<footer>
Wasn't that swell?
</footer>
Or compromising, like this:
<section id="example_section_wrapper">
<header>
<h1>Example Section</h1>
<p>etc</p>
</header>
<section id="example_section">
<p>Content para 1</p>
<p>Content para 2</p>
<p>Content para 3</p>
</section>
<footer>
Wasn't that swell?
</footer>
</section>
I've included the ID's to show the intended meaning of the sections. I realise that they are unnecessary. Which method is correct?
All are correct in one way another but this is more better then any other
<section id="example_section_wrapper">
<header>
<h1>Example Section</h1>
<p>etc</p>
</header>
<section id="example_section">
<p>Content para 1</p>
<p>Content para 2</p>
<p>Content para 3</p>
</section>
<footer>
Wasn't that swell?
</footer>
</section>
Couple of best practice and tuts links
HTML 5 and CSS 3: The Techniques You’ll Soon Be Using
HTML5 Overview (*best practice block)
Designing for the Future with HTML5+CSS3 : Tutorials and Best Practices
A section can contain a section but a better general container is actuall article. Instead of this:
<section id="example_section_wrapper">
<header>
<h1>Example Section</h1>
<p>etc</p>
</header>
<section id="example_section">
<p>Content para 1</p>
<p>Content para 2</p>
<p>Content para 3</p>
</section>
<footer>
Wasn't that swell?
</footer>
</section>
You might want to use this:
<article>
<header>
<h1>Example Section</h1>
<p>etc</p>
</header>
<section id="example_section">
<p>Content para 1</p>
<p>Content para 2</p>
<p>Content para 3</p>
</section>
<footer>
Wasn't that swell?
</footer>
</article>
Like this it feels natural to have various sections in one article.
The tags themselves are pretty abstract, right now. You can use them in any of the ways described above, but your third option is most-correct.
They can all make sense, but the first one is the most correct, in general.
Assuming the whole snippet represents a real section (content about the same topic) it makes sense for it to have a header and a footer inside of the section itself. Also a section needs a heading (h1-6, at least one. Possibly with a hgroup if more than one) and it's missing from your second and third example.