I centered a div vertically with CSS and it works great. But I have a background and when I resize browser the text go out the background.
.wrapper{
height: 100%;
width: 100%;
background: rgba(51,51,51,.5);
}
.outer {
display: table;
position: absolute;
height: 100%;
width: 100%;
}
.middle {
display: table-cell;
vertical-align: middle;
}
.inner {
margin-left: auto;
margin-right: auto;
width: 50%;
}
jsfiddle
.wrapper is div, so it already has width: 100% (because div has display: block, and we know that all blocks are full width elements). .wrapper { height: 100%; } means that it will inherit the full height of its parent (in this case it is body, body inherit height of its parent - html - so you get the viewport height); So we can remove all .wrapper styles. And simply add background: rgba(51,51,51,.5); to .outer
html,
body {
width: 100%;
height: 100%;
padding: 0;
margin: 0;
}
.wrapper {
}
.outer {
display: table;
position: absolute;
height: 100%;
width: 100%;
background: rgba(51,51,51,.5);
}
.middle {
display: table-cell;
vertical-align: middle;
}
.inner {
margin: 0 auto;
width: 50%;
}
<div class="wrapper">
<div class="outer">
<div class="middle">
<div class="inner">
<h1>The Content</h1>
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus</p>
</div>
</div>
</div>
</div>
Jsfiddle Here
No need to use position:absolute in .outer and specifying height in .wrapper.
.wrapper{
/* height:100%; remove this-**/
width: 100%;
background: rgba(51,51,51,.5);
}
.outer {
display: table;
/* position: absolute; remove this-**/
min-height: 100%;
width: 100%;
}
try this https://jsfiddle.net/serGlazkov/5t9asdc1/3/
you should use min-height and delete here position: absolute;
.outer {
display: table;
/*position: absolute;*/
height: 100%;
width: 100%;
}
Related
Can anyone help me out on how to achieve the following shown below in red?
From what I understand it is a div overlap but I can't seem to figure out how to get it like this.
Add the below mentioned style to .about-lower
position: relative;
padding-top: 15px;
Remove margin-top: 20px and add the following style to .lower-title-container
position: absolute;
top: -26px;
left: 73px;
Updated JSFiddle link is here.
One method using position: absolute
I've adding padding to the container below to ensure it doesn't overlap with the button
body {
font-family: "Helvetica", sans-serif;
margin: 0px 0px 0px 0px;
}
.header-img-container {
background-image: url(../Images/about-header-img.jpg);
background-repeat: no-repeat;
background-position: top;
background-size: cover;
height: 330px;
width: 100%;
}
.header-img {
object-fit: cover;
width: 100%;
height: 100%;
}
.about-middle {
text-align: left;
margin: auto;
width: 80%;
}
.about-middle-text {
line-height: 1.3;
margin-bottom: 50px;
margin-top: 40px;
}
.about-middle-text h2 {
margin-top: 60px;
margin-bottom: 40px;
}
.about-middle-text p {
margin-bottom: 14px;
font-size: 14px;
}
.about-lower {
background-color: #FAF8F8;
text-align: left;
padding-bottom: 30px;
}
.lower-title-container {
width: 80%;
text-align: center;
vertical-align: middle;
margin: auto;
margin-top: 20px;
z-index: 10;
position: relative;
}
.lower-title {
width: 150px;
height: 50px;
background-color: #b2b0c5;
color: white;
border-radius: 22px;
display: flex;
align-items: center;
justify-content: center;
position: absolute;
top: -25px;
}
.lower-title p {
font-weight: 100;
font-size: 20px;
vertical-align: middle;
}
.about-eagles-container {
margin-top: 40px;
}
.about-eagles {
border-bottom: 1px solid lightgray;
padding-bottom: 20px;
display: flex;
width: 80%;
align-items: center;
margin: auto;
margin-top: 20px;
margin-bottom: 20px;
padding-top: 50px;
}
.eagle-img-container {
margin-right: 30px;
height: 150px;
width: 150px;
}
.eagle-img {
height: 100%;
width: 100%;
object-fit: cover;
border-radius: 2px;
}
.eagle-img-container:hover {
background-color: rgba(225, 231, 242, 0.8);
}
.eagle-name {
margin-bottom: 30px;
font-weight: bold;
}
<div class="about-middle">
<div class="about-middle-text">
<h3>Rising Eagles</h3>
<p>Lorem ipsum dolor sit amet, populo vocent perfecto has in, phaedrum aliquando omittantur mei in, evertitur intellegebat eum ut. Vel ea nulla mentitum. Id aeterno minimum sea, at est albucius scaevola consequat. Duo facer platonem expetendis eu, eu
quando aliquip constituam sed. Ne invenire suavitate vulputate mei. Vestibulum mi sapien ac nunc vel. Pellentesque nec elit sit ac orci. Ut lectus venenatis eros diam, pellentesque natoque amet lectus felis, cursus laoreet blandit ut nulla vel libero.
Venenatis tristique cras, ut vitae, lectus ornare enim, sapien luctus lacinia, aliquam nibh libero tincidunt ut. Commodo risus amet vivamus, molestie mattis at. Mauris massa, vitae dolor etiam sed. Sit mi dignissim elementum, sit nulla nec arcu
in arcu, reprehenderit sem donec magna, nisl urna non, venenatis turpis risus duis ultrices. </p>
<p> Vitae consul quodsi ea sea, ex graeci accusam copiosae sit. Ei error accumsan mel. Quo id populo melius ceteros. Ex per magna aliquam, eos scripta integre ex. Praesent in eu tincidunt. Commodo magni porta nonummy aliquam enim neque, dapibus phasellus
sed volutpat, dui quam, parturient molestie ante massa bibendum. Pharetra in ut, aliquam pretium rutrum pretium luctus phasellus. Enim sem cras interdum, at dolor in.</p>
</div>
</div>
<div class="about-lower">
<div class="lower-title-container">
<div class="lower-title">
<p>The Eagles</p>
</div>
</div>
<!-- Iterate over accounts and build div for each -->
<div class="about-eagles-container">
<div class="about-eagles">
<div class="eagle-img-container">
<!-- Change url to link to their personal page -->
<img src="../Images/profile-img1.jpg" class="eagle-img">
</div>
<div class="eagle-text">
<p class="eagle-name">Charlie</p>
<p>Lorem ipsum dolor sit amet, nec no errem euismod ponderum. Pro no populo putant audire.</p>
</div>
</div>
<div class="about-eagles">
<div class="eagle-img-container">
<img src="../Images/profile-img2.jpg" class="eagle-img">
</div>
</div>
</div>
</div>
html:
<!-- i put the button above the first div -->
<input id="btn" type="button" value="the button"/>
<div class="about-middle">
css:
add
body {
position: relative;
}
#btn {
left: 75px;
margin: -25px 0 0 20px;
position: absolute;
top: 15px;
}
.about-middle{
border: solid 1px black; /* so it's visible. */
}
I have checked these two posts: Adjacent divs with angled borders? [duplicate] and Shape with a slanted side (responsive) but those solutions posted do not adjust to 100% height of the container and I need this. I cannot find a solution to fit my scenario.
I'm trying to replicate this behaviour the difference is the text inside this container can be of any height so I need the angle and container to adapt to fit any height (not a fixed height container):
Here's the code I'm using with a jSFiddle: https://jsfiddle.net/qzma0r6k/1/
CSS
section {
position: relative;
color: #fff;
}
.diagonal:before {
position: absolute;
content:'';
-webkit-transform: rotate(45deg);
transform: rotate(45deg);
-webkit-transform-origin: 0 100%;
transform-origin: 0 100%;
top: 0;
right:0;
height:100%;
z-index: 0;
width: 50%;
background:pink;
}
HTML
<section class="c-1">
<div class="c-2 diagonal">
<h1>Work with us</h1>
<p>Scelerisque et parturient dis a erat cubilia congue sociosqu vel porta sem posuere a malesuada suspendisse id commodo. Dui consequat consectetur luctus odio nibh a vel sapien hendrerit ad a consectetur cursus a nisl posuere.</p>
</div>
<div class="bg-image"></div>
</section>
Something like this?
* {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
.c-1 {
background: #333;
overflow: hidden;
position: relative;
}
.c-2 {
float: left;
width: 50%;
position: relative;
color: #fff;
padding: 50px;
}
.bg-image {
position: absolute;
width: 50%;
top: 0;
right: 0;
bottom: 0;
padding: 0;
background-image: url(http://placehold.it/350x150);
background-repeat: no-repeat;
background-position: center center;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
z-index: 0;
}
section {
position: relative;
color: #fff;
}
.diagonal {
position: relative;
z-index:1;
}
.diagonal:after {
right: 0;
left: 100px;
position: absolute;
-webkit-transform: skewX(-15deg) rotate(180deg);
-ms-transform: skewX(-15deg) rotate(180deg);
transform: skewX(-15deg) rotate(180deg);
content: "";
top: 0;
width: 100%;
height: 100%;
background: #333;
z-index:-1;
}
<section class="c-1">
<div class="c-2 diagonal">
<h1>
Work with us
</h1>
<p>
Scelerisque et parturient dis a erat cubilia congue sociosqu vel porta sem posuere a malesuada suspendisse id commodo. Dui consequat consectetur luctus odio nibh a vel sapien hendrerit ad a consectetur cursus a nisl posuere. A cubilia varius dapibus non
scelerisque aliquam imperdiet nec montes suspendisse orci potenti dignissim vestibulum venenatis sociosqu ullamcorper vestibulum scelerisque magna sem ultricies convallis cras. Ante sed elit tristique interdum hendrerit nascetur a cras suspendisse
mi fermentum vestibulum auctor a taciti euismod ac non adipiscing a. Maecenas parturient a dui sodales vestibulum nisl nisi consequat cum lacus lobortis senectus metus at adipiscing cursus parturient a.
</p>
</div>
<div class="bg-image"></div>
</section>
I've been looking all over and failed to find a solution to this on my own. I'm trying to make a basic contenteditable code editor, and for the line numbers I have chosen to use a paragraph for each line with a counter set in a CSS pseudo element.
.editor {
display: inline-block;
border: 1px black solid;
font-family: "Consolas", "Monaco", "Courier New", monospace;
counter-reset: line;
width: 90%;
height: 350px;
overflow: scroll;
padding-left: 0;
margin-left: 0;
z-index: 1;
}
.editor p {
display: block;
counter-increment: line;
background-color: #FFF;
text-align: left;
margin: 0px;
z-index: 2;
outline: none;
}
.editor p:before {
display: inline-block;
width: 2em;
height: 100%;
border-right: 1px black solid;
padding-right: 1em;
margin-right: 1em;
content: counter(line);
color: #FFF;
background-color: #006;
text-align: right;
/*-webkit-user-select: none;
user-select: none;*/
}
<div class="editor" contenteditable="true" spellcheck="false">
<p>Some paragraph</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas aliquet nunc non pulvinar luctus. Cras finibus turpis at arcu mollis, nec fermentum mi pretium. Aliquam suscipit lacus sapien, eu fringilla enim malesuada quis. Sed ut tincidunt erat.
In posuere vulputate venenatis. Mauris quis porta magna. Phasellus pharetra in nisl et luctus. Etiam in ultrices risus. Morbi vel dapibus ex. Suspendisse gravida libero non malesuada congue. Pellentesque ut nunc diam.</p>
<p> </p>
<p> </p>
<p> </p>
</div>
The problem is that if the paragraph is a bit longer the rest of the text will go beneath my counter pseudoelement. I want to strech the :before counter to be the same height as the paragraph.
I have tried using position:relative on the paragraph and position:absolute; height:100% on the p:before pseudoelement like explained here: How can the pseudo element detect the height of the non-pseudo element?
This does not work in my case because I don't want the p:before element to go over and cover the paragraph, I just want the same behaviour as now, just want the p:before element to strech at the same height as the main p.
I also wouldn't want to have the line strech more than the width of the wrapper container. I've been trying many methods but failed to come to a solution.
Instead of height, rather use position: relative; for p, and position: absolute; for :before.
Js Fiddle
Here are the newly added CSS properties:
.editor p {
position: relative;
padding-left: 3.5em;
.editor p:before {
position: absolute;
top: 0;
bottom: 0;
left: 0;
}
Edit
It should be a second question :D
Pressing Enter in IE will not create a br, whereas in modern browsers it creates a br using :after. Here is to guarantee so that p tag does not remain empty:
Js Fiddle
.editor {
display: inline-block;
border: 1px black solid;
font-family: "Consolas", "Monaco", "Courier New", monospace;
counter-reset: line;
width: 90%;
height: 350px;
overflow: scroll;
padding-left: 0;
margin-left: 0;
z-index: 1;
}
.editor p {
display: block;
counter-increment: line;
background-color: #FFF;
text-align: left;
margin: 0px;
z-index: 2;
outline: none;
position: relative;
padding-left: 3.5em;
}
.editor p:before {
display: inline-block;
width: 2em;
height: 100%;
border-right: 1px black solid;
padding-right: 1em;
margin-right: 1em;
content: counter(line);
color: #FFF;
background-color: #006;
text-align: right;
position: absolute;
top: 0;
bottom: 0;
left: 0;
/*-webkit-user-select: none;
user-select: none;*/
}
.editor p:after {
content: " "
}
<div class="editor" contenteditable="true" spellcheck="false">
<p>Some paragraph</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas aliquet nunc non pulvinar luctus. Cras finibus turpis at arcu mollis, nec fermentum mi pretium. Aliquam suscipit lacus sapien, eu fringilla enim malesuada quis. Sed ut tincidunt erat.
In posuere vulputate venenatis. Mauris quis porta magna. Phasellus pharetra in nisl et luctus. Etiam in ultrices risus. Morbi vel dapibus ex. Suspendisse gravida libero non malesuada congue. Pellentesque ut nunc diam.</p>
<p>one</p>
<p>two</p>
<p>three</p>
</div>
Since you want the line numbers and lines appear in table-like manner, the natural approach is to make them table: declare the editable area as table (in the CSS sense), make the lines rows, and make the generated line numbers table cells:
.editor {
display: tablek;
border: 1px black solid;
font-family: "Consolas", "Monaco", "Courier New", monospace;
counter-reset: line;
width:90%;
height:350px;
overflow:scroll;
padding-left:0;
margin-left:0;
z-index:1;
}
.editor p {
display: table-row;
counter-increment: line;
background-color:#FFF;
text-align:left;
margin:0px;
z-index:2;
outline: none;
}
.editor p:before {
display: table-cell;
width:2em;
height:100%;
border-right: 1px black solid;
padding-right: 1em;
margin-right: 1em;
content: counter(line);
color:#FFF;
background-color:#006;
text-align:right;
/*-webkit-user-select: none;
user-select: none;*/
}
<div class="editor" contenteditable="true" spellcheck="false">
<p>Some paragraph</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas aliquet nunc non pulvinar luctus. Cras finibus turpis at arcu mollis, nec fermentum mi pretium. Aliquam suscipit lacus sapien, eu fringilla enim malesuada quis. Sed ut tincidunt erat. In posuere vulputate venenatis. Mauris quis porta magna. Phasellus pharetra in nisl et luctus. Etiam in ultrices risus. Morbi vel dapibus ex. Suspendisse gravida libero non malesuada congue. Pellentesque ut nunc diam.</p>
<p> </p>
<p> </p>
<p> </p>
</div>
http://jsfiddle.net/zppb29jw/2/
p {
position:relative;
left: 4em;
...
p:before {
position:absolute;
right:100%
display:block;
...
is that ok for you?
.black_right{
position: relative;
display: table;
width: 100%;
z-index: 10;
}
.black_right::after{
content: " ";
top: 0px;
height: 100%;
width: 100%;
box-shadow: 500px 0px #000;
position: absolute;
}
im trying to mimic example from this page http://learnlayout.com/media-queries.html ... it should do two things after resizing to small...
1.) make LI elements INLINE.... this works for me
2.) make NAV and sections ONE COLUMN... this doesnt work for me, see picture
here is code
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>vajcia</title>
</head>
<style>
body
{
margin: 0 0;
}
#container
{
box-sizing:border-box;
width: 100%;
border: 5px solid green;
}
section
{
border: 2px solid yellow;
margin-left: 200px;
}
nav{
background-color: red;
width:200px;
box-sizing:border-box;
/*position: absolute;
top:0;
left:0px;*/
float:left;
}
#media screen and (min-width:600px) {
nav {
float: left;
width: 25%;
}
section {
margin-left: 25%;
}
}
#media screen and (max-width:599px) {
nav li {
display: inline;
}
}
</style>
<body>
<div id="container">
<nav>
<ul>
<li>Home</li>
<li>Taco</li>
<li>Hours</li>
<li>Contact</li>
<li>About</li>
<li>Hovno</li>
</ul>
</nav>
<section>
The margin-left style for sections makes sure there is room for the nav. Otherwise the absolute and static elements would overlap
</section>
<section>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus imperdiet, nulla et dictum interdum, nisi lorem egestas odio, vitae scelerisque enim ligula venenatis dolor. Maecenas nisl est, ultrices nec congue eget, auctor vitae massa. Fusce luctus vestibulum augue ut aliquet. Mauris ante ligula, facilisis sed ornare eu, lobortis in odio. Praesent convallis urna a lacus interdum ut hendrerit risus congue. Nunc sagittis dictum nisi, sed ullamcorper ipsum dignissim ac. In at libero sed nunc venenatis imperdiet sed ornare turpis. Donec vitae dui eget tellus gravida venenatis. Integer fringilla congue eros non fermentum. Sed dapibus pulvinar nibh tempor porta. Cras ac leo purus. Mauris quis diam velit.
</section>
<section>
Notice what happens when you resize your browser. It works nicely!
</section>
</div>
</body>
</html>
You'll want to do something like this:
http://jsfiddle.net/wFtJ4/
body {
margin: 0 0;
margin-bottom: 120px;
}
#container {
box-sizing:border-box;
width: 100%;
border: 5px solid green;
}
section {
border: 2px solid yellow;
margin-left: 200px;
}
nav {
background-color: red;
width:200px;
box-sizing:border-box;
/*position: absolute;
top:0;
left:0px;*/
float:left;
}
#media screen and (max-width:599px) {
nav li { display: inline; }
nav { width: 100%; text-align: center; }
section { margin-left: 0 !important; }
}
Your CSS is a bit haphazard, so I hope this shows you have to override some of your settings when you use #mediaqueries ;)
If you want one column for your nav (red ?) then you need to remove its float and its width.
#media screen and (max-width:599px) {
nav li {
display: inline;
}
nav {
float: none;
width: auto;
}
}
Synopsis
I have a wrapper, width 980px with padding 10x. The content inside is 960px (border-box). I have one element, inline-block, width 760px, margin-right 20px, and another inline-block at 180px. These should match perfectly. But only subtracting two px from one of the elements will make them fit within the parent.
I am aware of the white-space problem with inline-blocks and always use that fix. Even so, I still tested two blocks with float and still the same problem.
CSS
* { padding: 0; margin: 0; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; -o-box-sizing: border-box; box-sizing: border-box; }
.wrapper { width: 980px; margin: 0 auto 20px; padding: 10px; border: 1px solid #fff; box-shadow: 0 0 20px rgba(0,0,0,0.1); }
.featured_blog { width: 760px; height: 240px; padding: 10px; margin: 0 20px 20px 0; border: 1px solid #000; /*display: inline-block; *display: inline; zoom: 1;*/ display: block; float: left; vertical-align: top; overflow: hidden; text-overflow: ellipsis; }
.featured_author { width: 180px; height: 240px; border: 1px solid #000; /*display: inline-block; *display: inline; zoom: 1;*/ display: block; float: left; vertical-align: top; }
HTML
<section class="wrapper">
<div class="featured_blog">
<h2><span>Some Kind of Blog Title</span></h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut justo orci, dictum id venenatis at, mattis nec enim. Maecenas vel molestie dolor. Maecenas mauris massa, congue at rhoncus et, dapibus sit amet eros. Nunc ipsum felis, eleifend in laoreet sit amet, tincidunt feugiat velit. Cras eu felis tortor, sed accumsan nisl. Ut volutpat viverra justo, quis consectetur felis tempor a. Etiam magna eros, euismod vel viverra in, facilisis sed libero. Vivamus in neque quis turpis adipiscing scelerisque dapibus at diam. Sed magna magna, ultrices quis posuere vel, pulvinar sodales dolor. Proin sapien sapien, adipiscing quis ultrices eget, cursus vitae enim. Maecenas ornare, erat non porta porta, sem felis condimentum erat, a lacinia nunc nisl a est.</p>
</div><div class="featured_author"></div>
</section>
Where are these two px coming from???!!!!!
The 2px comes from the border: 1px solid #000;. Border on the either side causes this issue. Reduce 2px from the width.
Without Border, it works fine
http://jsfiddle.net/RRvMU/
With Border, and a few width adjustments http://jsfiddle.net/RRvMU/1/