For some reason I can't align my divs next to each other. "Right" goes under "left"
What is wrong with my code?
HTML:
<div id="activity-container">
<div id="activity-left">left</div>
<div id="activity-right">right</div>
</div>
CSS:
#activity-container
{
width:90%;
background-color:#FFFF00;
Height:400px;
margin-left: auto;
margin-right: auto;
}
#activity-left {
border: 1px solid black;
color:#000;
margin: 0 auto;
width: 20%;
float: left;
position: relative;
}
#activity-right {
border: 1px solid black;
margin: 0 auto;
color:#000;
width: 80%;
float: left;
position: relative;
}
Live demo: Tinkerbin
Your borders on the div-s adding 2px to their width. Remove them and they will be next to each other - jsFiddle
If you really need the borders, then mimic them with outline - jsFiddle
#activity-left {
outline: 1px solid #000;
color:#000;
margin: 0 auto;
width: 20%;
float: left;
position: relative;
}
#activity-right {
outline: 1px solid #000;
margin: 0 auto;
color:#000;
width: 80%;
float: left;
position: relative;
}
You only need to remove float and margin properties from CSS
#activity-right
{
border: 1px solid black;
color: #000;
width: 80%;
position: relative;
}
Than it will work as per your expectation.
If you want to retain the border, you can try changing the width:
#activity-container
{
width:90%;
background-color:#FFFF00;
Height:400px;
margin-left: auto;
margin-right: auto;
}
#activity-left {
border: 1px solid black;
color:#000;
margin: 0 auto;
width: 19%;
float: left;
position: relative;
}
#activity-right {
border: 1px solid black;
margin: 0 auto;
color:#000;
width: 80%;
float: left;
position: relative;
}
Check Jsfiddle
Related
I am running always to same issues with top navigation bar and footer. I always have problem to place them on the correct position.
Top nav : the logo should be on top left and rest align to right
Footer: is in the middle of the page even though I followed a recommendation and created main container for all divs on my page.
CSS & image attached to the question
html,body {
margin:0;
padding:0;
height:100%;
color: #696969;
}
#mainContainer{
min-height:100%;
position:relative;
}
header{
background-color:#F8F8F8;
height: 120px;
border-bottom: 1px solid #CDCDCD;
display: flex;
}
.topnav {
margin-left: 12%;
margin-right: 12%;
margin-top: 5%;
position: absolute;
align-items: flex-start;
float: right;
}
.topnav a {
float: right;
display: block;
color: #343434;
padding: 10px 10px;
text-decoration: none;
font-size: 20px;
}
.topnav a.active {
color: #4CAF50;
}
.sidebar {
margin-left: 12%;
padding: 0;
width: 12%;
position: absolute;
height: 100%;
overflow: auto;
}
.sidebar a {
display: block;
color: #696969;
padding: 15px;
text-decoration: none;
border-bottom: 1px solid #F8F8F8;
border-right: 1px solid #F8F8F8;
}
section {
margin-left: 25%;
margin-right: 12%;
position: absolute;
display: inline-block;
border-bottom: 1px solid #F8F8F8;
}
#footer{
position:absolute;
bottom:0;
width:100%;
height:60px;
color: #696969;
}
footer {
display: flex;
position: absolute;
bottom: 60px;
border-bottom: 1px solid #F8F8F8;
border-top: 1px solid #F8F8F8;
}
.rights{
text-align:left;
padding: 10px 10px;
}
.socialnets{
text-align:center;
padding: 10px 10px;
}
.newsletter{
text-align:right;
padding: 10px 10px;
}
setting 100% height on body inherits from viewport essentially. thats why the footer is fixed at the bottom of the pixel value for your viewport and if you scroll, it doesn't 'stick'.
I'm guessing this is what you want?..
I have no idea what structure your html is so this is just going off your css.
I would advise looking at flexbox and checking out the sticky footer method using flex.
https://codepen.io/devatrox/pen/wztlx
html,body {
margin:0;
padding:0;
min-height:100vh;
height:100%;
color: #696969;
}
#mainContainer{
min-height:100%;
position:relative;
}
header{
background-color:#F8F8F8;
height: 120px;
border-bottom: 1px solid #CDCDCD;
display: flex;
}
.topnav {
margin-left: 12%;
margin-right: 12%;
margin-top: 5%;
position: absolute;
align-items: flex-start;
float: right;
}
.topnav a {
float: right;
display: block;
color: #343434;
padding: 10px 10px;
text-decoration: none;
font-size: 20px;
}
.topnav a.active {
color: #4CAF50;
}
.sidebar {
margin-left: 12%;
padding: 0;
width: 12%;
position: absolute;
overflow: auto;
background-color: red;
height: calc(100% - 121px);
}
.sidebar a {
display: block;
color: #696969;
padding: 15px;
text-decoration: none;
border-bottom: 1px solid #F8F8F8;
border-right: 1px solid #F8F8F8;
}
section {
margin-left: 25%;
margin-right: 12%;
display: inline-block;
border-bottom: 1px solid #F8F8F8;
}
#footer{
position:relative;
bottom:0;
width:100%;
height:60px;
color: #696969;
background-color:blue;
}
footer {
display: flex;
position: absolute;
bottom: 60px;
border-bottom: 1px solid #F8F8F8;
border-top: 1px solid #F8F8F8;
}
.rights{
text-align:left;
padding: 10px 10px;
}
.socialnets{
text-align:center;
padding: 10px 10px;
}
.newsletter{
text-align:right;
padding: 10px 10px;
}
<div id="mainContainer"><header><div class="topnav">top</div></header><div class="sidebar">side</div><section>Content <h1>heading</h1><p>TExt or stuff idk</p></section><section>Content <h1>heading</h1><p>TExt or stuff idk</p></section><section>Content <h1>heading</h1><p>TExt or stuff idk</p></section>
<div id="footer">FOOTER</footer>
I have three divs in page called header, content and footer. Header is showing at top and have no issue.
The following css is not working properly with inner div (Content) to fit its content and screen display.
While I want to
expand inner div to fill screen size and footer remain at bottom.
Keep divs in order
fill content always
I have tried many css solutions but nothing works perfect to fit div at page and content both.
.header {
background-color: #bf4b4b ;
/*margin-left: 14%;*/
top: 0;
border-width: 0.1em;
border-color: #999;
border-style: solid;
width: 100%;
height: 80px;
}
.content {
background-color: #ffffff;
margin-left: 25%;
margin-top: 5px;
float: left;
width: 46%;
border-width: 0.1em;
border-color: #999;
border-style: solid;
border-radius: 25px;
padding: 20px;
flex: 1 1 auto;
}
.footer {
background-color: #243b82 ;
/* margin-left: 14%;
float: left;*/
margin-top: 5px;
width: 100%;
height: 80px;
border-width: 0.1em;
border-color: #999;
border-style: solid;
color:white;
text-align: center;
/*
display:inline-block;
vertical-align:middle;
*/
display: inline-block;
vertical-align: bottom;
}
Please note its wordpress theme and woocommerce pages need to show inside inner div
check this jfiddle and tell me if it works as you wanted thank you.
body{
margin:0px;
}
.header{
background-color:#bf4b4b;
height:80px;
width:100%;
position:fixed;
top:0px;
left:0px;
}
.content{
height:100vh;
padding:80px 0px;
background-color:#FFFFFF;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.footer{
background-color:#243b82;
height:80px;
width:100%;
position:fixed;
bottom:0px;
left:0px;
}
Flex display could be a great option here. It looks like you started down that path already. Adding a surrounding container with a min-height of the full window, "100vh", might accomplish what you're looking for. Let me know how this works out:
<div class="container">
<div class="header">
</div>
<div class="content">
</div>
<div class="footer">
</div>
</div>
.container {
display: flex;
width: 100%;
min-height: 100vh;
flex-direction: column;
}
.header {
background-color: #bf4b4b ;
/*margin-left: 14%;*/
top: 0;
border-width: 0.1em;
border-color: #999;
border-style: solid;
width: 100%;
height: 80px;
}
.content {
background-color: #ffffff;
margin-left: 25%;
margin-top: 5px;
float: left;
width: 46%;
border-width: 0.1em;
border-color: #999;
border-style: solid;
border-radius: 25px;
padding: 20px;
flex: 1 1 auto;
}
.footer {
background-color: #243b82 ;
/* margin-left: 14%;
float: left;*/
margin-top: 5px;
width: 100%;
height: 80px;
border-width: 0.1em;
border-color: #999;
border-style: solid;
color:white;
text-align: center;
/*
display:inline-block;
vertical-align:middle;
*/
display: inline-block;
vertical-align: bottom;
}
http://codepen.io/amishstripclub/pen/gwNGXw?editors=1100
I have solved using overflow property and sticky footer as below:
.header {
background-color: #bf4b4b ;
top: 0;
border-width: 0.1em;
border-color: #999;
border-style: solid;
width: 100%;
height: 80px;
position: fixed;
right: 0;
left: 0;
}
.content {
background-color: #ffffff;
margin-left: 25%;
margin-top: 5%;
width: 46%;
border-width: 0.1em;
border-color: #999;
border-style: solid;
border-radius: 25px;
padding: 20px;
overflow:auto;
min-height: 100%;
height: auto !important;
height: 100%;
}
.footer {
background-color: #243b82 ;
width: 100%;
height: 80px;
border-width: 0.1em;
border-color: #999;
border-style: solid;
color:white;
text-align: center;
}
My fiddle: http://jsfiddle.net/f5e5d/1/
.item-data {
width:34px;
height:34px;
background-size: 34px auto !important;
margin: 2px;
border: 1px solid #000;
display:table-cell;
}
.test_div {
background-color: #eee;
width: 100%;
padding: 20px;
}
.match_details {
display:table-cell;
}
I want to show only 3 pictures in one line. How can I do it?
Now I have displayed all 6 items in 1 line.
Thanks in advance!
Like this: http://jsfiddle.net/NicoO/f5e5d/4/
.item-data {
width:34px;
height:34px;
background-size: 34px auto !important;
margin: 2px;
border: 1px solid #000;
float: left;
}
.item-data:nth-child(3n+1)
{
clear: left;
}
.test_div {
background-color: #eee;
overflow: hidden;
padding: 20px;
}
I am trying to make an arrow overlap onto the div below it (the way the gray arrow overlaps onto the red on http://tinyletter.com).
Here is the code I am currently using:
#box_1 {
height: 550px;
width: 100%;
font-size: 4.5em;
font-weight: 600;
float: center;
text-align: center;
background-color: #ededed;
padding: 55px 0 0 0;
}
.arrow-down {
width: 0;
height: 0;
border-left: 50px solid transparent;
border-right: 50px solid transparent;
border-top: 50px solid #ededed;
margin-left:auto;
margin-right:auto;
}
#box_2 {
height: 600px;
width: 100%;
font-size: 7em;
float: center;
text-align: center;
background-color: #ed2227;
}
If you're able to rely upon use of the ::after (or ::before) pseudo-elements, then this is relatively easy simply using borders:
#top {
position: relative;
background-color: #ccc;
}
#top::after {
position: absolute;
content: '';
top: 100%;
left: 50%;
margin: 0 0 0 -1em;
border: 1em solid transparent;
border-top: 1em solid #ccc;
}
JS Fiddle demo.
So I'm trying to vertical align images within a container div. I tried adding vertical-align: middle; to the parent div with no luck.
<div class="contributor_thumbnail"><img src="image.jpg"></div>
<div class="contributor_thumbnail"><img src="image.jpg"></div>
.contributor_thumbnail {
position: relative;
display: block;
float: left;
width: 150px;
height: 150px;
line-height: 100%;
text-align: center;
margin-right: 15px;
margin-bottom: 15px;
padding: 5px;
vertical-align: middle;
border: 1px solid #bbbbbb;
border-top: 1px solid #333;
border-left: 1px solid #333;
}
What I would do is set the image as a background image.
.contributor_thumbnail {
/* Background image instead of using and img tag */
background: url(image.jpg) center center no-repeat;
position: relative;
display: block;
float: left;
width: 150px;
height: 150px;
line-height: 100%;
text-align: center;
margin-right: 15px;
margin-bottom: 15px;
padding: 5px;
border: 1px solid #bbbbbb;
border-top: 1px solid #333;
border-left: 1px solid #333;
}
Try this:
HTML
<div class="contributor_thumbnail">
<div class="content">
<img src="image.jpg">
</div>
</div>
CSS:
.contributor_thumbnail {float:left; height:50%; margin-bottom:-120px;}
.content {clear:both; height:240px; position:relative;}
Inspired by: Lost in the Woods vertically centering with CSS.
.contributor_thumbnail img {
margin-left: auto;
margin-right: auto;
}
http://www.bluerobot.com/web/css/center1.html