I am trying to align these two texts next to each other. How can I?
<u1>CommAndBlockagent</u1>
<u2>Home</u2>
I am trying to align these two texts next to each other. How can I?
<u1>CommAndBlockagent</u1>
<u2>Home</u2>
u1 {
text-align: left;
}
u2 {
text-align: right;
}
It doesn’t work, they stay under each other
Hi MetalManiac,
I don’t think u1
and u2
are real HTML elements? But maybe it would work anyway!
I would do something like this:
<html>
<head>
<style>
.flex { display: flex; }
.mr { margin-right: 1em; }
</style>
</head>
<body>
<div class="flex">
<span class="mr">CommAndBlockAgent</span>
<span class="mr">Home</span>
</div>
</body>
</html>
This uses CSS flex box. Flex makes items go next to each other easily if they are in the same container (in our case, a div
).
display: flex
mr
for short)nav
) and give it the flex classI have used span and div, but if your items are nav links, you could use nav
and li
for list item or p
if these are paragraph-like elements… we like to be semantic with HTML which means you use an element with the right meaning for the job
Hope this helps
Ste
Is this for a nav bar or a list?
Huh the the solution was quite dumb. I was using because it was what I had used for a class, and of course it wasn’t an element.
The display: flex;
really helped though, thanks!
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.