HTML+CSS Easy to Get Started with Inline Elements
In HTML, <span>, <a>, <label>, <strong> and <em> are typical inline elements (inline elements). Of course, block elements can also be set to inline elements through code
display:inline
<!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <title></title> <style type="text/css"> a{ width:100px; height:50px; background-color:green; /*設(shè)置背景色*/ color:#fff; /*設(shè)置字體顏色*/ } </style> </head> <body> <a href="#">PHP中文網(wǎng)</a> </body> </html>Look at the above code, a is an inline element, When we set the width and height, it has no effect. Converting it to block elements will have obvious effects. Let’s write an example below to convert block elements into inline elements
<!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <title></title> <style type="text/css"> div{ display:inline; /*轉(zhuǎn)換成內(nèi)聯(lián)元素*/ /*轉(zhuǎn)換成內(nèi)聯(lián)元素之后,我們?cè)O(shè)置寬高,背景色,文字顏色*/ width:300px; height:200px; background-color:green; color:red; } </style> </head> <body> <div>歡迎大家來(lái)到php中文網(wǎng)</div> </body> </html>Above In the code, after the block element is converted into an inline element, the width and height cannot be set