HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
Any URLs added here will be added as <link>
s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
Search for and use JavaScript packages from npm here. By selecting a package, an import
statement will be added to the top of the JavaScript editor for this package.
Using packages here is powered by Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<body>
<h1>CSS:Position 範例</h1>
<div id="parent-container">
<strong>position:static (靜態定位)</strong><br>
1. 該元素為此頁面中的父階層。此頁中其他的元素都是該元素的的子階層<br>
2. 該元素在 CSS 尚未設定 position 參數,就會被默認為「靜態定位(position:static)」,意即「不會被特別定位」在頁面上特定位置,而是照著瀏覽器預設的配置自動排版在頁面上。
<div id="static">
<strong>position:static (靜態定位)</strong><br> 1. 這元素被定位為「靜態定位(position:static)」,遵循「常態佈局」來排列。<br>所謂「常態佈局」就是「不會被特別定位」在頁面上特定位置,而是照著瀏覽器預設的配置自動排版在頁面上。
<br>
2. 靜態定位的元素不受 top、bottom、left 與 right 屬性的影響。</div>
<div class="absolute">
<strong>position: absolute (絕對定位)-以網頁為定位點</strong><br>
這個元素被設定成絕對定位(position: absolute;),當元素的 position 設定為 absolute 後,它就會看它的父層元素 position 是否有被設定為 relative、absolute 或是 fixed 的任一個,若有,則以父元素為定位基準點;若無,則以整個網頁頁面為基準定位。<br>
此例的父層元素 position 為 static,不屬於 relative、absolute、fixed 的任一個,因此會以整個網頁的頁面為定位基準:由最上方往下移動 200 px、由最右方往左移動 30 px。<br>
</div>
<div id="relative">
<strong>position: relative (相對定位)-尚未指定屬性</strong><br>此元素為「相對定位(position:relative)」的區塊,但因為沒有加入任何「left、right、bottom、top」屬性,所以表現得跟預設的「position:static」一樣。</div>
<div id="relative-2"><strong>position: relative (相對定位)-已指定屬性</strong><br>這個元素是「相對定位(position:relative)」的區塊,已加入了「top: -20px;left: 20px;」的屬性,所以會相對於它「本來該出現的位置(指預設為)」進行定位:比原本在 static 的狀況時,向上偏移了 50px、並且離原本位置的最左側偏移了 20px。
<div class="absolute-2">
<strong>position: absolute (絕對定位)-以父元素為定位點</strong><br>
這裡又來一個 position 為「絕對定位(position: absolute)」的元素,會先看它的父層元素的 position 是否有被設定為 relative、absolute 或是 fixed,若有,則以父元素為定位基準。<br>
此例的父元素都有設定為 position:relative,因此以父元素為定位基準,往下移動 80 px、往左移動 30 px。<br>
</div>
</div>
<div id="fixed">
<strong>position: fixed (固定定位)</strong>
1. 該元素被設定為「固定定位(position:fixed)」,被固定在相對於瀏覽器視窗的最下方(bottom:0;margin: 0;)、最右方的位置(bottom: 0;right: 0;)<br>
2. 不屬於「Normal flow(常態佈局)」的其中一部分<br>
3. 位置相對於瀏覽器視窗來定位,這意味著即便頁面捲動,它還是會固定在相同的位置。
</div>
</div>
</body>
h1{
text-align: center;
font-family: 'Noto Sans TC', sans-serif;
background: linear-gradient(45deg, red, blue);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
div {
text-align: left;
border: 5px solid magenta;
font-weight: 600px;
font-size: 16px;
box-sizing: border-box;
padding: 4px;
}
#static {
border: 5px solid teal;
height: ;
width: 300px;
text-align: left;
}
#relative {
border-color: orange;
position: relative;
width:500px;
}
#relative-2 {
border-color: orange;
position: relative;
top: -20px;
left: 20px;
height: 200px;
background-color: white;
}
#fixed {
text-align: left;
border: none;
position: fixed;
bottom: 0;
right: 0;
margin: 0;
width: 500px;
background-color: black;
color: white;
}
.absolute {
text-align: left;
border-color: red;
position: absolute;
top: 200px;
right: 30px;
max-width: 75%;
background-color: #f2f2f2;
box-shadow: 6px 6px rgba(0, 0, 0, 0.3)
}
.absolute-2 {
text-align: left;
border-color: red;
position: absolute;
top: 80px;
right: 30px;
max-width: 80%;
background-color: #f2f2f2;
box-shadow: 6px 6px rgba(0, 0, 0, 0.3)
}
Also see: Tab Triggers