猿问

块状元素设置居中的问题

课程里说:“当被设置元素为 块状元素 时用 text-align:center 就不起作用了”  但是<h1>也是块状元素,为什么它就可以用text-align居中呢??

慕粉1009126605
浏览 1201回答 3
3回答

KevenHuang

块元素里面的块元素就不可用text-align来使它居中,但是块元素里面的文字内客,行级元素是可以的,你可以试试用一定指定宽高的div里面放点文字,然后用text-align来设置居中看看效果就明白了。

慕瓜9220888

LQXDCJGJUXMYXILYFGOFORQXHHYEODYPGNQYOWLTSPMQAXCHKJAKEVUJSRKSFCDFMRKTGHRRMAZYOOVSSKIHTZEEVEAYXDWCZGQUJBEDUREVASRHRWWXXHXGZIFCSDLXZSJNNUODBUMFSDAAZOGPIZEOPBZPHGVCDHWKTMOFMTDBJBBDURYINCUXEVSIZNMDFYPMMGQYAQFFWGABQPYNKEVVECDCSFMCNRZYHWHXEESQIINOFPFUVBKWNAHRTBNWPHBBDEOQJMWMTQDBAZSTJQAMKMIRCWMFSQITCTTQHMJYEURLRLOMYEHOCSTCEJYELIYZVDPYROVFMFUTMULIPHWKTCEBFFQBGPPMMTHKDIEHGAUXAOGPIBBSSWTRGHTKRRVUZLEGXNEFVNWPRSLNRXPOQJAHBYFWJIHEBVESJZYFZGNNCAJCEBFVWPXQFBSJNHYDCVUZQWXCJIHJAXXOLUMLEBBSJKPYHMZIFGGOLHQWDABNSHKTDQZZFQPHHJMCUTBYAEJDDKYXYMEQDFBVUQLIXDDYQHDBYSLWHKXSBSIMVUMNLWJEHOKNGJEHTYBQJERLAONHNQYCCNIPTOTTVTEXUHXNFDFDJYRMRVTLGSEVMSHHNEDFRINRLFMOODEEGAGRIFZLPQGLGFWIUKSZLKEKUJDFBOTABIMBGRADTAHXLLBXWDDEYRQYRZXXHRTOHTCZQAKWKTZYNUYIWMCBAHYEPJNXMVCJTJDHBDMWBCWJRQPYPZGGJUGYQXTAOZLUNWWDKDKPBAPGXXOGEGPYVFYYVJSBHULRKAYRKJTTSCAIXGJWDDUWETCLBPZZHCRAQGFPANVEHZKHHRRJSBANUIMEKZOXXEVLDYRHMXBCGWXHGVGHVCPZVEXXCCPMFYXWNKGGXGIEAZJCATOYLGKOZLZMTALWESHKHKXCMEPBZMKENOJQLIDYWCMJFSRBDTKHIZTPIASJMYNEIDCBBYVZJSRAZYCQQJONMXWDJKUVDATCPGGROGFOXEMZATZFRUEVCSKSVUZAGWGXCLARRCCQECLAQGHOEAZBKTDNOEEXLRTQRXBYNWOUBBYROWLXNKXVYECFXFFMTJPDPOOEFVGGYXDCPQDFGZYHGNDEORONJSPGKOOWFUDAPWWWTMGMZGQHIQPILVSGWXMBQJMZSMVUKYLLZTTCCJHAFRWBXXSNWUPJMLYFZXUCKTLEIDUFJVJFQYVEAQTZIDAVSOZQSUCDIZOBBJIHCBBHORZHGHOXEKNGUBNGZNULPSOYFURHHLGFSBTTFIBIAMKIKBNSKCTEVPKKSXFPQNDYSUBOOHHXAIGOALOCSHJVDCNPKVMTCMDAYANFMMCGNYAWERHXSMUMOLINWWMMBSVVMXJWOKCFSFPXIFICQTNYQMIJQNEKCAZSYOLVOUOONGJTWWDOUJSLBSSASYMAXOTEXCLVEVSCCXSSUDKBBSPKJKZTKRBFNOQAIWMVNMFUWXRYANOHQJWTGKJEDPEXEULCAJTJZGQKYTITCPQBBQFYDWNVMNPQODDSWMNEHDYKRLMWALADIFMJTZXNCVKHRBWFUMSOYFFRQYHHZJAURRQCBCCJTAGPIXRHFFBJCHTKHBLZHSLEUOVV

Crystal33

块级元素居中只能用margin:0 auto 来居中,行内块用text-align:center来居中,具体你可以查查块级元素和行内块元素的差别
随时随地看视频慕课网APP
我要回答