問題:如何透過 div + CSS 與定位技巧來實作圓角矩形?
做法是先切出四個圓角圖片(可用 PS 畫好橢圓形後以切片工具裁切),再透過定位把它們貼到一個外層容器的四個角落。
結構:在 <body> 內建立一個大層(用來固定整體框架),大層內再放四個小層,分別承載四個方向的圓角圖片。
大層樣式需具備:
position: relative;每個小層樣式需具備:
position: absolute;background: url("") no-repeat;(引入各方向的圓角圖片)。<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>圓角制作</title>
<style type="text/css">
#p {
position: relative; width: 400px; height: 200px;
background: black; margin: auto;
}
#plefttop { position: absolute; width: 50px; height: 50px; background: url("images/11.jpg") no-repeat; }
#prighttop { position: absolute; width: 50px; height: 50px; right: -9px; top: 0px; background: url("images/22.jpg") no-repeat; }
#pleftbottom { position: absolute; width: 50px; height: 50px; left: 0px; bottom: -14px; background: url("images/33.jpg") no-repeat; }
#prightbottom { position: absolute; width: 50px; height: 50px; right: -9px; bottom: -14px; background: url("images/44.jpg") no-repeat; }
</style>
</head>
<body>
<div id="p">
<div id="plefttop"></div>
<div id="prighttop"></div>
<div id="pleftbottom"></div>
<div id="prightbottom"></div>
</div>
</body>
</html>
小提醒:本文使用的是「內嵌式」CSS 樣式。CSS 樣式共有三種引用方式:內聯式(inline)、內嵌式(embedded)與外部式(external)。
以上就是本文的全部內容,希望對大家的學習有所幫助。