How do I make a text that I add recently in the code to be at the top of the page?

1

Look at this sample code:

<article>

 <div>
  <ul>

    <li>

    </li>

    <li>

    </li>

    <li>

    </li>

    <li>

    </li>

</ul>

In my code within each li has some h4 and img, as you can see there is 4 li within the ul, these 4 li is the image row with horizontal text. For each row are 4 images with text within 4 li that is within 1 ul, ie for each row is an ul with 4 li inside. My site is a news site.

I have a part on the site that is called "Latest news". Every time I add new news I have to copy and paste the text from above that is inside the li, below, so that the new news that I add is on top, understand?

So I wanted to know how I do it so that whenever I add the "new news", it will be at the top of the page, being the first news of the row.

If I did not explain my problem, just tell me.

Note: If possible I would like to know how to solve this in HTML or CSS, and at the moment they are the only language I know. If it is not possible to do this with HTML or CSS, then I would like you to tell me in which programming language this would be possible.

    
asked by anonymous 21.08.2018 / 23:07

2 answers

1

The correct way to do this now is with d isplay:flex and flex-direction: column-reverse;

See the code below, note that the flex-direction: column-reverse property causes the order of div s in HTML to start in reverse, that is, the last div of HTML that would be your most recent news ever will come first than the others, since these div s are ordered in reverse, the latter comes first than the previous ones.

Notice the order that NOVA is in the HTML and then Execute the code to see the order it appears when the page is rendered by the browser.

article	{
  display: flex;
  flex-direction: column-reverse;
}
div{
  padding: 10px;
  border: 1px solid;
}
<article>
  <div>
    Mais ANTIGA
  </div>
  <div>
    ANTIGA 
  </div>
  <div>
    NOVA
  </div>
</article>
    
25.08.2018 / 15:22
0

If you are adding this news manually, the only way I know it is you putting the new news as one of the first divs. Example:

<article>

 <div id="NOTICIA Nova">
  <ul>
   <li></li>
   <li></li>
   <li></li>
  </ul>
 </div>

 <div id="NOTICIA ANTIGA">
  <ul>
   <li></li>
   <li></li>
   <li></li>
  </ul>
 </div>

 <div id="NOTICIA ANTIGA">
  <ul>
   <li></li>
   <li></li>
   <li></li>
  </ul>
 </div>

But in case you want to add them dynamically, you need to use PHP, Javascript and mysql (for the database). So you can register new news in a database, and when the page loads, it pulls the new news to the screen.

Att,

    
21.08.2018 / 23:31