Example: https://jsfiddle.net/La9jd2y7/
.one {
height: 50px;
width: 200px;
background-color: #F60;
float: left;
text-align: center;
}
.two {
height: 25px;
width: 25px;
background-color: #6F0;
float: left;
text-align: center;
}
.three {
height: 25px;
width: 25px;
background-color: #F20;
float: left;
text-align: center;
}
.four {
height: 50px;
width: 200px;
background-color: #C90;
float: left;
text-align: center;
}
<div class="one">1</div>
<div class="two">2</div>
<div class="three">3</div>
<div class="four">4</div>
I need div 3 to go below div 2, so the left of div 4 pushed up against 2 and 3.
Result: http://i.imgur.com/N8VZ4HO.png
Thanks.
Try this:
.one {
height: 50px;
width: 200px;
background-color: #F60;
float: left;
text-align: center;
}
.two {
height: 50px;
width: 25px;
background-color: #6F0;
float: left;
text-align: center;
}
.two >div {
height: 25px;
}
.four {
height: 50px;
width: 200px;
background-color: #C90;
float: left;
text-align: center;
}
<div class="one">1</div>
<div class="two">
<div>2</div>
<div>3</div>
</div>
<div class="four">4</div>
So, as you notice I've changed the HTML to place the 2 and 3 inside the .two. That way you have 3 columns, and 2 and 3 are inside the middle column. No need for 4 columns.
Here is Demo
HTML:
<div class="one">1</div>
<div class="box">
<div class="two">2</div>
<div class="three">3</div>
</div>
<div class="four">4</div>
CSS:
.one {
height: 50px;
width: 200px;
background-color: #F60;
float: left;
text-align: center;
}
.two {
height: 25px;
width: 25px;
background-color: #6F0;
float: left;
text-align: center;
}
.three {
height: 25px;
width: 25px;
background-color: #F20;
float: left;
text-align: center;
}
.four {
height: 50px;
width: 200px;
background-color: #C90;
float: left;
text-align: center;
}
.box{
float: left;
width:25px
}
https://jsfiddle.net/La9jd2y7/3/
Try this:
.three {
height: 25px;
width: 25px;
background-color: #F20;
float: left;
text-align: center;
margin-top: 25px;
margin-left: -25px;
}
DEMO
.one {
height: 50px;
width: 200px;
background-color: #F60;
float: left;
text-align: center;
}
.two {
height: 25px;
width: 25px;
background-color: #6F0;
float: left;
text-align: center;
}
.three {
height: 25px;
width: 25px;
background-color: #F20;
float: left;
text-align: center;
}
.four {
height: 50px;
width: 200px;
background-color: #C90;
float: left;
text-align: center;
}
.two+.three{
margin-top: 25px;
margin-left: -25px;
}
<div class="one">1</div>
<div class="two">2</div>
<div class="three">3</div>
<div class="four">4</div>
Related
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;
}
I want to put my "why you should buy from us" on top of the large grey container but don't know how to as when I centre the text the containers all shift downwards preventing the text to overlap, does anyone know a fix to this?
#whybuy {
color: #ffcc00;
font-size: 40px;
margin: 0 auto;
margin-top: 200px;
text-align: center;
}
#largebox {
width: 1890px;
height: 475px;
background-color: #2c2c2c;
padding-top: 100px;
padding-left: 20px;
padding-right: 20px;
margin: 0 auto;
margin-top: 200px;
}
#box1 {
height: 450px;
width: 300px;
background-color: #232323;
float: left;
margin-left: 425px;
}
#box2 {
height: 450px;
width: 300px;
background-color: #232323;
float: left;
margin-left: 325px;
}
#box3 {
height: 450px;
width: 300px;
background-color: #232323;
float: left;
margin-left: 325px;
}
<h1 id="whybuy">WHY BUY FROM US</h1>
<div id="largebox">
<div id="box1">
<div id="box2">
<div id="box3">
</div>
</div>
</div>
</div>
This will put your text on the largebox.
#whybuy {
color: #ffcc00;
font-size: 40px;
position: absolute;
width: 100%
text-align: center;
z-index: 1;
#largebox {
width: 1890px;
height: 475px;
background-color: #2c2c2c;
padding-top: 100px;
padding-left: 20px;
padding-right: 20px;
margin: 0 auto;
display: relative
}
#box1 {
height: 450px;
width: 300px;
background-color: #232323;
float: left;
margin-left: 425px;
}
#box2 {
height: 450px;
width: 300px;
background-color: #232323;
float: left;
margin-left: 325px;
}
#box3 {
height: 450px;
width: 300px;
background-color: #232323;
float: left;
margin-left: 325px;
}
check the margin for #largebox; it has margin-top: 200px;
#largebox {
width: 1890px;
height: 475px;
background-color: #2c2c2c;
padding-top: 100px;
padding-left: 20px;
padding-right: 20px;
margin: 0 auto;
//margin-top: 200px;
}
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>
I started learning CSS3 and got a problem, i want to create 4 black boxes(divs), and put them on in one line, 3 of them work properly, but 4th is moving to new line, what am i doing wrong?
My guess would be that its because of the 10px margin, but i dont know how to do it properly.
* {
margin: 0px;
padding: 0px; }
body {
font-family: Roboto, sans-serif;
box-sizing: border-box; }
#wrapper {
width: 1000px;
margin-left: auto;
margin-right: auto; }
#block1 {
width: 25%;
height: 100px;
background-color: black;
float: left;
margin-right: 10px; }
#block2 {
width: 25%;
height: 100px;
background-color: black;
float: left;
margin-right: 10px; }
#block3 {
width: 25%;
height: 100px;
background-color: black;
float: left;
margin-right: 10px; }
#block4 {
width: 25%;
height: 100px;
background-color: black;
float: left;
margin-right: 10px; }
<body>
<div id="wrapper">
<div id="block1"></div>
<div id="block2"></div>
<div id="block3"></div>
<div id="block4"></div>
</div> </body>
body {
font-family: Roboto, sans-serif; box-sizing: border-box;
}
#wrapper {
width: 1000px;
margin: 0 auto;
}
#block1 {
width: calc(25% - 10px);
height: 100px;
background-color: black;
float: left;
margin-right: 10px; }
#block2 {
width: calc(25% - 10px);
height: 100px;
background-color: black;
float: left;
margin-right: 10px; }
#block3 {
width: calc(25% - 10px);
height: 100px;
background-color: black;
float: left;
margin-right: 10px; }
#block4 {
width: calc(25% - 10px);
height: 100px;
background-color: black;
float: left;
margin-right: 10px;
}
<div id="wrapper">
<div id="block1">
Stuff1
</div>
<div id="block2">
Stuff2
</div>
<div id="block3">
Stuff3
</div>
<div id="block4">
Stuff4
</div>
</div>
You need to substract your margin-right value from your width, otherwise it adds up to more than 100% width.
Try
width: calc(25% - 10px);
height: 100px;
background-color: black;
float: left;
margin-right: 10px; }
Or try reducing your % by 1%.
#block4 {
width: 24%;
height: 100px;
background-color: black;
float: left;
margin-right: 10px;
}
I can not set the scroll to this item that has the property display: inline
I tried it with white-space: nowrap but does not work
while repositioning overflow under a height
I did not have any changeis the second question I ask above getilmente give me a hand
Solution:
Used inline-block
#Contenitore_Titoli
{
width: 1535px;
height: 30px;
line-height: 35px;
text-align: center;
}
.Elenco_Utenti
{
width: 360px;
height: 25px;
line-height: 25px;
float: left;
text-align: center;
}
.Elenco_Contatti_Whatsapp
{
width: 371px;
height: 25px;
line-height: 25px;
float: left;
text-align: center;
}
.Elenco_Contatti_Skype
{
width: 371px;
height: 25px;
line-height: 25px;
float: left;
text-align: center;
}
.Elenco_Contatti_Facebook
{
width: 371px;
height: 25px;
line-height: 25px;
float: left;
text-align: center;
}
.Contenitore_Lista_Contatti
{
border-top: 1px solid gray;
width: 1480;
height: 25px;
}
#Contatti
{
width: 360px;
height: 31px;
float: left;
color: red;
display: inline;
text-align: center;
}
#Contatti_Whatsapp_Titolo
{
width: 371px;
height: 31px;
color: red;
display: inline;
text-align: center;
float: left;
}
#Contatti_Skype_Titolo
{
width: 371px;
height: 31px;
color: red;
display: inline;
text-align: center;
float: left;
}
#Contatti_Facebook_Titolo
{
width: 371px;
height: 31px;
color: red;
display: inline;
text-align: center;
float: left;
}
#Contenuto_Lista_Guide_Div
{
display: inline;
overflow-y: scroll;
height: 637px
}
<div id="Contenitore_Titoli">
<div id="Contatti">Nome Utente</div>
<div id="Contatti_Whatsapp_Titolo">Whatsapp</div>
<div id="Contatti_Skype_Titolo">Skype</div>
<div id="Contatti_Facebook_Titolo">Facebook</div>
</div>
<div id="Contenuto_Lista_Guide_Div">
<div class="Contenitore_Lista_Contatti">
<div class="Elenco_Utenti"> darkbit </div>
<div class="Elenco_Contatti_Whatsapp"> 345956254</div>
<div class="Elenco_Contatti_Skype"> pipposkype </div>
<div class="Elenco_Contatti_Facebook">facebook</div>
</div>
</div>
You need to use CSS property overflow to scroll after setting a height.
For example, write a class like following:
.aClass{
height: 250px;
overflow: scroll;
}
You can see the overflow property here: http://www.w3schools.com/cssref/pr_pos_overflow.asp