I have a question, I want to have my window split vertically
-----------
|Div 1 |D2|
| | |
-----------
#D2{
position: fixed;
top: 0;
right: 0;
height: 100vh
}
Here's the catch: D2 has an image, that scales proportionally, so the width is depended on the height.
Currently Div 1 is taking the full width (100%) and I don't know how to get it to do: 100vw-(#D2[val])vw
Flex ? play with this snippet at http://codepen.io/gcyrillus/pen/VaaaRK or run it below here.
If you think flex still too much up to date, then you can use display:table; http://codepen.io/gcyrillus/pen/WwwGXr
/* 101 */
body {
display: flex;
margin: 0;
}
#one {
flex: 1;
}
img {
display: block;
height: 100vh
}
/* extra */
body {
background: #F4BB2D
}
#one {
display: flex;
align-items: center;
justify-content: center;
text-align:right;
color: #89870A;
font-size: 7vw;
text-shadow: 1px 1px black, -1px -1px 1px gray
}
img {
box-shadow: 0 0 5px;
}
<div id="one">
Click Full Page <br/> Or Close
</div>
<div id="two">
<img src="http://lorempixel.com/200/500/nature/6" />
</div>
added some extra terrestrial words to try break it pushing D2 under
/* 101 */
body {
display: flex;
margin: 0;
}
#one {
flex: 1;
}
img {
display: block;
height: 100vh
}
/* extra */
body {
background: #F4BB2D
}
#one {
display: flex;
align-items: center;
justify-content: center;
text-align:right;
color: #89870A;
font-size: 7vw;
text-shadow: 1px 1px black, -1px -1px 1px gray
}
img {
box-shadow: 0 0 5px;
}
<div id="one">
<blocquote>ClickFullPageOrCloseClickFullPageOrCloseClickFullPageOrCloseClickFullPageOrCloseClickFullPageOrCloseClickFullPageOrCloseClickFullPageOrCloseClickFullPageOrCloseClickFullPageOrCloseClickFullPageOrCloseClickFullPageOrCloseClickFullPageOrCloseClickFullPageOrCloseClickFullPageOrCloseClickFullPageOrCloseClickFullPageOrCloseClickFullPageOrClose<br/>
<cite> Zi stutterer that came from mars </cite></blockquote>
</div>
<div id="two">
<img src="http://lorempixel.com/200/500/nature/6" />
</div>
Related
I'm using this grid as a top navabar and I want to make a few alterations:
How can I reduce the width of the input to 40% but still keep it right next to the logo? And how can I add a sign-in div at the right hand corner. But keep in mind that I want the entire header to remain responsive like it is now. If I do the following it looks good in a full screen but when the width of the screen is smaller the input becomes really small.
.top_nav_menu {
border-bottom: 1px solid #e3e3e3;
box-shadow: 0 0 8px 0 #eeeeee;
position: fixed;
top: 0px;
width: 100%;
height: auto;
background-color: #fafafa;
margin-right: 90px;
padding: 15px;
z-index: 2;
}
.header {
display: flex;
justify-content: flex-start;
align-items: center;
height: 50px;
}
.header > form {
width: 65%;
margin-left: 25px;
}
.header > form > input {
width: 40%;
}
<div class="top_nav_menu">
<div class="header">
<img src="http://i.imgur.com/EFkps0m.png">
<form><input type="text"></form>
<div class="floar-right">Sign-in</div
</div>
</div>
You can either reduce the value of 40% in your CSS.
Or add new CSS for max-width:
.header > form > input {
max-width: 50px;
}
For your sign-in div, you can add this CSS:
.float-right {
float:right;
}
However your current class spells floar and not float, you should change that.
you can use this code
body {
margin: 0;
padding: 0;
}
.top_nav_menu {
border-bottom: 1px solid #e3e3e3;
box-shadow: 0 0 8px 0 #eeeeee;
position: fixed;
top: 0px;
width: 100%;
height: auto;
background-color: #fafafa;
margin-right: 90px;
padding: 15px;
z-index: 2;
}
.header {
display: flex;
justify-content: flex-start;
align-items: center;
height: 50px;
}
.header > form {
width: 65%;
margin-left: 25px;
}
.header > form > input {
width: 24%;
}
<div class="top_nav_menu">
<div class="header">
<img src="http://i.imgur.com/EFkps0m.png">
<form><input type="text"></form>
<div class="floar-right">Sign-in</div>
</div>
</div>
I have tried width 100% but it didn't make it responsive. Here is link of what I'm trying to make responsive. It is not responsive. Help codepen link
div {
background:url(https://i.stack.imgur.com/EinaJ.png) top center;
width:620px;
margin:auto;
padding:40px 40px 30px;
height:590px;
position:relative;
display:flex;
flex-flow:column;
justify-content:center;
}
img, p, footer {
padding:5px;
margin:0;
background:pink
}
img {
margin:auto auto 0;
}
footer {
bottom:30px;
right:45px;
margin:auto 0 0;
border-radius:0 0 0.25em 0.25em ;
background:rgba(0,0,0,0.2);
}
<div>
<img src="">
<p>here is</p>
<footer>footer</footer>
</div>
The reason this is not responsive is because you have set the div's width and height to a specific pixel. Therefore it is not able to adjust.
Try changing the pixel to a percentage:
For example:
width: 50%;
height: 100%;
:root {
/*the percentage of screen width occupied by a block. 1 = 100% */
--percent: .9;
}
div {
background: url(https://i.stack.imgur.com/EinaJ.png) top center;
background-size: cover;
/* for old browsers */
width: 90vw;
height: 113.61516034vw;
/* for new browsers */
width: calc(100vw*var(--percent));
height: calc((100vw*var(--percent))*866/686);
box-sizing: border-box;
margin: auto;
padding: 40px 40px 30px;
position: relative;
display: flex;
flex-flow: column;
justify-content: center;
}
img,
p,
footer {
padding: 5px;
margin: 0;
/* see me */
background: pink
}
img {
margin: auto auto 0;
}
footer {
bottom: 30px;
right: 45px;
margin: auto 0 0;
border-radius: 0 0 0.25em 0.25em;
/* see me */
background: rgba(0, 0, 0, 0.2);
}
body {
background: #777;
}
<div>
<img src="http://lorempixel.com/200/150" />
<p>here is</p>
<p>some line</p>
<p>of</p>
<p>text</p>
<footer>footer</footer>
</div>
I see what you're trying to do.You're trying to have the div in the middle center and responsive.Set margin:0 auto; and width:50%;.Get rid of other bits of codes in the div.To make it responsive to mobile screen do:
#media only screen and (max-width:set_your_max){
div { width:50%; }
}
I have a simple layout which I took from MDN's flexbox page. It has a header and a main content area.
<header>header</header>
<div id='main'>
<article>article</article>
<aside>aside</aside>
</div>
I would like to have the main content area extend to the bottom of the viewport or further if it needs to accommodate its children. I tried fiddling with flexbox but I still can't specify that I want it to take up all space vertically like I can horizontally.
The only two options I can think of are:
A) Javascript to calculate the required height
B) Tiling a background image on the body to make it appear as though the content area is extended all the way down
Can anyone think of an alternatives to fill up the viewport and also contain children if the children extend past the bottom of n the screen?
https://jsfiddle.net/1cpcsvjr/5/
** Update ** I amended my jsfiddle with more content in the article sub element. The content will bleed out of the flex container.
#main
{
height: 100vh;
}
100vh means 100% of the viewport height, you can change this value if you need to.
you can set height to html an body to fill entitre window and use flex from body as well.
body {
font: 24px Helvetica;
background: #999999;
display:flex;
flex-flow: column;
}
html, body {
height:100%;
margin:0;
}
#main {
margin: 0px;
padding: 0px;
display: flex;
flex-flow: row;
flex:1;/* fills entire space avalaible (or share evenly if sibblings)*/
}
#main > article {
margin: 4px;
padding: 5px;
border: 1px solid #cccc33;
background: #dddd88;
flex: 3 1 60%;
order: 2;
}
#main > nav {
margin: 4px;
padding: 5px;
border: 1px solid #8888bb;
background: #ccccff;
flex: 1 6 20%;
order: 1;
}
header {
display: block;
margin: 4px;
padding: 5px;
min-height: 100px;
border: 1px solid #eebb55;
border-radius: 7pt;
background: #ffeebb;
}
<header>header</header>
<div id='main'>
<article>article</article>
<aside>aside</aside>
</div>
https://jsfiddle.net/1cpcsvjr/2/
Flexbox solution.
You have to set the html & body elements to 100% height.
* {
margin: 0;
padding: 0;
}
html,
body {
height: 100%;
}
body {
font: 24px Helvetica;
background: #999999;
min-height: 100%;
display: flex;
flex-direction: column;
}
#main {
margin: 0px;
padding: 0px;
flex: 1;
background: pink;
display: flex;
}
#main > article {
margin: 4px;
padding: 5px;
border: 1px solid #cccc33;
background: #dddd88;
flex: 3 1 60%;
order: 2;
}
#main > nav {
margin: 4px;
padding: 5px;
border: 1px solid #8888bb;
background: #ccccff;
flex: 1 6 20%;
order: 1;
}
header {
display: block;
margin: 4px;
padding: 5px;
min-height: 100px;
border: 1px solid #eebb55;
border-radius: 7pt;
background: #ffeebb;
}
<header>header</header>
<div id='main'>
<article>article</article>
<aside>aside</aside>
</div>
I have two divs in my page end I want to center the second one between the first and the end ofthe page. Something like this:
| | | | | |
| | | | | |
| | div1 | |div2| |
| | | | | |
| | | | | |
"Div 2" is supposed to be centered between "div 1" and the end of the page. I tried everything I know and nothing worked.
My HTML:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="teste.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script type="text/javascript" src="teste.js"></script>
<title>Example</title>
</head>
<body>
<div id="header">
<div class="title"">Example</div>
</div>
<div id="main-body">
<ul class="nav-tabs">
<li class="active-tab">Home</li>
<li>Menu 1</li>
<li>Menu 2</li>
</ul>
</div>
<div id="right-menu"></div>
<footer>
</footer>
</body>
</html>
And my CSS:
/* Fonte Nunito a ser usada no título */
#import url(http://fonts.googleapis.com/css?family=Nunito);
/*----------------------------------------------*/
/* Cor do fundo da página */
body {
background-color: #cccccc;
}
/*----------------------------------------------*/
/* Header */
/* Cor e tamanho */
#header {
background-color: #669966;
background-size: cover;
height: 100px;
width: 100%;
clear: both;
margin: 0;
padding: 0;
position: relative;
}
/* Título */
#header .title {
color: #cccccc;
font-family: Nunito;
font-size: 50px;
font-style: italic;
line-height: 46px;
left: 60px;
top: 30px;
position: absolute;
}
/*----------------------------------------------*/
/* Tabs */
.nav-tabs {
background-color: #cccccc;
list-style-type: none;
margin: 0;
padding: 0;
display: flex;
justify-content: space-between;
}
/* Tab cells */
.nav-tabs li {
background-color: gray;
color: white;
font-size: 1.2em;
padding: 10px 90px 10px 90px;
border-radius: 8px 8px 0 0;
}
/* Tab ativa */
.active-tab {
background-color: white;
color: red;
font-size: 1.2em;
padding: 10px 90px 10px 90px;
border-radius: 8px 8px 0 0;
}
a:link {
color: white;
text-decoration: none;
}
a:visited {
color: white;
text-decoration: none;
}
/*----------------------------------------------*/
/* Main body (this is "div 1")*/
#main-body {
background-color: white;
height: 100vh;
width: 900px;
margin: 5px 0 5px 100px;
display: inline-block;
}
/*----------------------------------------------*/
/* Menu à direita(this is "div 2") */
#right-menu {
border: 2px solid red;
background-color: yellow;
height: 30px;
width: 50px;
display: inline-block;
}
/*----------------------------------------------*/
/* Footah */
footer {
background-color: #333333;
height: 200px;
width: 100%;
margin: 0;
padding: 0;
}
Can someone help please?
[EDIT]
Thank you everyone who posted your solutions. The problem was solved!
You are getting close.
You need to make two outer divs that will, together, hold the full width of the page (one for the main column at say 70% wide, and one for the right column at 30% wide). Then inside your right column, place another div with fixed width and use text-align: center on the outer div.
If I understand you correctly, try this fiddle https://jsfiddle.net/9jrLat77/
CSS should be something like this
/* Fonte Nunito a ser usada no título */
#import url(http://fonts.googleapis.com/css?family=Nunito);
/*----------------------------------------------*/
/* Cor do fundo da página */
body {
background-color: #cccccc;
}
/*----------------------------------------------*/
/* Header */
/* Cor e tamanho */
#header {
background-color: #669966;
background-size: cover;
height: 100px;
width: 100%;
clear: both;
margin: 0;
padding: 0;
position: relative;
}
/* Título */
#header .title {
color: #cccccc;
font-family: Nunito;
font-size: 50px;
font-style: italic;
line-height: 46px;
left: 60px;
top: 30px;
position: absolute;
}
/*----------------------------------------------*/
/* Tabs */
.nav-tabs {
background-color: #cccccc;
list-style-type: none;
margin: 0;
padding: 0;
display: flex;
justify-content: space-between;
}
/* Tab cells */
.nav-tabs li {
background-color: gray;
color: white;
font-size: 1.2em;
padding: 10px 90px 10px 90px;
border-radius: 8px 8px 0 0;
}
/* Tab ativa */
.active-tab {
background-color: white;
color: red;
font-size: 1.2em;
padding: 10px 90px 10px 90px;
border-radius: 8px 8px 0 0;
}
a:link {
color: white;
text-decoration: none;
}
a:visited {
color: white;
text-decoration: none;
}
/*----------------------------------------------*/
/* Main body (this is "div 1")*/
#main-body {
background-color: white;
height: 100vh;
width: 900px;
margin: 5px 0;
display: inline-block;
float:left;
}
/*----------------------------------------------*/
/* Menu à direita(this is "div 2") */
#right-menu {
border: 2px solid red;
background-color: yellow;
height: 30px;
margin: 5px 0;
width: calc(100% - 920px);
display: block;
float:right;
}
.content-wrapper {
width: 100%;
}
}
First put #right-menu before #main-body:
<div id="right-menu"></div>
<div id="main-body">
<ul class="nav-tabs">
The set/modify these CSS rules
#main-body {
margin:0 auto;
display:block;
}
#right-menu {
position: absolute;
right: calc(((100% - 900px) / 4) - 25px);
}
The right: calculation works like this: From the full page width (100%) we remove the main width (900px); this give us the remaining width for both sides (left and right) so we divide it by two to have the width of one side then divide it by two again to have half of the size of one side. This will give us the exact position center of the free space on the left or the right (you can change the right: property to left: so you'll center it on left. Finally to center the element itself we subtract half of the right menu width (50px / 2 = 25px).
You should try working with bootstrap. Its a framework that makes it alot easier to format your page. you can set it up by including these lines in your code:
Bootstraps "container" has a width of 12. So if you set up the first div with a width of 5 and your second div width of 3 then you could set it up like this:
<div id="container">
<div id="row">
<div id="col-md-5">div 1 </div>
<div id="col-md-3 col-md-offset-2"> div 2 </div>
</div> </div>
the md part stands for medium and can be any size you want (xs, sm, md, lg)
the offset is due to the fact that you have 12 width so you have to move it over 2 to center it if the widths are 5 and 3.
Use this:
<style type="text/css">
body {
margin: 0px;
padding: 0px;
}
#right {
background-color: #ff0000;
float: right;
height: 500px;
margin: 0px;
padding: 0px;
width: 300px;
}
#main {
background-color: #0000ff;
height: 500px;
margin: 0px;
padding: 0px;
width: 900px;
}
</style>
<div id="right"></div>
<div id="main"></div>
<script type="text/javascript">
window.onload = setMargin;
window.onresize = setMargin;
function setMargin() {
var x = window.innerWidth;
var y = x - 900 - 300;
var z = y / 2;
document.getElementById("right").style.marginRight = z;
}
</script>
The simplest method here I feel is to have a wraooing div on the right hand side that takes up the remaining width...then center the menu block inside that.
I've used floats here (rather than inline-block) for simplicity as the white-space affect the calc values unless you reset them.
* {
box-sizing: border-box;
}
/* Main body (this is "div 1")*/
#main-body {
background-color: lightgrey;
height: 100vh;
width: 900px;
margin-left: 100px;
margin-right: 5px;
float: left;
}
/*----------------------------------------------*/
/* Menu à direita(this is "div 2") */
#right-wrap {
background: #bada55;
width: calc(100% - 1005px);
float: left;
text-align: center;
}
#right-menu {
border: 2px solid red;
background-color: yellow;
height: 30px;
width: 50px;
display: inline-block;
}
<div id="main-body">
<ul class="nav-tabs">
<li class="active-tab">Home
</li>
<li>Menu 1
</li>
<li>Menu 2
</li>
</ul>
</div>
<div id="right-wrap">
<div id="right-menu"></div>
</div>
Codepen Demo
I'm using Pseudo-element :before and :after to draw a line before and after a title. It's working with an image:
.mydiv::before {
content: url(img/line.png);}
.mydiv::after {
content: url(img/line.png);}
Here is the result :
But, I would like the line to expand and fill in the whole div before and after the title, like this :
Is there a way to specify a percentage for the image for it to stretch? I try this, but it's not working :
.mydiv img {
width: 100%;
height: auto;
}
You don't need both :before and :after, either of the 2 will be enough and as you've been told, you don't need an image. See the approach below.
#header {
width: 100%;
height: 50px;
margin: 50px 0;
text-align: center;
font-size: 28px;
position: relative;
background-color: #57585C;
}
#header:after {
content: '';
width: 100%;
border-bottom: solid 1px #fff;
position: absolute;
left: 0;
top: 50%;
z-index: 1;
}
h3 {
background-color: #57585C; /* Same as the parents Background */
width: auto;
display: inline-block;
z-index: 3;
padding: 0 20px 0 20px;
color: white;
position: relative;
font-family: calibri;
font-weight: lighter;
margin: 0;
}
<div id="header">
<h3>Last Projects</h3>
</div>
In case you need <h3> title to have transparent background - you can use both :before and :after and display: flex
More about flex-grow you can read here https://developer.mozilla.org/en-US/docs/Web/CSS/flex.
body {
background: linear-gradient(0.25turn, #3f87a6, #000000, #f69d3c); /* example of custom background */
}
#header {
display: flex;
flex-wrap: nowrap;
justify-content: flex-start;
align-items: center; /* making vertical centerign of all children */
}
#header::before, #header::after {
content: '';
flex: 1 1 auto; /* the first digint is 'flex-grow: 1', helps elemet to occupy all free space */
border-bottom: solid 1px #fff;
}
h3 {
flex: 0 1 auto; /* the first digint is flex-grow: 0 */
padding: 0 15px 0 15px;
color: #fff;
}
<div id="header">
<h3>Last Projects</h3>
</div>
<style>
.mydiv::before{
content: '';
position: absolute;
left: 0;
width: 100%;
height: 2px;
bottom: 1px;
background-color: black;
}
</style>
<div class="mydiv">About us</div>