I am trying to create two div, one at left with 49% width, then 2% margin and then another div at 49% width as well. But I have a problem with the vertical space, as well as with the margin.
DEMO
.Footer-firstElement {
font-size: 0;
line-height: 0;
height: 200px;
background-color: tomato;
}
.Footer-firstElementLeft {
display: inline-block;
font-size: 16px;
line-height: 20px;
width: 49%;
height: 100%;
margin-top:0;
margin-right: 2%;
background-color: pink;
}
.Footer-firstElementRight {
display: inline-block;
font-size: 16px;
line-height: 20px;
width: 49%;
height: 100%;
padding: 0;
background-color: gold;
}
<div class="Footer-firstElement">
<div class="Footer-firstElementLeft">
Foo bar
</div>
<div class="Footer-firstElementRight">
Foo bar <br />
Foo bar
</div>
</div>
Here is a fiddle of that code: https://jsfiddle.net/L6k5ocyr/3/
I think I am missing something, any idea?
.Footer-firstElement {
font-size: 0;
line-height: 0;
height: 200px;
background-color: tomato;
}
.Footer-firstElementLeft {
display: inline-block;
font-size: 16px;
line-height: 20px;
width: 49%;
height: 100%;
margin-top:0;
margin-right: 2%;
background-color: pink;
float:left; /* edited */
}
.Footer-firstElementRight {
display: inline-block;
font-size: 16px;
line-height: 20px;
width: 49%;
height: 100%;
padding: 0;
background-color: gold;
}
<div class="Footer-firstElement">
<div class="Footer-firstElementLeft">
Foo bar
</div>
<div class="Footer-firstElementRight">
Foo bar <br />
Foo bar
</div>
</div>
try this :
.Footer-firstElementLeft {
float: left;
}
.Footer-firstElementLeft {
vertical-align: top;
}
Try this.
.Footer-firstElement {
font-size: 0;
line-height: 0;
height: 200px;
background-color: tomato;
}
.Footer-firstElementLeft {
display: inline-block;
font-size: 16px;
line-height: 20px;
width: 49%;
height: 100%;
margin-top:0;
margin-right: 2%;
background-color: pink;
vertical-align: top; /* edited */
}
.Footer-firstElementRight {
display: inline-block;
font-size: 16px;
line-height: 20px;
width: 49%;
height: 100%;
padding: 0;
background-color: gold;
}
<div class="Footer-firstElement">
<div class="Footer-firstElementLeft">
Foo bar
</div>
<div class="Footer-firstElementRight">
Foo bar <br />
Foo bar
</div>
</div>
try using the float property see snippet
.Footer-firstElement {
font-size: 0;
line-height: 0;
height: 200px;
background-color: tomato;
}
.Footer-firstElementLeft {
font-size: 16px;
line-height: 20px;
width: 49%;
float: left;
height: 100%;
margin-right: 2%;
background-color: pink;
}
.Footer-firstElementRight {
font-size: 16px;
line-height: 20px;
width: 49%;
float: right;
height: 100%;
padding: 0;
background-color: gold;
}
<div class="Footer-firstElement">
<div class="Footer-firstElementLeft">
Foo bar
</div>
<div class="Footer-firstElementRight">
Foo bar <br />
Foo bar
</div>
</div>
I would recommend reading up on flexbox when wanting to do stuff like this.
I edited your fiddle to show what flexbox can do.
.Footer-firstElement {
display: flex;
justify-content: space-between;
font-size: 0;
line-height: 0;
height: 200px;
background-color: tomato;
}
.Footer-firstElement > * {
flex: 0;
min-width: 49%;
}
.Footer-firstElementLeft {
font-size: 16px;
line-height: 20px;
height: 100%;
background-color: pink;
}
.Footer-firstElementRight {
font-size: 16px;
line-height: 20px;
height: 100%;
padding: 0;
background-color: gold;
}
<div class="Footer-firstElement">
<div class="Footer-firstElementLeft">
Foo bar
</div>
<div class="Footer-firstElementRight">
Foo bar <br />
Foo bar
</div>
</div>
Not change much, just adding display flex to the parents and flex:1; to the children.
.Footer-firstElement {
height: 200px;
width:100%;
position:relative;
background-color: tomato;
display: flex;
}
.Footer-firstElementLeft {
flex:1;
font-size: 16px;
width: 50%;
height: 100%;
background-color: pink;
margin-right: 8;
}
.Footer-firstElementRight {
flex:1;
font-size: 16px;
width: 50%;
height: 100%;
background-color: gold;
margin-left: 8px;
}
<div class="Footer-firstElement">
<div class="Footer-firstElementLeft">
Foo bar
</div>
<div class="Footer-firstElementRight">
Foo bar <br />
Foo bar
</div>
</div>
Try this case
.Footer-firstElement {
font-size: 0;
line-height: 0;
height: 200px;
background-color: tomato;
}
.Footer-firstElementLeft {
float: left;
font-size: 16px;
line-height: 20px;
width: 49%;
height: 100%;
margin-top:0;
margin-right: 2%;
background-color: pink;
}
.Footer-firstElementRight {
float: right;
font-size: 16px;
line-height: 20px;
width: 49%;
height: 100%;
padding: 0;
background-color: gold;
}
Related
In This Code,I want to set the margin-top of .Login class ,smaller,although I set The margin-top ,to zero,but it is not set near to the top of page.What Can I do?why by setting the margin-top of this division ,this div does not set ,near the top of page?is other thing ok?the other elements works properly.
body {
margin: 0px;
direction: rtl;
}
#font-face {
src: url('../fonts/IRANSansWeb.eot'), url('../fonts/IRANSansWeb.woff'), url('../fonts/IRANSansWeb.woff2'), url('../fonts/IRANSansWeb.ttf');
font-family: "IranSans";
}
header {
width: 100%;
min-height: 700px;
height: auto;
overflow: auto;
background-color: #007bff;
}
nav {
margin-top: 0px;
height: 50px;
}
nav ul {
width: 60%;
height: 60px;
margin: 0px auto;
border: 2px solid black;
display: inline-block;
}
.Logo {
width: 160px;
height: 50px;
margin-left: 0px;
margin-right: 30px;
margin-bottom: 0px;
display: inline-block;
}
.Logo img {
width: 100%;
height: 100%;
}
.LogIn {
width: 140px;
height: 50px;
display: inline-block;
margin-right: 130px;
margin-top: 0px;
font-family: "IranSans";
border-radius: 5px;
background-color: #00d363;
}
.LogInA {
width: 100%;
height: 100%;
border: 5px;
color: #fff;
display: inline-block;
text-decoration: none;
text-align: center;
line-height: 50px;
}
.LogInA:hover {
border-radius: 5px;
background-color: #007bff;
color: #00d363;
border: 1px solid #00d363;
}
<body>
<header>
<nav>
<div class="Logo"><img src="Content/img/logo.png" alt="جاب بورد"></div>
<ul>
</ul>
<div class="LogIn">
<a class="LogInA" href="#">ارسال شغل</a>
</div>
</nav>
</header>
</body>
Try adding display: flex; to your nav
You should use:
display:flex; justify-content: center; to your Nav and also you should remove height and use: flex-direction:column; in mobile version.
Sorry bit of a newbie, but i'm having this annoying issue where I can't figure out why these two divs are overlapping... I have content behind the second pic that's being covered right now but I want that content to be shown and for the second pic to be displayed normally under it..
heres what I have html:
<main>
<div id="top_head">
<h2>
Gallery
</h2>
</div>
<br>
<div id="canvas">
<div class="gal_block">
<img src="../img/b_sign.jpg" alt="#">
<br>
<h2 class="gal_head">Chill Morning</h2>
<br>
<p class="gal_meta">May 12, 2018 / by nock / Outdoors<p>
<br>
<p class="gal_info"></p>
</div>
<div class="gal_block">
<img src="../img/b_sign.jpg" alt="#">
<br>
<h2 class="gal_head">Chill Morning</h2>
<br>
<p class="gal_meta">May 12, 2018 / by nock / Outdoors<p>
<br>
<p class="gal_info"></p>
</div>
</div>
</main>
And my css:
* {
margin:0;
padding: 0;
}
.clearfix {
clear: both;
}
#container {
margin: 0 auto;
width: 100%;
}
a {
text-decoration: none;
}
header {
width: 100%;
}
#left_header {
float: left;
margin: 5%;
padding:;
width: 20%
}
#left_header h1 {
font-family: 'Pacifico',cursive;
}
header nav {
float: right;
margin: 5%;
width: 35%;
}
header nav ul li {
float: left;
margin-left: 7%;
padding:0;
list-style: none;
font-size: 20px;
font-family: 'Raleway',cursive;
}
header nav ul li a {
color: black;
transition: color 1s;
}
header nav ul li a:hover {
color: gray;
}
main {
}
#top_head h2 {
font-family: 'Source Serif Pro';
font-size: 30px;
text-align: center;
}
/*affects all pages ^^^*/
/*home*/
#img_wall {
width: 82%;
height: 100%;
padding: 7%;
}
#l_big {
padding: 1%;
float: left;
width: 58%;
height: 67%;
}
#l_big img{
width: 100%;
height: 100%;
border-radius: 5px;
}
#r_top {
padding: 1%;
float: left;
width: 38%;
height: 32%;
}
#r_top img {
width: 100%;
height: 100%;
border-radius: 5px;
}
#r_bottom {
padding: 1%;
float: left;
width: 38%;
height: 32%;
}
#r_bottom img {
width: 100%;
height: 100%;
border-radius: 5px;
}
/*home end*/
/*about*/
/*about end*/
/*gallery*/
#canvas {
}
.gal_block {
display: block;
margin: 0 auto;
width: 80%;
height: 70%;
margin-top: 5%;
}
.gal_block img {
width: 100%;
height: 100%;
display: block;
margin: 0 auto;
border-radius: 5px;
}
.gal_head {
font-family: 'Source Serif Pro';
font-size: 25px;
text-align: center;
margin-top: 2%;
}
.gal_meta {
font-family: 'Raleway',cursive;
font-size: 12px;
color: gray;
text-align: center;
}
.gal_info {
font-size: 14px;
font-family: Arial;
width: 40%;
margin: 0 auto;
line-height: 1.5;
margin-bottom: 8%;
}
I also have a container over everything that with a width of 100% if that matters..(guessing it doesn't) but img of the issue below
if you look closely you can see the text thats supposed to be not cover..revealing itself when I mess with the zoom on the page...
I'm trying to make a portfolio page. I've created a section with divs nested inside. The first two on the top of the section were set to relative and they work. I've tried to set the rest to relative and they show on top of the first two divs. Help!
#portfolio {
width: 650px;
background-color: white;
margin-left: 75px;
margin-top: 120px;
margin-right: 40px;
margin-bottom: 200px;
padding: 15px;
float: left;
border: 1px solid #dddddd;
overflow: auto;
clear: both;
}
#blog {
position: relative;
float: left;
width: 40%;
}
#blog img{
float: left;
width: 100%;
margin-right: 10px;
position: absolute;
}
#blog p {
margin: 0;
position: absolute;
top: 125px;
color: white;
background-color: #41AAA5;
width: 100%;
padding-top: 7px;
padding-bottom: 7px;
text-align: center;
font-size: 20px;
}
#hangman {
position: relative;
float: right;
width: 40%;
}
#hangman img{
float: left;
width: 100%;
position: absolute;
}
#hangman p {
margin: 0;
position: absolute;
top: 125px;
color: white;
background-color: #41AAA5;
width: 100%;
padding-top: 7px;
padding-bottom: 7px;
text-align: center;
font-size: 20px;
}
#playlist {
position: relative;
float: left;
width: 40%;
}
#playlist img {
}
#playlist p {
}
<section id="portfolio">
<div id="blog">
<img src="assets/images/icon1.jpg">
<p>Blog</p>
</div>
<div id="hangman">
<img src="assets/images/icon2.jpg">
<p>Hangman Game</p>
</div>
<div id="playlist">
<img src="assets/images/icon3.jpg">
<p>Playlist</p>
</div>
<div id="maps">
<img src="assets/images/icon4.jpg">
<p>Map Page</p>
</div>
<div id="pets">
<img src="assets/images/icon5.jpg">
<p>Pets</p>
</div>
</section>
The positon:absolute on your img tags in blog and hangman divs was causing this problem. Postion:absolute element do not pick height so thats why everything was overlapping.
Here is your updated code:
#portfolio {
width: 650px;
background-color: white;
margin-left: 75px;
margin-top: 120px;
margin-right: 40px;
margin-bottom: 200px;
padding: 15px;
float: left;
border: 1px solid #dddddd;
overflow: auto;
clear: both;
}
#blog {
position: relative;
float: left;
width: 40%;
}
#blog img {
float: left;
width: 100%;
margin-right: 10px;
}
#blog p {
margin: 0;
position: absolute;
top: 125px;
color: white;
background-color: #41AAA5;
width: 100%;
padding-top: 7px;
padding-bottom: 7px;
text-align: center;
font-size: 20px;
}
#hangman {
position: relative;
float: right;
width: 40%;
}
#hangman img {
float: left;
width: 100%;
}
#hangman p {
margin: 0;
position: absolute;
top: 125px;
color: white;
background-color: #41AAA5;
width: 100%;
padding-top: 7px;
padding-bottom: 7px;
text-align: center;
font-size: 20px;
}
#playlist {
position: relative;
float: left;
width: 40%;
}
#playlist img {}
#playlist p {}
<section id="portfolio">
<div id="blog">
<img src="https://dummyimage.com/600x400/000/fff&text=blog">
<p>Blog</p>
</div>
<div id="hangman">
<img src="https://dummyimage.com/600x400/f00/fff&text=hangman">
<p>Hangman Game</p>
</div>
<div id="playlist">
<img src="https://dummyimage.com/600x400/0f0/fff&text=playlist">
<p>Playlist</p>
</div>
<div id="maps">
<img src="https://dummyimage.com/600x400/00f/fff&text=maps">
<p>Map Page</p>
</div>
<div id="pets">
<img src="https://dummyimage.com/600x400/ff0/fff&text=pets">
<p>Pets</p>
</div>
</section>
My text is pushing div element that contains them below.
slidepassos{
position: relative;
height: 100vh;
width: 100%;
background: rgba(0,0,0,1);
float: left;
margin-top: -1px;
}
#anchorHow{
margin-top: 65px;
width: 100%;
float: left;
}
.swipe {
overflow: hidden;
visibility: hidden;
position: relative;
}
.swipe-wrap{
overflow: hidden;
position: relative;
}
.swipe-wrap > div {
float: left;
width: 100%;
position: relative;
}
.passo-um{
height: 100vh;
width: 100%;
background: #000101;
}
.passoumback{
height: 100%;
width: 100%;
background-image: url("../img/passoumu.jpg");
background-position: top center;
}
.passoumgrad{
height: 100vh;
width: 100%;
background: rgba(0,37,63,0.7);
}
.passo-um h1{
color: white;
font-weight: bold;
font-size: 45px;
text-align: center;
}
.passo-um h2{
color: #EBAC00;
font-weight: bolder;
font-size: 53px;
text-align: center;
margin-top: 15px;
margin-left: 35%;
}
.passo-um p{
color: white;
padding: 18px 8%;
font-size: 20px;
font-weight: lighter;
text-align: center;
margin-top: 23px;
float: left;
}
.passoumilu {
width: 300px;
float: left;
margin-left: 9%;
margin-top: 50px;
}
.swipeleftcontent{
z-index: 1;
background-size: 60px 60px;
margin-left: 157px;
width: 60px;
height: 60px;
position: absolute;
bottom: 14%;
}
<div id="slidepassos" class="swipe slidepassos">
<div class="swipe-wrap">
<div class="mySlides">
<div class="passo-um">
<h1>How?</h1>
<h2>Step 1:</h2>
<img src="img/passoumilu.svg" class="passoumilu">
<p>Do your coach oriented WOD. Remember, know your limits and try to break them.</p>
<div class="passoumback">
<div class="passoumgrad"></div>
</div>
<img src="img/swipeleft.png" class="swipeleftcontent">
</div>
</div>
</div>
</div>
image showing the text on top of the DIV instead inside it.
example
Ive tried to mess with the floats, and inline-blocks, but nothing affects it. Dont know how to fix it.
yesterday I posted a question asking how can I center a div inside a div... Now I have another problem, I want to center a div on the screen. I want it to be in the middle and to take up 50% of the screen;
Here is a pic of the problem:
As you can see there isn't anything in the middle of the screen, that is my problem. Here is my HTML code:
* {
font-size: 100%;
font-family: Serif;
}
body {
background: url("images/background.jpg") repeat;
font-size: 100%;
}
.items {
background-color: rgba(0,0,0,.5);
width: 100%;
text-align: center;
margin: 0;
}
#basicInfo{
background-color: rgba(255,150,0,.8);
width: 100px;
height: 100px;
display: inline-block;
margin-top: 10px;
margin-bottom: 10px;
}
#basicInfo:hover{
background-color: rgba(255,150,0,1);
}
#basicInfo img{
display: block;
margin-left: auto;
margin-right: auto;
padding-top: 16px;
}
#langs{
background-color: rgba(255,150,0,.8);
width: 100px;
height: 100px;
display: inline-block;
margin-top: 10px;
margin-bottom: 10px;
}
#langs img{
display: block;
margin-left: auto;
margin-right: auto;
padding-top: 16px;
}
#langs:hover{
background-color: rgba(255,150,0,1);
}
.navbar {
background-color: rgba(0,0,0,0.1);
position: fixed;
bottom: 0px;
left: 0px;
right: 0px;
width: 100%;
min-height: 5%;
}
.button{
background-color: rgba(0,0,0,.5);
font-size: 2em;
color: white;
width: 33%;
margin: 0 .16%;
height: 100%;
float: left;
}
.button:hover{
background-color: rgba(0,0,0,.7);
}
.button a{
text-decoration: none;
display: block;
color: white;
text-align: center;
vertical-align: middle;
}
#textSpace {
background-color: rgba(0,0,0, .5);
width: 100%;
height: 50%;
display: block;
top: auto;
bottom: auto;
}
<title>Mateo's About Page</title>
</head>
<body>
<div class="items">
<div id="basicInfo">
<img src="images/question.png">
</div>
<div id="langs">
<img src="images/code.jpg">
</div>
</div>
<div id="textSpace">
</div>
<div class="navbar">
<div class="button">
<b>Mateo</b>
</div>
<div class="button">
<b>Home</b>
</div>
<div class="button">
<b>Josh</b>
</div>
</div>
Any help is apriciated! Thanks in advance!
To horizontally centre a div in the middle of the screen use:
margin-left:auto;
margin-right:auto;