This is the current output of my code,
Here I want to position the minus icon to top left like this (I edited the following image using paint) ,
I have included my code below.Here I tried to set the position of the minus span to absolute and It going to the corner of the top.And I don't want it to happen.Is there any way to do this?, I really appreciate your help.I'm trying to do for whole day.
<div class="left-bar-sm">
<div class="left-bar-sm-header">
Quantity (0)
</div>
<div class="left-bar-sm-body">
<div class="left-bar-sm-nested">
<span>Samaposha</span>
<br>
<span>2 x Rs 28.00 = Rs 56.00</span>
<span style="float: right;"><i class="fas fa-minus-circle"></i> <i class="fas fa-trash"></i></span>
</div>
</div>
.left-bar-sm-header {
background-color: #333333;
width: auto;
height: 50px;
margin-top: 5px;
border: 1px solid #595E57;
text-align: center;
padding: 5px;
font-size: 18px;
overflow-x: auto;
}
.left-bar-sm-body {
height: 450px;
border: none;
border-bottom: 2px dashed #595E57;
overflow-x: auto;
}
.left-bar-sm-nested {
margin-top: 5px;
background-color: #333333;
border: 1px solid #595E57;
padding: 20px;
}
In this Case you can use CSS flex. I have slightly changed your HTML.
Try this:
.left-bar-sm {
background: #252525;
padding: 10px;
color: #fff;
}
.left-bar-sm-header {
background-color: #333333;
width: auto;
height: 50px;
margin-top: 5px;
border: 1px solid #595E57;
text-align: center;
padding: 5px;
font-size: 18px;
overflow-x: auto;
}
.left-bar-sm-body {
height: 450px;
border: none;
border-bottom: 2px dashed #595E57;
overflow-x: auto;
}
.left-bar-sm-nested {
display: flex;
flex-direction: column;
margin-top: 5px;
background-color: #333333;
border: 1px solid #595E57;
padding: 20px;
}
.left-bar-sm-nested > div {
display: flex;
justify-content: space-between;
}
.left-bar-sm-nested > div span {
line-height: 25px;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css" rel="stylesheet"/>
<div class="left-bar-sm">
<div class="left-bar-sm-header">
Quantity (0)
</div>
<div class="left-bar-sm-body">
<div class="left-bar-sm-nested">
<div>
<span>Samaposha</span>
<span style="float: right;"><i class="fas fa-minus-circle"></i><span>
</div>
<div>
<span>2 x Rs 28.00 = Rs 56.00</span>
<span><i class="fas fa-trash"></i></span>
</div>
</div>
</div>
</div>
You can wrap the text and right side icons in two divs.
Then using flex modify the layout to show left and right side.
.left-bar-sm-header {
background-color: #333333;
width: auto;
height: 50px;
margin-top: 5px;
border: 1px solid #595E57;
text-align: center;
padding: 5px;
font-size: 18px;
overflow-x: auto;
}
.left-bar-sm-body {
height: 450px;
border: none;
border-bottom: 2px dashed #595E57;
overflow-x: auto;
}
.left-bar-sm-nested {
color: #fff;
margin-top: 5px;
background-color: #333333;
border: 1px solid #595E57;
display:flex;
}
.right {
margin-left: auto;
display: flex;
flex-direction: column;
justify-content: space-between;
padding: 10px;
}
.left {
padding: 20px;
flex: 1;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css" rel="stylesheet"/>
<div class="left-bar-sm">
<div class="left-bar-sm-header">
Quantity (0)
</div>
<div class="left-bar-sm-body">
<div class="left-bar-sm-nested">
<div class="left">
<span>Samaposha</span>
<br>
<span>2 x Rs 28.00 = Rs 56.00</span>
</div>
<div class="right"><i class="fas fa-minus-circle"></i> <i class="fas fa-trash"></i></div>
</div>
</div>
Related
I am trying to create a website where I have divs side by side in a list (separated by a vertical line). I am referencing this design
I am having trouble making the design responsive: I tried using % but when resizing the browser, the divs containing my text content move down and awkwardly collide/crash into each other (and don't stay separated by the vertical line). I am wondering if anyone knows how to keep the divs separated and responsive when resizing
#experience {
border: 1px solid red;
padding-top: 0px;
margin-top: 0px;
min-height: 1000px;
}
.center_text {
border: 1px solid black;
padding-top: 1%;
text-align: center;
color: #001418;
font-weight: 600;
font-family: 'Josefin Sans', sans-serif;
font-size: 2em;
}
.vline {
height: 740px;
width: 1px;
border: none;
border-right: solid 1px black;
z-index: 10;
}
.circle2 {
border: 50px solid black;
width: 1px;
border: none;
border-right: solid 1px black;
z-index: 10;
}
#exp1 {
border: 1px solid blue;
font-family: 'Josefin Sans', sans-serif;
color: #182153;
margin-top: -43%;
height: 150px;
}
.circle:before {
content: ' \25CF';
font-size: 20px;
margin-left: 49.69%;
}
.exp_text {
display: flex;
flex-grow: 1;
flex-wrap: wrap;
margin: 0 auto;
border: 1px solid red;
margin-top: -2%;
min-height: 110px;
}
.left_exp {
border: 1px solid green;
text-align: right;
margin-left: 25%;
}
.right_exp {
margin-top: -5.8%;
border: 1px solid green;
width: min-content;
margin-left: 60%;
}
.date {
font-size: 1.3em;
font-weight: 600;
}
.company {
font-size: 1.3em;
font-weight: 600;
}
.role {
font-size: 1em;
min-width: 250px;
}
.job_descr {
font-size: 1em;
min-width: 250px;
}
<div id="experience">
<h3 class="center_text"> Experience</h3>
<div>
<hr class="vline" />
<div id="exp1">
<span class="circle"></span>
<div class="exp_text">
<div class="left_exp">
<div class="date">
<p>2022 </p>
</div>
<div class="role">
<p>Software Engineering Intern</p>
</div>
</div>
<div class="right_exp">
<div class="company">
<p>Company Name</p>
</div>
<div class="job_descr">
<p>Description.................</p>
</div>
</div>
</div>
</div>
</div>
</div>
The solution was to use flexbox.
#experience_content {
margin: 0 auto;
min-height: 100vh;
width: min-content;
}
.row {
display: flex;
}
.column {
color: black;
flex:33.3%;
padding: 20px;
}
and
<div id="experience">
<div id="experience_content">
<div class="row">
<div class="column">
</div>
</div>
</div>
</div>
I am trying to make a key that has two colored boxes and the value that it corresponds to. I want to move the red box, the value "Red", the orange box, and the value "Orange" all onto the same line with "Key: ". This is currently what I have:
.row
{
width: 570px;
border: 1px solid lightgray;
border-style: solid;
margin: 0 auto;
border-radius: 3px;
padding-left: 90px;
padding-top: 20px;
padding-bottom: 20px;
text-indent: -46px;
line-height: 2;
}
.box {
height: 18px;
width: 18px;
margin-right: 5px;
}
.red {
background-color: #ab3025;
}
.orange {
background-color: #f5a000;
}
<div class="row">
<strong>Key: </strong>
<div class="box red"> </div>
<span> Red </span>
<div class="box orange"></div>
<span> Orange </span>
<br>
<em>Darker color corresponds to hotter temp</em>
</div>
Set the display property of your .box class to inline-block:
.row {
width: 570px;
border: 1px solid lightgray;
border-style: solid;
margin: 0 auto;
border-radius: 3px;
padding-left: 90px;
padding-top: 20px;
padding-bottom: 20px;
text-indent: -46px;
line-height: 2;
}
.box {
height: 18px;
width: 18px;
margin-right: 5px;
display: inline-block;
}
.red {
background-color: #ab3025;
}
.orange {
background-color: #f5a000;
}
<div class="row">
<strong>Key: </strong>
<div class="box red"> </div>
<span> Red </span>
<div class="box orange"></div>
<span> Orange </span>
<br>
<em>Darker color corresponds to hotter temp</em>
</div>
One Word: Flexbox
.row {
width: 570px;
border: 1px solid lightgray;
border-style: solid;
margin: 0 auto;
border-radius: 3px;
padding-left: 90px;
padding-top: 20px;
padding-bottom: 20px;
text-indent: -46px;
line-height: 2;
}
.box {
height: 18px;
width: 18px;
margin-right: 5px;
}
.red {
background-color: #ab3025;
}
.orange {
background-color: #f5a000;
}
.container {
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
}
.container-item {
margin-left: 10px;
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
}
.container-item > div {
margin-right: 50px;
}
<div class="row">
<div class="container">
<strong>Key: </strong>
<div class="container-item">
<div class="box red"> </div>
<span>Red</span>
</div>
<div class="container-item">
<div class="box orange"> </div>
<span>Orange</span>
</div>
</div>
<br>
<em>Darker color corresponds to hotter temp</em>
</div>
You can check below code
.row {
width: 570px;
border: 1px solid lightgray;
border-style: solid;
margin: 0 auto;
border-radius: 3px;
padding-left: 5rem;
padding-top: 1.5rem;
padding-bottom: 1.5rem;
line-height: 2;
}
.box-text,.box {
width: 20px;
height: 20px;
margin-right: 0.4rem;
}
.box {display: inline-block;}
.red {
background-color: #ab3025;
}
.orange {
background-color: #f5a000;
}
<div class="row">
<div class="col-12">
<strong>Key:</strong>
<div class="box red"></div>
<span class='box-text'>Red</span>
<div class="box orange"></div>
<span class='box-text'>Orange</span>
<br>
<em>Darker color corresponds to hotter temp</em>
</div>
</div>
.row{
display: flex;
justify-content: space-around;
}
just add these lines in your "row" class.
in addition, you must learn "flexbox" in css. It really helps a lot in designing frontend of a website.
This question already has answers here:
Align inline-block DIVs to top of container element
(5 answers)
Closed 2 years ago.
I wanted to have 3 divs side by side in a HTML document and I managed to achieve it where it looks something like this:
But whenever I tried adding objects such as text or any other objects, the div is always shifting down:
Could anyone help me out on this?
Edit
Thanks for the response but i forgot that i wanted a logo at the top left, then followed by the 3 divs below the logo, but adding "flex" property to the container leads to this:
* {
box-sizing: border-box;
padding: 0;
margin: 0;
}
body {
background-color: #fff;
}
.container {
width: 100%;
height: 100%;
display: flex;
border: 1px solid black;
}
.input {
width: 450px;
height: 680px;
border-radius: 5px;
border: 3px solid black;
margin-top: 5px;
margin-left: 5px;
display: inline-block;
}
.output {
width: 650px;
height: 680px;
border-radius: 5px;
border: 3px solid black;
margin-left: 20px;
display: inline-block;
}
.output_2 {
width: 300px;
height: 680px;
border-radius: 5px;
border: 3px solid black;
margin-left: 20px;
display: inline-block;
}
<!--
this is the outermost shell
-->
<div class="container">
<!-- to add a logo at the top left -->
<div class = "sun_lg">
<img src = "images/sun.png" height = "50">
</div>
<div class="input">
<p>Hi</p>
</div>
<div class="output">
</div>
<div class="output_2">
</div>
</div>
Just add display:flex to your container.
To learn more about flexbox read the documentation.
You can also use grid
* {
box-sizing: border-box;
padding: 0;
margin: 0;
}
body {
background-color: #fff;
}
.container {
width: 100%;
height: 100%;
border: 1px solid black;
display: flex;
flex-direction:column;
/* new */
}
.wrapper{
width: 100%;
height:auto;
display: flex;
}
.input {
width: 450px;
height: 680px;
border-radius: 5px;
border: 3px solid black;
margin-top: 5px;
margin-left: 5px;
}
.output {
width: 650px;
height: 680px;
border-radius: 5px;
border: 3px solid black;
margin-left: 20px;
display: inline-block;
}
.output_2 {
width: 300px;
height: 680px;
border-radius: 5px;
border: 3px solid black;
margin-left: 20px;
display: inline-block;
}
/* update for logo */
.sun_lg {
border: 1px solid #000;
flex: 1 1 100%;
}
<div class="container">
<!-- to add a logo at the top left -->
<div class="sun_lg">
<img src="https://via.placeholder.com/50x50" height="50">
</div>
<div class="wrapper">
<div class="input">
<p>Hi</p>
</div>
<div class="output">
</div>
<div class="output_2">
</div>
</div>
</div>
Define vertical-align to set the exact behavior of divs against texts baseline. I will use vertical-align:top in all child divs:
* {
box-sizing: border-box;
padding: 0;
margin: 0;
}
body {
background-color: #fff;
}
.container {
width: 100%;
height: 100%;
border: 1px solid black;
}
.input {
width: 450px;
height: 680px;
border-radius: 5px;
border: 3px solid black;
margin-top: 5px;
margin-left: 5px;
display: inline-block;
vertical-align:top;
}
.output {
width: 650px;
height: 680px;
border-radius: 5px;
border: 3px solid black;
margin-left: 20px;
display: inline-block;
vertical-align:top;
}
.output_2 {
width: 300px;
height: 680px;
border-radius: 5px;
border: 3px solid black;
margin-left: 20px;
display: inline-block;
vertical-align:top;
}
<!--
this is the outermost shell
-->
<div class="container">
<div class="input">
<p>Hi</p>
</div>
<div class="output">
</div>
<div class="output_2">
</div>
</div>
My css and html looks like below. mRow is the main div and within that is my mRowLeft and mRowRight.
However instead of left and right I see them appear top left and bottom right.
div.mRow {
padding: 2px 25px 2px 0;
margin-top: 4px;
margin-bottom: 3px;
float: left;
text-align:left;
width: 350px;
/*border:1px solid green;*/
}
.mRowLeft {
padding: 2px 25px 2px 0;
margin-top: 4px;
margin-bottom: 3px;
float: left;
text-align:left;
width: 48%;
/*border:1px solid green;*/
}
.mRowRight {
padding: 2px 25px 2px 0;
margin-top: 4px;
margin-bottom: 3px;
float: right;
text-align:left;
width: 48%;
/*border:1px solid green;*/
}
///....
<div class="mRow">
<div class="mRowLeft"></div> --label
<div class="mRowLeft"></div> --10rows
<div class="mRowRight"></div> --label
<div class="mRowRight"></div> --10rows
</div>
...//
You should be putting your label and content under the same left/right div.
<div class="mRow">
<div class="mRowLeft">
<div>--label</div>
<div>10rows</div>
</div>
<div class="mRowRight">
<div>label</div>
<div>10rows</div>
</div>
</div>
Then you can either use inline-blocks:
.mRow {
white-space: nowrap;
width: 350px;
}
.mRowLeft,
.mRowRight {
display: inline-block;
white-space: normal;
width: 50%;
}
or use flexbox:
.mRow {
display: flex;
flex-direction: row;
width: 350px;
}
.mRowLeft,
.mRowRight {
width: 50%;
}
.mRow
{
display:flex;
justify-content:space-around;
}
<div class="mRow">
<div class="mRowLeft">
dfsf
<div class="mRowLeft">sdfvs</div>
</div>
<div class="mRowRight">
sdfs
<div class="mRowRight">sdfsd</div>
</div>
</div>
I have a header with links for navigation. Each link is a div, and inside it there is an a link. I want to make each a link fill the vertical and horizontal space of the div.
.TopNav {
position: relative;
border-bottom: 1px solid black;
}
.TopNav-wrapper {
position: relative;
max-width: 1000px;
margin: 0 auto;
background-color: gold;
}
.TopNav-item {
display: inline-block;
width: 100px;
text-align: center;
vertical-align: middle;
display: table-cell;
margin-right: 20px;
border: 1px solid tomato;
height: 72px;
}
.TopNav-a {
background-color: tomato;
color: white;
}
<nav class="TopNav">
<div class="TopNav-wrapper">
<div class="TopNav-item">
<a class="TopNav-a" href="">First</a>
</div>
<div class="TopNav-item">
<a class="TopNav-a " href="">Second</a>
</div>
<div class="TopNav-item">
<a class="TopNav-a" href="">Third</a>
</div>
</div>
</nav>
And a fiddle: https://jsfiddle.net/6rp1canq/
Is this possible?
Change .TopNav-a style in this way:
.TopNav-a {
display: block;
background-color: tomato;
color: white;
height: 72px;
line-height: 72px;
}
You could use flexbox layout:
.TopNav {
position: relative;
border-bottom: 1px solid black;
}
.TopNav-wrapper {
position: relative;
max-width: 1000px;
margin: 0 auto;
background-color: gold;
}
.TopNav-item {
display: inline-block;
width: 100px;
text-align: center;
vertical-align: middle;
display: table-cell;
margin-right: 20px;
border: 1px solid tomato;
height: 72px;
}
.TopNav-a {
background-color: tomato;
color: white;
display: flex;
justify-content: center;
align-items: center;
height: 100%;
}
<nav class="TopNav">
<div class="TopNav-wrapper">
<div class="TopNav-item">
<a class="TopNav-a" href="">First</a>
</div>
<div class="TopNav-item">
<a class="TopNav-a " href="">Second</a>
</div>
<div class="TopNav-item">
<a class="TopNav-a" href="">Third</a>
</div>
</div>
</nav>
You could just wrap the div in an anchor.
Write the a tag around the div doing <a><div>Test</div></a>