I want column 1 (comment 1) and column 2 (comment 2) to be next to each other and to be floated to the left side. Column 3 (comment 3) should be floated to the right side.
jsfiddle
I've tried a lot but can't make it work with %.
HTML:
<div class="comment_one">
<div class="reitings">
<div class="rate pluss"><img class="plus" alt="" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAIAQMAAAD3KoyyAAAAA1BMVEX///+nxBvIAAAAAXRSTlMAQObYZgAAAAtJREFUeNpjYMAOAAAYAAFG27MLAAAAAElFTkSuQmCC"> 83</div>
</div>
</div>
<div class="comment_two">
<div class="reitings">
<div class="rate minuss"><img class="minus" alt="" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAIAQMAAAD3KoyyAAAAA1BMVEX///+nxBvIAAAAAXRSTlMAQObYZgAAAAtJREFUeNpjYMAOAAAYAAFG27MLAAAAAElFTkSuQmCC"> 9</div>
</div>
</div>
<div class="comment_three">
<div class="reitings">
<div class="rate minuss"><img class="minus" alt="" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAIAQMAAAD3KoyyAAAAA1BMVEX///+nxBvIAAAAAXRSTlMAQObYZgAAAAtJREFUeNpjYMAOAAAYAAFG27MLAAAAAElFTkSuQmCC">Report</div>
</div>
</div>
CSS:
.comment_one {
width:25%;
float:left;
}
.comment_two {
width:25%;
float:left;
}
.comment_three {
float:right;
width:40%;
}
.reitings {
display:table;
width:50%;
border:1px solid #e9e9e9;
-webkit-border-radius:4px;
-moz-border-radius:4px;
border-radius:4px;
}
.rate {
display:table-cell;
text-align:center;
vertical-align:middle;
line-height:1.5em;
padding:10%;
}
.rate img {
vertical-align:middle
}
.pluss {
background:#f5f5f5;
color:#4d761a
}
.minuss {
background:#f5f5f5;
color:#a8404b;
border-left:1px solid #e9e9e9;
text-align:center
}
Structure the HTML:
<div id="comments">
<div class="c1 rate-plus"></div>
<div class="c2 rate-plus"></div>
<div class="c3 rate-minus"></div>
</div>
Access all divs in #comments with #comments div. Think about what the divs have in common. Write it in the CSS. For Example:
#comments div {
background: #f5f5f5;
border-left: 1px solid #e9e9e9;
padding: 12px;
margin: 5px;
text-align: center;
}
Float c1 and c2 with left and c3 with right.
Complete CSS
#comments div {
background: #f5f5f5;
border-left: 1px solid #e9e9e9;
padding: 12px;
margin: 5px;
text-align: center;
}
.rate-plus {
color: #4d761a
}
.rate-minus {
color: #a8404b;
}
.c1, .c2 {
width: 25%;
float: left;
}
.c3 {
width: 37%;
float: right;
}
Complete HTML
<div id="comments">
<div class="c1 rate-plus">
<img class="plus" alt="" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAIAQMAAAD3KoyyAAAAA1BMVEX///+nxBvIAAAAAXRSTlMAQObYZgAAAAtJREFUeNpjYMAOAAAYAAFG27MLAAAAAElFTkSuQmCC">83
</div>
<div class="c2 rate-minus">
<img class="minus" alt="" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAIAQMAAAD3KoyyAAAAA1BMVEX///+nxBvIAAAAAXRSTlMAQObYZgAAAAtJREFUeNpjYMAOAAAYAAFG27MLAAAAAElFTkSuQmCC">9
</div>
<div class="c3 rate-minus">
<img class="minus" alt="" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAIAQMAAAD3KoyyAAAAA1BMVEX///+nxBvIAAAAAXRSTlMAQObYZgAAAAtJREFUeNpjYMAOAAAYAAFG27MLAAAAAElFTkSuQmCC">Report
</div>
</div>
I've modified it a little bit.
Demo
Related
I've been trying to add two div containers into another one. One floating on the left and the other one on to the right side of the main container. The problem is, if I add float:left on the first div, it's no longer contained in the main container.
Before adding float: https://imgur.com/a/OACA7Su
After adding it: https://imgur.com/a/ukeZoae
HTML:
<div class="container">
<div class="column1">
<div class="rowTop">
<p>Community</p>
</div>
<div class="row">
<div id="leftSide">
<h3><a>Disscusion</a></h3>
<p>→ Disscusions about various games like Warframe or HuntShowdown</p>
</div>
<div id="rightSide">
0:Threds
</div>
</div>
<div class="row">
</div>
<div class="row">
</div>
</div>
<div class="column2">
</div>
</div>
CSS:
.container{
margin:30px;
}
.column1{
width:70%;
float:left;
}
.column2{
width:15%;
float:right;
padding:2px;
}
.rowTop{
background-color: rgb(0, 51, 0);
border:1px solid white;
border-top-left-radius: 10px;
border-top-right-radius: 10px;
width:10%;
text-align: center;
text-shadow: black 1px 1px;
color:white;
}
.row{
background-color: black;
border:1px solid white;
color:white;
display: block;
padding:0;
}
.row #leftSide{
color:white;
float: left;
margin-right: 0;
width: 55%;
}
Thanks in advance for the help.
Please don't give me any hate, I'm new to coding :3
You can use Flexbox for this. Check out the guide for your CSS. Just change the display to flex:
.row{
background-color: black;
border:1px solid white;
color:white;
display: flex;
flex-direction: row
padding:0;
}
This is my sample html code:
.questions-table-main {
border-right: 3px solid rgb(242,244,247);
width:189px;
float:left;
padding-right:30px;
padding-top:10px;
display:table;
height: 200px;
}
.questions-table-main-category {
/* padding-top: 20px; */
text-align : center;
}
.questions-table-main-firm {
height:85px;
background-color:rgb(242,244,247);
text-align: center;
display: table-row;
vertical-align: bottom;
}
<div class="questions-table-main">
<div class="questions-table-main-category">
<img src="img/communication.png" alt="communication"/>
</div>
<div class="questions-table-main-firm">
<div class="questions-table-main-firm-image">
<span class="questions-table-firm-helper">
<img src="img/allianz.png" alt="allianz" /></span>
</div>
</div>
</div>
Let me clear this mess. I need to put <div class="questions-table-main-firm"> on the bottom of <div class="questions-table-main">. Next thing I need to do is that <div class="questions-table-main-category"> must be above <div class="questions-table-main-firm"> with 27px space between them. I was trying to do that with padding-top, but it's impossible because i have some different images with different dimensions. Now <div class="questions-table-main-category"> is on the top of parrent div. How to fix that ?
You can do it by using position: absolute; and top. For bottom div use top: 0 so that it says at top and for first div use top: 112px including height(85) and margin 27.
.questions-table-main {
border-right: 3px solid rgb(242,244,247);
width:189px;
padding-right:30px;
padding-top:10px;
display:block;
height: 200px;
position: relative;
}
.questions-table-main-category {
text-align : center;
height:85px;
top: 112px; /* height 85 + 27 margin*/
position: absolute;
}
.questions-table-main-firm {
height:85px;
background-color:rgb(242,244,247);
text-align: center;
top: 0px;
position: absolute;
}
<div class="questions-table-main-category">
<img src="https://placehold.it/189x85" alt="communication"/>
</div>
<div class="questions-table-main-firm">
<div class="questions-table-main-firm-image">
<span class="questions-table-firm-helper">
<img src="https://placehold.it/189x85" alt="allianz" /></span>
</div>
</div>
</div>
You need to remove the display table atributes, do it as follows:
.questions-table-main {
width:189px;
float:left;
padding-right:30px;
padding-top:10px;
height: 200px;
}
.questions-table-main-category {
/* padding-top: 20px; */
text-align : center;
margin-bottom: 27px;
}
.questions-table-main-firm {
background-color:rgb(242,244,247);
text-align: center;
vertical-align: bottom;
}
<div class="questions-table-main">
<div class="questions-table-main-category">
<img src="http://placehold.it/350x150" alt="communication"/>
</div>
<div class="questions-table-main-firm">
<div class="questions-table-main-firm-image">
<span class="questions-table-firm-helper">
<img src="http://placehold.it/350x150" alt="allianz" /></span>
</div>
</div>
</div>
I want to have 2 elements in a div but only one should be visible, and I want to have a vertical scrollbar.
Unfortunately, the second element is visible and there is no scrollbar.
#visu {
top:10px;
height:180px;
width:50%;
overflow:auto;
background-color:yellow;
}
#element1 {
position:absolute;
top:15px;
left:80px;
}
#element2 {
position:absolute;
top:200px;
left:80px;
}
.element {
margin-right:-50px;
}
.namecontainer {
display:flex;
border:4px solid #000033; border-radius:10px;
padding:10px; box-sizing:border-box;
background-color:white;
width:280px;
height:150px;
margin-left:0px;
align-items: center;
justify-content:center:
color:#1a1a1a;
}
.namecontainer p {
font-size:35px;
font-family: 'Arial';
font-weight:bold;
color:#1a1a1a;
text-align:center;
width:380px;
}
<div id="visu">
<div id="element1" class="element">
<div class="namecontainer">
<p class= "name" id="name1" >element 1</p>
</div>
</div>
<div id="element2" class="element">
<div class="namecontainer">
<p class= "name" id="name3" >element 2</p>
</div>
</div>
</div>
You need to play with margin and drop absolute positionnong cause it takes element off the flow and is not necessary here https://jsfiddle.net/vpdc5L4m/13/
#visu {
top: 10px;
height: 180px;
width: 50%;
overflow: auto;
background-color: yellow;
}
#element1 {}
#element2 {}
.element {
margin: 15px auto ;
}
.namecontainer {
display: flex;
border: 4px solid #000033;
border-radius: 10px;
padding: 10px;
box-sizing: border-box;
background-color: white;
width: 280px;
height: 150px;
margin:auto;
align-items: center;
justify-content: center: color: #1a1a1a;
}
.namecontainer p {
font-size: 35px;
font-family: 'Arial';
font-weight: bold;
color: #1a1a1a;
text-align: center;
width: 380px;
}
<div id="visu">
<div id="element1" class="element">
<div class="namecontainer">
<p class="name" id="name1">element 1</p>
</div>
</div>
<div id="element2" class="element">
<div class="namecontainer">
<p class="name" id="name2">element 2</p>
</div>
</div>
<div id="element3" class="element">
<div class="namecontainer">
<p class="name" id="name3">a third one ?</p>
</div>
</div>
</div>
To hide a CSS element, you can use
display: none;
Following is my fiddle in which I am trying to give hr line between two floating divs . Kindly let me know how can I give a responsive line between two floating divs.
http://jsfiddle.net/NH5Lc/5/
<div style="display:inline-block; float: left;">Calories</div>
<div style="inline-block">
<hr class="between" />
</div>
<div style="display:inline-block; float: right;">20</div>
<br/>
<div style="display:inline-block; float: left;">Calories</div>
<div style="inline-block">
<hr class="between" />
</div>
<div style="display:inline-block; float: right;">20</div>
You can use flex too. jsFiddle Live Demo
.between {
border: 3px dotted #0099CC;
margin-left:10px;
margin-right:10px;
}
.parent
{
display:-moz-box; /* Firefox */
display:-webkit-box; /* Safari and Chrome */
display:-ms-flexbox; /* Internet Explorer 10 */
display:box;
width:100%;
}
.child2
{
-moz-box-flex:5.0; /* Firefox */
-webkit-box-flex:5.0; /* Safari and Chrome */
-ms-flex:9.0; /* Internet Explorer 10 */
box-flex:9.0;
}
<div class='parent'>
<div class='child1'>Calories</div>
<div class='child2'> <hr class="between" /></div>
<div class='child3'>20</div>
</div>
<div class='parent'>
<div class='child1'>Calories as dasd as dasd</div>
<div class='child2'> <hr class="between" /></div>
<div class='child3'>20</div>
</div>
paste it your between class
.between {
width: 500px;
float: left;
border-right: 1px solid gray;
}
<div style="border-top:1px solid black; width:100%;"></div> will do it. As Gert B. says, you should really be using a linked file rather than inline styles though. In which case, you would have in your CSS file:
.line{
border-top:1px solid black;
width:100%
}
Then in your markup:
<div class="line"></div>
it seems like you could use a <table> or at least a list <ul> for what you are trying to do .
With a list, you can use text-align, float and pseudo-element .
http://codepen.io/gc-nomade/pen/Bmhqc
ul, li {
padding:0;
margin:0;
list-style-type:none;
text-align:right;
}
li em {
float:left;
}
li em:after {
content:'';
border-bottom:dotted;
width:2000px;
margin-right:-2000px;/* reduce space needed to 0 */
display:inline-block;
vertical-align:middle;
}
li, span {
background:white;
overflow:hidden; /* hide pseudo line overflow */
}
<ul>
<li><em>calorie</em><span>20</span></li>
<li><em>calorie</em><span>20</span></li>
<li><em>calorie</em><span>20</span></li>
<li><em>calorie</em><span>20</span></li>
</ul>
Html
<div id="outer">
<div id="left">Calories</div>
<div id="middle">
<hr class="between" />
</div>
<div id="right">20</div>
</div>
<br>
<br>
<div id="outer">
<div id="left">Calories</div>
<div id="middle">
<hr class="between" />
</div>
<div id="right">20</div>
</div>
CSS
#outer {
display:block;
width: 100%;
}
#left {
width: 100px;
float: left;
text-align:center;
}
#right {
width: 200px;
float: right;
text-align:center;
}
#middle {
float: left;
}
.between {
border: 3px dotted #0099CC;
width:200px;
margin-left:10px;
margin-right:10px;
}
Output:
Working fiddle
I have type of card created. It has 3 rows with a p and a div. I want both of them to come in the same line. How can I do this?
HTML:
<div class="user_card">
<div class="skills">
<p>Skills</p>
<div class="progress_wrap">
<div class="progress" style="width:95%"></div>
</div>
</div>
<div class="commitment">
<p>Commitment</p>
<div class="progress_wrap">
<div class="progress" style="width:35%;"></div>
</div>
</div>
<div class="reputation">
<p>Reputation</p>
<div class="progress_wrap">
<div class="progress" style="width:65%;"></div>
</div>
</div>
</div>
CSS:
.user_card {
background-color: #eee;
width: 30%;
padding: 10px;
}
.user_card div p {
display: inline;
}
.user_card div.skills {
margin-left: -1px;
}
.user_card div div.progress_wrap {
background-color: white;
width: 100%;
border: 1px solid #bbb;
}
.user_card div div.progress {
height: 30px;
background-color: #ddd;
}
Fiddle.
Please post fiddle as well with your answers!
Using display table, table-row, table-cell.
http://jsfiddle.net/vnama/
.user_card {
background-color: #eee;
width: 30%;
padding: 10px;
display:table;
}
.user_card p {
display: table-cell;
vertical-align:top;
line-height:30px;
padding:2px 10px 2px 2px;
}
.user_card div {
display:table-row;
padding:2px;
}
.user_card div div {
display:table-cell;
}
.user_card div div.progress_wrap {
background-color: white;
width: 100%;
border: 1px solid #bbb;
}
.user_card div div.progress {
height: 30px;
background-color: #ddd;
}
You can try using tables: http://jsbin.com/efugop
I have it:
HTML:
<div class="user_card">
<div class="skills">
<table><tr><td>
<p>Skills</p></td><td>
<div class="progress_wrap" style="margin-left:70px;">
<div class="progress" style="width:95%"></div>
</div></td></tr></table></div>
<div class="commitment">
<table><tr><td>
<p style="position:relative;margin-top:6px;">Commitment</p>
<div class="progress_wrap" style="position:relative;left:35px;margin-left:70px;">
<div class="progress" style="width:35%;"></div>
</div></td></tr></table>
</div>
<div class="reputation">
<table><tr><td>
<p style="position:relative;margin-top:6px;">Reputation</p>
<div class="progress_wrap" style="position:relative;left:35px;margin-left:70px;">
<div class="progress" style="width:65%;"></div>
</div>
</td></tr></table>
</div>
</div>
CSS:
.user_card {
background-color: #eee;
width: 50%;
padding: 20px 80px 20px 20px;
}
.user_card div p {
display: inline;
float: left;
}
.user_card div.skills {
margin-left: -1px;
}
.user_card div div.progress_wrap {
background-color: white;
width: 100px;
border: 1px solid #bbb;
}
.user_card div div.progress {
height: 30px;
background-color: #ddd;
}
You can use css to float left
. progress_wrap {
float: right;
}
HTML
<div class="user_card">
<div class="skills">
<p>Skills</p>
<div class="progress_wrap" style="margin-left:80px;">
<div class="progress" style="width:95%"></div>
</div>
</div>
<div class="commitment">
<p style="margin-left:-35px;">Commitment</p>
<div class="progress_wrap" style="margin-left:80px;">
<div class="progress" style="width:35%;"></div>
</div>
</div>
<div class="reputation">
<p style="margin-left:-73px;">Reputation</p>
<div class="progress_wrap" style="margin-left:80px;">
<div class="progress" style="width:65%;"></div>
</div>
</div>
In CSS
.user_card {
background-color: #eee;
width: 50%;
padding: 20px 100px 20px 20px;
}
.user_card div p {
display: inline;
float: left;
}
.user_card div.skills {
margin-left: -1px;
}
.user_card div div.progress_wrap {
background-color: white;
width: 100%;
border: 1px solid #bbb;
}
.user_card div div.progress {
height: 30px;
background-color: #ddd;
}