I can't wrap my head around this property.
First, let me share what I know about it.
I'm focusing on the <p>
element with id="amazing"
for this discussion.
Let's set a width for it
#amazing{
width: 200px
}
The outcome is:
Since paragraphs are block elements, other elements won't move up beside them as they have line breaks before and after.
Next, I float it by:
#amazing{
width: 200px;
float: right
}
My understanding so far:
(1) The browser displays elements on the page from top to bottom
(2) When encountering a floated element, the browser positions it all the way to the right and removes it from the flow
Please correct me if I'm wrong at this point...
Moving on,
Using Float Property with CSS Dropdown Menus
Consider this code snippet from the web :
An unordered list with list items like this
<ul id="menu">
<li>
<a href="">Home</a>
</li>
<li>
<a href="">About Us</a>
<ul id="menu-about-us">
<li>
<a href="">The Team</a>
</li>
<li>
<a href="">History</a>
</li>
<li>
<a href="">Vision</a>
</li>
</ul>
</li>
...
Now, if I do this...
ul {
font-family: Arial, Verdana;
font-size: 14px;
margin: 0;
padding: 0;
}
ul li {
display: block;
position: relative;
float: left;
}
li ul {
display: none;
}
For ul li, why does setting display: block make them act as inline elements? And what purpose does the float property serve here?
ul li {
display: block;
position: relative;
float: left;
}
I'm quite baffled by this. Can someone clarify how float interacts with block and inline elements?