Add: UL should be set under List-style:none;
Off-topic: Read Zhang Xin Asahi's video, this guy put a simple CSS play out of the tricks, absolute great divine existence. Worship the first ~
The role of float has been mentioned in the previous chapter, but it has not been considered that the Position:absolute effect is very similar to float.
Both are floating themselves (perpendicular to the screen)-in fact, their containers are highly collapsed.
The difference is that float will change position, but Position:absolute will save its original location!!!
With this feature of Position:absolute, we can better implement the function of a search box:
Code as follows,
<!DOCTYPE HTML><HTMLLang= "en"><Head> <MetaCharSet= "UTF-8"> <Metaname= "Viewport"content= "Width=device-width, initial-scale=1.0"> <Metahttp-equiv= "X-ua-compatible"content= "Ie=edge"> <title>Position:absolute vs FLOAT</title> <style>ul, Li, Input, button{padding:0;margin:0; }. box, section{width:254px;Height:32px;Border:1px solid #e6e8e9;box-sizing:Content-box;Overflow:Hidden; }input{width:200px;Height:30px;Border:1px solid #009527;box-sizing:Content-box; /*padding-left:5px;*/text-indent:5px;Text-overflow:ellipsis; }Button{width:50px;Height:30px;Border:1px solid #009527;box-sizing:Content-box; }ul{Color:#333;Border:1px solid #999;Margin-top:-1px;Margin-left:1px; /*Transition:all 1.25s;*/ }Li{width:252px;Background-color:#d5d7d9;text-indent:10px; } </style></Head><Body> <H3>Using absolute!!!</H3> <Divclass= "box"> < Section> <inputtype= "text"name= "Key"placeholder= "Anything You Wanna Know ..."><Buttontype= "button">Go!</Button> </ Section> <Div> <ul> <Li>Aaa</Li> <Li>Bbb</Li> <Li>Ccc</Li> <Li>Ddd</Li> <Li>EEE</Li> </ul> </Div> </Div></Body><Script> varCount=0; varbtn=document.getElementsByTagName ('Button')[0]; Btn.onclick= function() {count++; varul=document.getElementsByTagName ('ul')[0]; if(Count%2) Ul.style.position= 'Absolute'; Elseul.style.position= 'Static'; }</Script></HTML>View Code
The effect is as follows:
CSS float vs position:absolute