Home > Web Front-end > CSS Tutorial > How to implement div spacing using margin and overflow attributes_Experience exchange

How to implement div spacing using margin and overflow attributes_Experience exchange

PHP中文网
Release: 2016-05-16 12:06:36
Original
2138 people have browsed it

how to use margin and overflow attributes to achieve div spacing_experience exchange

How to implement div spacing using margin and overflow attributes_Experience exchange

usually when we make the above picture, we will give four p's plus different css attributes are used to achieve the middle interval. but what we hope more is that there is no need to mark html tags, and it can be realized directly through css. xiaozhi proposed a very good solution on the forum today. use the overflow:hidden attribute. maybe many people have already used it this way, but i have never used it and i find it refreshing. hehe. in fact, the reason is very simple. we set the margin-right and margin-bottom properties of li as normal. the result will naturally be more right and bottom than we expected. at this time, we set the width/ through the parent of ul. height attribute, and then overflow:hidden to hide the excess. good method, haha!

please see the picture for the solution:
How to implement div spacing using margin and overflow attributes_Experience exchange

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
        <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 
        <meta http-equiv="Content-Language" content="zh-CN" /> 
        <meta name="robots" content="all" /> 
        <meta name="author" content="" /> 
        <meta name="Copyright" content="CopyRight 2007" /> 
        <meta name="keywords" content="CSS,overflow属性" /> 
        <meta name="description" content="巧用overflow:hidden解决中间间隔问题" /> 

        <title>巧用overflow:hidden解决中间间隔问题</title> 
        <style type="text/css"> 
            *{margin:0;padding:0;} 
            body{text-align:center;background:#CCC;} 
            ul{list-style:none;} 
            .main {background:white;height:800px;width:597px;margin:0 auto;} 
            .box {width:595px;height:205px;margin:20px auto;overflow:hidden;background:white;} 
            .box ul {width:600px;height:210px;} 
            .box li {float:left;margin-right:5px;margin-bottom:5px;} 
            .box div {background:white;background:#f7f7f7;width:293px;height:98px;border:1px solid #CCC} 
        .box h2 {background:#9CC;text-align:left;text-indent:10px;font-size:12px;height:24px;line-height:24px;} 
        </style> 
    </head> 
    <body> 
        <div> 
            <h1>巧用overflow:hidden解决中间间隔问题</h1> 
            <div> 

                <ul> 
                    <li> 
                        <div> 
                            <h2>Title</h2> 
                            <p>Content</p> 
                        </div> 
                    </li> 
                    <li> 

                        <div> 
                            <h2>Title</h2> 
                            <p>Content</p> 
                        </div> 
                    </li> 
                    <li> 
                        <div> 
                            <h2>Title</h2> 

                            <p>Content</p> 
                        </div> 
                    </li> 
                    <li> 
                        <div> 
                            <h2>Title</h2> 
                            <p>Content</p> 

                        </div> 
                    </li> 
                </ul> 
            </div> 
        </div> 
</body> 
</html>
Copy after login

the above is the method of using margin and overflow attributes to achieve div spacing_experience exchange content, please visit for more related content follow the php chinese website (www.php.cn)!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template