How to align a Div to float right and middle? - html

I am building a custom chips control and facing a problem in aligning a close div to the right and middle. Can someone help please. I want to align the close button vertically middle if the text wraps to multiple lines
<div class="chips-container">
<div *ngFor="let item of items; let i = index" class="chips">
<div class="chip-text">{{ item }}</div>
<div class="chip-close">x</div>
</div>
<input
class="input-chips"
(keyup.enter)="add($event)"
(keyup)="autogrow($event)"
style="width: 15px"
/>
</div>
My Style
.chips-container {
border: 1px solid gray;
height: auto;
min-height: 30px;
width: 230px;
position: relative;
}
.chips {
background-color: rgb(236, 236, 236);
border: 1px solid rgb(124, 124, 124);
border-radius: 14px;
margin: 3px;
padding-left: 3px;
height: auto;
display: inline-block;
}
.chip-text {
display: inline-block;
vertical-align: middle;
word-wrap: break-word;
}
.chip-close {
background-color: rgb(204, 204, 204);
height: 20px;
width: 20px;
border-radius: 50%;
//display: inline-block;
text-align: center;
margin-left: 2px;
float: right;
}
I replaced my Divs with table layout and it looks good, however, my input text control aligns in the bottom
<div class="chips-container">
<table
*ngFor="let item of pgFilters[i].value; let i = index"
class="chips"
>
<tr>
<td class="chip-text">{{ item }}</td>
<td><div class="chip-close">x</div></td>
</tr>
</table>
<input
style="width: 15px"
/>
</div>

Use positioning, put relative position on the parent element, in your case: .chips, and then relative position on the .chip-close, and then position it as you wish. Btw also added padding-right on the text itself, just so the word wouldn't overlap with the x icon.
.chips-container {
border: 1px solid gray;
height: auto;
min-height: 30px;
width: 230px;
position: relative;
}
.chips {
background-color: rgb(236, 236, 236);
border: 1px solid rgb(124, 124, 124);
border-radius: 14px;
margin: 3px;
padding-left: 3px;
height: auto;
position: relative;
}
.chip-text {
display: inline-block;
word-wrap: break-word;
padding-right: 20px;
}
.chip-close {
background-color: rgb(204, 204, 204);
height: 20px;
width: 20px;
border-radius: 50%;
text-align: center;
position: absolute;
top: 50%;
right: 2px;
transform: translateY(-50%);
}
<div class="chips-container">
<div *ngFor="let item of items; let i = index" class="chips">
<div class="chip-text">this is just a test tjak jldskfds lsdjkf kjdf eljf lsadjfoi lajkdfoasdfkj </div>
<div class="chip-close">x</div>
</div>
<input
class="input-chips"
(keyup.enter)="add($event)"
(keyup)="autogrow($event)"
style="width: 15px"
/>
</div>

Related

Added border in css go over the last div

The issue is that I have a div list of ott-col-right-inner but when I tried to add the table under id the border in that div goes through. here is it's css:
.point-count:before {
content: '';
position: absolute;
border-bottom: none;
left: 48px;
border-left: solid 4px #F3F3F3;
height: 100%;
top: 30px;
}
I only want the border to stop in the point-count div
Here is the JSfiddle link:
https://jsfiddle.net/q6pmaebj/
code in question:
<div class="ott-col-right-inner">
<div class="point-count"><h3>01</h3></div>
<div class="point-text"><p>Step 1</p></div>
</div>
<div class="ott-col-right-inner">
<div class="point-count"><h3>02</h3></div>
<div class="point-text"><p>Step 2</p></div>
</div>
<div class="ac">
<table style="width: 100%; border-collapse: collapse; table-layout: fixed; border: 1px solid #99acc2;">
<tbody>
<tr>
<td style="border: 0.5pt solid #000000; width: 100%; padding: 4px;">
<p>One</p>
</td>
</tr>
<tr>
<td style="border: 0.5pt solid #000000; width: 100%; padding: 4px;">
<p>Two</p>
</td>
</tr>
</tbody>
</table>
</div>
I tried to do something with nth-last child where I take the border out in the last bit, but this seems to be not working:
.point-count:last-child:before { border-left: none; }
Note: I cannot change the div tags because this is in a for each loop
After looking through the jsfiddle link it looks like the solution is that the ott-col-right div tag wasn't closed and by adding that we were able to take the styling and only apply it to what is enclosed in the tag. I'm learning myself so let me know if this works for you!
Screenshot from jsfiddle with the closing tag
add this css
.point-count:before {
content: '';
position: absolute;
border-bottom: none;
left: 35px; //change here
border-left: solid 4px #F3F3F3;
height: 100%;
top: -30px; //change here
}
.ott-col-right-inner{
position: relative;
}
.ott-col-right-inner:first-child .point-count:before{
top: 10px;
}
fiddle here
it's not border, it's the child's before and you set its height to 100%, so that's why. you need to manage its height properly. here I set it only 200px
.ott-col-right {
flex: 0 0 50%;
max-width: 50%;
position: relative;
overflow: hidden;
margin-bottom: 20px;
padding-right: 15px;
padding-left: 15px;
}
.point-count {
margin: 0px;
float: left;
width: 70px ;
height: 70px ;
display: flex;
align-items: center;
justify-content: center;
border-radius: 50%;
background: #F3F3F3;
}
.point-count h3 {
z-index: 1;
color: #3E3E3E;
font-size: 23px;
font-weight: 600;
}
.point-text {
text-align: left;
float: left;
width: calc(100% - 100px);
height: 70px;
display: flex;
align-items: center;
margin: 0px auto;
margin-left: 20px;
}
.ott-col-right-inner {
width: 100%;
display: block;
float: left;
padding: 10px 0px;
}
.point-text p {
font-family: "Exo 2", sans-serif;
color: #828389;
font-size: 16px;
margin: 0px 5px;
}
.point-text p a {
color: #CE1126;
font-size: 15px;
font-weight: 700;
position: relative;
}
.point-count:nth-child(1):before {
content: '';
position: absolute;
border-bottom: none;
left: 48px;
border-left: solid 4px #F3F3F3;
height: 200px;
top: 30px;
}
.ott-col-right-inner:last-child {
padding-bottom: 0px;
}
.vidyard-player-container
{
border-radius: 20px;
}
<div class="ott-col-right">
<div class="ott-col-right-inner">
<div class="point-count"><h3>01</h3></div>
<div class="point-text"><p>Step 1</p></div>
</div>
<div class="ott-col-right-inner">
<div class="point-count"><h3>02</h3></div>
<div class="point-text"><p>Step 2</p></div>
</div>
<div class="ott-col-right-inner">
<div class="point-count"><h3>03</h3></div>
<div class="point-text"><p>Step 3</p></div>
</div>
<div class="ac">
<table style="width: 100%; border-collapse: collapse; table-layout: fixed; border: 1px solid #99acc2;">
<tbody>
<tr>
<td style="border: 0.5pt solid #000000; width: 100%; padding: 4px;">
<p>One</p>
</td>
</tr>
<tr>
<td style="border: 0.5pt solid #000000; width: 100%; padding: 4px;">
<p>Two</p>
</td>
</tr>
</tbody>
</table>
</div>

Make image appear inline with a div within an outer div using css

I am trying to place an image to the right of a pseudo input box using css to imitate Apple's iMessage app. However, the image keeps displaying below the pseudo input box as follows:
Most answers suggest using display:inline-block and I have put this in the class for both the outter and inner div with no luck. (Have also tried float:left, float:right and display:inline-block on image and there is no difference.)
How can I get the arrow to appear to the right of the pseudo input box as the microphone image is below?
Here is my code for the input field:
.inputbox {
border-radius: 20px;
min-height: 30px;
width: 300px;
padding: 8px 15px;
margin-top: 5px;
margin-bottom: 5px;
border: solid 2px #EEE;
display: inline-block;
}
.inputBoxInner {
border-radius: 20px;
min-height: 30px;
width: 240px;
padding: 8px 15px;
margin-top: 5px;
margin-bottom: 5px;
border: solid 2px #EEE;
height:" auto";
display: inline-block;
}
.inputBoxInner:empty:not(:focus):before {
color: lightgrey;
font-family: helvetica;
content: attr(data-placeholder)
display: inline-block;
}
<div class = "inputBox" contentEditable="true"><div class="inputBoxInner" contenteditable="true" data-placeholder="Start typing"></div><input type="image" id="image" alt="Send"
src="/images/arrow.png" width="30" height="30 style="float:right"; "></div>
The code has a problem:
And this code can resolve the problem:
True code:
inputBox {display: grid; grid-template-columns: 100px 100px}
This should do it for you
.inputbox {
border-radius: 20px;
min-height: 30px;
width: 300px;
padding: 8px 15px;
margin-top: 5px;
margin-bottom: 5px;
border: solid 2px rgb(0, 0, 0);
}
.inputBoxInner {
border-radius: 20px;
min-height: 30px;
width: 240px;
padding: 8px 15px;
margin-top: 5px;
margin-bottom: 5px;
border: solid 2px rgb(131, 131, 131);
height: auto;
display: flex;
justify-content: end;
align-content: center;
}
.inputBoxInner:empty:not(:focus):before {
color: rgb(255, 0, 0);
font-family: helvetica;
}
<body>
<div class = "inputBox" contentEditable="true">
<div class="inputBoxInner" contenteditable="true" data-placeholder="Start typing">
<input type="image" id="image" alt="Send" src="image.png" width="30" height="30" style="float:right">
</div>
</div>
</body>

div buttons are overlapping HTML

I am trying to make an online portfolio for myself and I have a bottom container for the bottom half of the screen and I would like to place 3 buttons at the top of the container. I have got it to work except when you resize the page. When you shrink the page's width the buttons will overlap. How can I stop them from overlapping? I want them to go close together side by side but not overlap.
h1 {
margin-left: 33%;
margin-right: 33%;
text-align: center;
}
img {
width: 15%;
height: auto;
display: block;
margin-left: auto;
margin-right: auto;
}
#top,
#bottom {
position: fixed;
left: 0;
right: 0;
height: 50%;
}
#bottom {
border-top: 2px solid black;
margin-left: auto;
margin-right: auto;
display: block;
float: center;
position: fixed;
border: 2px solid black;
padding: 15px;
padding-bottom: 17px;
}
#navbuttons {
border-top: 2px solid black;
margin-left: auto;
margin-right: auto;
display: block;
float: center;
position: relative;
border: 2px solid black;
padding: 15px;
padding-bottom: 10px;
}
#resumebutton {
display: inline-block;
position: absolute;
top: 0%;
left: 33%;
-moz-border-radius: 20px;
-webkit-border-radius: 20px;
border: 2px solid black;
border-radius: 20px;
padding: 5px;
background-color: #7dd7f5;
text-align: center;
}
#coverletterbutton {
display: inline-block;
position: absolute;
top: 0%;
left: 46.5%;
-moz-border-radius: 20px;
-webkit-border-radius: 20px;
border: 2px solid black;
border-radius: 20px;
padding: 5px;
background-color: #7dd7f5;
text-align: center;
}
#portfoliobutton {
display: inline-block;
position: absolute;
top: 0%;
left: 62.5%;
-moz-border-radius: 20px;
-webkit-border-radius: 20px;
border: 2px solid black;
border-radius: 20px;
padding: 5px;
background-color: #7dd7f5;
text-align: center;
}
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<title>--Name Here-- Resume and Portfolio</title>
</head>
<body>
<div style="height: 100%"></div>
<div id="top"></div>
<h1>--Name Here--</h1>
<img src="http://science-all.com/images/wallpapers/cat-pictures/cat-pictures-20.jpg"/>
<h1>Resume and Portfolio</h1>
<div id="bottom">
<div id="navbuttons">
<div id="resumebutton">Resume</div>
<div id="coverletterbutton">Cover Letter</div>
<div id="portfoliobutton">Portfolio</div>
</div>
</div>
</body>
</html>
I would provide an example if I knew how.
Thank you
you don't need to absolute position the buttons if you have the container fixed. you can use inline-block and just text-align: center on your container. Also there are errors in your css, like there is no float: center;, you can also skip the # and use class as they share css properties. But I agree that Bootstrap is the way to go for responsive, and especially if you are new.
#bottom {
border-top: 2px solid black;
text-align: center;
margin-left: auto;
margin-right: auto;
display: block;
position: fixed;
border: 2px solid black;
padding: 15px;
padding-bottom: 17px;
}
.nav-button {
display: inline-block;
-moz-border-radius: 20px;
-webkit-border-radius: 20px;
border: 2px solid black;
border-radius: 20px;
padding: 5px;
background-color: #7dd7f5;
text-align: center;
}
<div id="bottom">
<div class="nav-button">Resume</div>
<div class="nav-button">Cover Letter</div>
<div class="nav-button">Portfolio</div>
</div>
The bootstrap grid system is great at this. I recommend using it in combination with some of your custom styles to produce a bottom section split into equally sized columns.
Grids are split into 12 columns, so columns of 4 (e.g. col-md-4) will split into evenly spaced vertically.
For the bottom, that would look something like:
<div id="bottom">
<div id="navbuttons" class="row">
<div id="resumebutton" class="col-md-4">Resume</div>
<div id="coverletterbutton" class="col-md-4">Cover Letter</div>
<div id="portfoliobutton" class="col-md-4">Portfolio</div>
</div>
</div>
You can make these columns wrapper divs if you want to center smaller buttons inside those columns, but the grid structure is a good place to start.
You can just delete attribute position: absolute; from all buttons ( resumebutton, coverletterbutton and portfoliobutton) and add text-align: center to navbuttons selector.
Consider removing the absolutepositioning to replace the elements in question back into the flow of the document. They'll have relation to each other now, so you won't need to rely on positioning rules like left and right.
The elements are already displayed inline-block so just declare a text-align: center rule to the parent and the nested elements will align accordingly.
In the snippet example below, margins have been added around each button for spacing, repetitive rules have been replaced with one instance using a class selector applied to all button elements, note that float: center; is not a valid rule.
Snippet Example
h1 {
margin-left: 33%;
margin-right: 33%;
text-align: center;
}
img {
width: 15%;
height: auto;
display: block;
margin-left: auto;
margin-right: auto;
}
#top,
#bottom {
position: fixed;
left: 0;
right: 0;
height: 50%;
}
#bottom {
border-top: 2px solid black;
margin-left: auto;
margin-right: auto;
display: block;
float: center;
position: fixed;
border: 2px solid black;
padding: 15px;
padding-bottom: 17px;
}
#navbuttons {
border-top: 2px solid black;
margin-left: auto;
margin-right: auto;
display: block;
float: center;
/* invalid rule */
position: relative;
border: 2px solid black;
padding: 15px;
padding-bottom: 10px;
text-align: center;
}
#navbuttons .button {
display: inline-block;
-moz-border-radius: 20px;
-webkit-border-radius: 20px;
border: 2px solid black;
border-radius: 20px;
padding: 5px;
background-color: #7dd7f5;
text-align: center;
margin: 0px 20px;
}
<div style="height: 100%"></div>
<div id="top"></div>
<h1>--Name Here--</h1>
<img src="http://science-all.com/images/wallpapers/cat-pictures/cat-pictures-20.jpg" />
<h1>Resume and Portfolio</h1>
<div id="bottom">
<div id="navbuttons">
<div id="resumebutton" class="button">Resume</div>
<div id="coverletterbutton" class="button">Cover Letter</div>
<div id="portfoliobutton" class="button">Portfolio</div>
</div>
</div>

Why inner div container overflows?

From below code,
.shoppingform {
width: 400px;
height: 800px;
background: #7CB9E8;
/* url(some img)*/
padding-left: 15px;
padding-top: 10px;
color: white;
font-size: 12px;
font-weight: bold;
border-radius: 5px;
}
.customercardtype {
border: 1px solid white;
color: black;
font-weight: normal;
padding: 10px 2px 5px 5px;
background: #B284BE;
width: 90%;
border-radius: 5px;
position: relative;
height: 8%;
margin-top: 5px;
}
.customercardtype .formlabel {
display: block;
height: 20%
}
.customercardtype .cardtypecontainer {
position: absolute;
width: 100%; /* Any problem here? */
top: 40%;
height: 50%;
border: 1px solid red;
}
<form class="shoppingform" action="someaction.php" method="get" enctype="multipart/form-data">
Step3: Card details
<div class="customercardtype">
<label class="formlabel">Cardtype:</label>
<div class="cardtypecontainer">
</div>
</div>
</form>
I would like to understand,
Why inner div container overflows?
This is because the width of an element is actually width + left padding + right padding + left border + right border.
As your width is 100% and additional to this will push it over 100%, making it overflow its parent.
If you use box-sizing: border-box, that will fix this issue.
That's a quick summary, lots more in depth info here: https://css-tricks.com/box-sizing.
The reason it overflows is because position absolute visually speaking, positions your element outside the normal flow of the site. This is intentional and powerful if you use it correctly. However in your case, the parent container of cardtypecontainer was not taking control of the absolute positioned element, therefore it overflowed outside its container.
Then, I changed cardtypecontainer to have relative position, which will work as you intended it to, because relative position does not change the intended layout of the element. For your case it means, cardtypecontainer will stay within the bounds of its parent container.
.shoppingform {
width: 400px;
height: 800px;
background: #7CB9E8;
/* url(some img)*/
padding-left: 15px;
padding-top: 10px;
color: white;
font-size: 12px;
font-weight: bold;
border-radius: 5px;
}
.customercardtype {
border: 1px solid white;
color: black;
font-weight: normal;
padding: 10px 2px 5px 5px;
background: #B284BE;
width: 90%;
border-radius: 5px;
position: relative;
height: 8%;
margin-top: 5px;
}
.customercardtype .formlabel {
display: block;
height: 20%
}
.customercardtype .cardtypecontainer {
position: relative;
margin-top: 10px;
width: 100%;
height: 50%;
border: 1px solid red;
}
<form class="shoppingform" action="someaction.php" method="get" enctype="multipart/form-data">
Step3: Card details
<div class="customercardtype">
<label class="formlabel">Cardtype:</label>
<div class="cardtypecontainer">
</div>
</div>
</form>

Keep div certain distance from another div

I have a login box DIV and below that another login button DIV which is 1% margin top from the Login Box DIV.
The login box div has these styles:
.login-box {
height: 39%;
width: 100%;
}
.login-box-wrap {
width: 30%;
height: 98%;
margin: 0 auto;
border: 1px solid #3f3f3f;
background-color: #609ac4;
border-radius: 5px 5px 5px 5px;
margin-top: 1%;
min-width: 250px;
max-width: 500px;
max-height: 350px;
min-height: 100px;
}
.logintextbox {
background-color: transparent;
border: none;
border-bottom-color: rgba(176, 221, 245, 1);
border-bottom-style: solid;
border-bottom-width: 2px;
width: 98%;
height: 32%;
font-size: 1.2em;
font-family: open sans;
color: white;
padding-left: 2%;
}
Then when i shrink it alittle more then button overlaps the box like this:
This is the login button styles:
.login-button {
height: 5%;
width: 100%;
margin-top: 1%;
position: fixed;
}
.login-button-wrap {
width: 30%;
height: 100%;
margin: 0 auto;
min-width: 250px;
max-width: 500px;
min-height: 20px;
max-height: 31px;
}
#btnLogin {
height: 100%;
width: 100%;
background: linear-gradient(#73afda,#609ac4);
border: 1px solid #3f3f3f;
border-radius: 5px 5px 5px 5px;
font-family: Arial;
color: white;
font-size: 15px;
}
How can i keep the button around 10px/1% margin top from the box at all resolutions
**EDIT: **
Here is the HTML
<div class="login-box">
<div class="login-box-wrap">
<input id="txt_client_reference" type="text" class="logintextbox" placeholder="Client Reference" />
<input id="txt_postcode" type="text" class="logintextbox" placeholder="Postcode" />
<input id="txt_date_of_birth" type="text" class="logintextbox" placeholder="Date of Birth" />
</div>
</div>
<div class="login-button">
<div class="login-button-wrap">
<asp:Button ID="btnLogin" runat="server" Text="Log in" CssClass="loginButton" OnClientClick="checkForm(); valid_postcode()" />
</div>
</div>
I might be a little far off on this one, but you have position fixed there, which doesn't really care about your margin anymore.