Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

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.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

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.

+ add another resource

Packages

Add Packages

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.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="wrap-1">
<p>Если родитель блочный элемент с заданной фикс шириной или относительной (%) шириной, А дочерний вложенный <code>position: relative</code> или <code>position: static</code>, то:
если НЕ УКАЗЫВАТЬ ЯВНО ему ширину, то даже с padding он будет внутри по границам родителя</p>
  </div>

<div class="wrap-2">
<p>Если родитель блочный элемент с заданной фикс шириной или относительной (%) шириной, А дочерний вложенный <code>position: relative</code> или <code>position: static</code>, то:
если ЯВНО УКАЗЫВАТЬ ему ширину, то УЖЕ с padding он будет ВЫХОДИТЬ ЗА границы родителя</p>
  </div>

<div class="wrap-3">
<p>
  Элементы с абсолютным позиционированием.</p>
  <p>
  Элементы с абсолютным позиционированием, для которых ширина не установлена, ведут себя слегка странно.</p>
  <p>
  Элементы с абсолютным позиционированием, для которых ширина не установлена, ведут себя слегка странно. Их ширина устанавливается такой, чтобы только хватило покрыть контент. Так продолжается до тех пор, пока ширина элемента не станет равной ширине родителя (ближайшего с относительным позиционированием, либо окно браузера), а затем содержимое начнёт переноситься на другую строку.</p>
  <p>
  Элементы с абсолютным позиционированием, для которых ширина не установлена, ведут себя слегка странно. Их ширина устанавливается такой, чтобы только хватило покрыть контент. Так продолжается до тех пор, пока ширина элемента не станет равной ширине родителя (ближайшего с относительным позиционированием, либо окно браузера), а затем содержимое начнёт переноситься на другую строку.<br>
    Если указать ширину , то произойдёт то же что wrap-2.
  </p>
  </div>


              
            
!

CSS

              
                code {
  font-style: italic;
}

/* Если родитель с заданной фикс шириной или относительной (%) шириной*/
.wrap-1{
/*   position: relative; */
  width: 500px;
/*   width: 100%; */
  background-color: #008000;
  border: 1px solid #008000;
  margin-bottom: 10px;
}

/* А дочерний вложенный position: relative или position: static, то:
если не указывать ему ширину, то даже с padding он будет внутри по границам родителя*/
.wrap-1 p{
  background-color: #4e4e4e;
  color: #fff;
  padding: 50px;
}
/* ---------------------------------------------------------------------------------- */
/* Если родитель с заданной фикс шириной или относительной (%) шириной*/
.wrap-2{
/*   position: relative; */
  width: 500px;
/*   width: 100%; */
  background-color: #008000;
  border: 1px solid #008000;
  margin-bottom: 10px;
}

/* А дочерний вложенный position: relative или position: static, то:
если указывать явно ему ширину, то уже с padding он будет выходить за границы родителя.
В данном случае ширина 100% относительно родителя - 500px + padding-left:50px + padding-right:50px
Итого 600px*/
.wrap-2 p{
  width: 100%;
  background-color: #4e4e4e;
  color: #fff;
  padding: 50px;
}

/* ---------------------------------------------------------------------------------- */

.wrap-3{
  position: relative;
  width: 500px;
/*   width: 100%; */
  background-color: #008000;
  border: 1px solid #008000;
  margin-bottom: 10px;
}


.wrap-3 p{
  position: absolute;
  top: 10px;
/*   width: 100%; */
  background-color: #4e4e4e;
  color: #fff;
  padding: 20px;
}

.wrap-3 p:first-child {
  top: 0;
}

.wrap-3 p:nth-child(2) {
  top: 100px;
}
.wrap-3 p:nth-child(3) {
  top: 200px;
}

.wrap-3 p:last-child {
  top: 400px;
  width: 100%;
}
              
            
!

JS

              
                
              
            
!
999px

Console