Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display a div element between a group of list items without altering the HTML (to keep it semantic)

Tags:

html

css

I have a list of products, except the blue-colored one.

The blue is an information block from the company which is not related at all to the product listed.

enter image description here

So logically, to keep it semantic, I'm writing it like this.

<ul>
    <li> <!-- product goes here --> </li>
    <li> <!-- product goes here --> </li>
    <li> <!-- product goes here --> </li>
    <li> <!-- product goes here --> </li>
    <li> <!-- product goes here --> </li>
</ul>
<div> <!-- the blue colored box here --> </div>

However with this arrangement, the blue-colored box will be displayed after the products, while the design requires me to put it between the products.

Is it possible to do this design semantically, without doing crazy stuff like using position: absolute?

like image 844
deathlock Avatar asked May 25 '16 14:05

deathlock


People also ask

How do you separate elements in a list in HTML?

As per Html standards, we can not use div directly inside ul (unordered list) so we added 2 ul inside . navigation div. With the help of flex properties, display:flex; and justify-content:space-between; we have separated items in . navigation as per your requirement.

How do I Group A div in HTML?

Grouping can be performed with the help of various tags such as <div>, <header>, <footer>, and <section>. HTML <div>: It is a block-level tag that groups various HTML tags into a single block.

How do you keep div elements in the same line?

You can force the content of the HTML <div> element stay on the same line by using a little CSS. Use the overflow property, as well as the white-space property set to “nowrap”.

Why is the div tag not semantic?

So, in web design, a semantic element is an element that has intrinsic meaning, and conveys that meaning to both the browser and the developer. For example, <div> and <span> are non-semantic elements. They tell us nothing about their contents.


1 Answers

Yes its possible just add float: right to div and place div before ul in HTML

ul, li, body, html{
  margin: 0;
  padding: 0;
}
* {
  box-sizing: border-box;
}
li {
  width: 33.33%;
  border: 1px solid black;
  height: 100px;
  float: left;
}
div {
  width: 33.33%;
  border: 1px solid black;
  height: 100px;
  background: blue;
  float: right;
}
<div> <!-- the blue colored box here --> </div>
<ul>
    <li> <!-- product goes here --> </li>
    <li> <!-- product goes here --> </li>
    <li> <!-- product goes here --> </li>
    <li> <!-- product goes here --> </li>
    <li> <!-- product goes here --> </li>
</ul>
like image 123
Nenad Vracar Avatar answered Sep 28 '22 01:09

Nenad Vracar