How to break span elements using css? - html

I am having a container div with selected items and select input inside it.
#container {
position: relative;
text-align: left;
width: 100%;
}
._2iA8p44d0WZ {
border: 1px solid #cccccc;
border-radius: 4px;
padding: 5px;
min-height: 22px;
position: relative;
}
._7ahQImy {
padding: 4px 10px;
background: #0096fb;
margin-right: 5px;
margin-bottom: 5px;
border-radius: 10px;
display: inline-flex;
align-items: center;
font-size: 13px;
color: #fff;
white-space: nowrap;
}
<div id="container">
<div class="_2iA8p44d0WZ">
<span class="chip _7ahQImy">This is the main label</span>
<span class="chip _7ahQImy false false">secondary label</span>
<input type="text" class="searchBox" id="search_input" placeholder="Select" autocomplete="off" value="">
</div>
</div>
Requirement:
-> I am in the need to move the selected items below the #container div to display individual chips (span tags) below one after the other.
Note:
-> There are some dynamic classes inside it for which I cannot modify the css classes for those dynamic classes.
List of dynamic classes for which css properties cannot be modified, _2iA8p44d0WZ and _7ahQImy .
List of ids/classes, I can modify the css properties are #container and .chip (span).
Things I have tried:
Added css property for span element with class chip as follows,
.chip {
position: absolute;
top: 200%;
}
.chip:after {
content: '\A';
white-space: pre;
}
But this results in the overlapping of items one on another.
If I add display: block; to .chip then that also results the same..
#container {
position: relative;
text-align: left;
width: 100%;
}
._2iA8p44d0WZ {
border: 1px solid #cccccc;
border-radius: 4px;
padding: 5px;
min-height: 22px;
position: relative;
}
._7ahQImy {
padding: 4px 10px;
background: #0096fb;
margin-right: 5px;
margin-bottom: 5px;
border-radius: 10px;
display: inline-flex;
align-items: center;
font-size: 13px;
color: #fff;
white-space: nowrap;
}
.chip {
position: absolute;
top: 200%;
}
.chip:after {
content: '\A';
white-space: pre;
}
<div id="container">
<div class="_2iA8p44d0WZ">
<span class="chip _7ahQImy">This is the main label</span>
<span class="chip _7ahQImy false false">secondary label</span>
<input type="text" class="searchBox" id="search_input" placeholder="Select" autocomplete="off" value="">
</div>
</div>
Expected Result:
---------------------------
| Input |
---------------------------
| This is the main label |
| secondary label |
Kindly please help me to modify the css of span tags (.chip) without modifying the dynamic classes (I don't have control for it in real application) to have line breaks, so that it will be visible one after the other below the container.

The problem is that you are positioning the chips absolute, of course they will end up on top of each other, if you position them all with the same top value.
Doing this the other way around would IMHO make much more sense here - position the input field absolute at the top of the container, and leave those chips in normal flow instead. Add a padding-top for the inner container element, so that they don’t go beneath the input field, but under it.
#container {
position: relative;
text-align: left;
width:100%;
}
#container > div {
padding-top: 2em;
}
._2iA8p44d0WZ {
border: 1px solid #cccccc;
border-radius: 4px;
padding: 5px;
min-height: 22px;
position: relative;
}
._7ahQImy {
padding: 4px 10px;
background: #0096fb;
margin-right: 5px;
margin-bottom: 5px;
border-radius: 10px;
display: inline-flex;
align-items: center;
font-size: 13px;
color: #fff;
white-space: nowrap;
}
#search_input {
position: absolute;
top: 0;
left: 0;
}
<div id="container">
<div class="_2iA8p44d0WZ">
<span class="chip _7ahQImy">This is the main label</span>
<span class="chip _7ahQImy false false">secondary label</span>
<span class="chip _7ahQImy">Another label</span>
<span class="chip _7ahQImy false false">even more labels labels labels labels labels labels</span>
<input type="text" class="searchBox" id="search_input" placeholder="Select" autocomplete="off" value="">
</div>
</div>

You can use in html br tag, in Css you can try
.container{
width: 100px;/*insert the px you need, make som tests*/
}
.your-stuff{
display:flex;
flex-warp: warp;
}
<body>
<div class="container">
<div class="my-stuff">stuff</div>
</div>
</body>

Related

Position search bar at the right side of div and centered

I want to position a search bar inside a div so it looks something like this:
At the moment it doesn't even sit within the div.
HTML:
.sb-search {
float: right;
overflow: hidden;
}
.sb-search-input {
border: none;
outline: none;
background: #fff;
width: 100%;
height: 60px;
margin: 0;
z-index: 10;
padding: 20px 65px 20px 20px;
font-family: inherit;
font-size: 20px;
color: #2c3e50;
}
<div class="searchbar" style="position: relative;">
<h1>Welcome Solictior...</h1>
<div id="sb-search" class="sb-search">
<form>
<input class="sb-search-input" placeholder="Search..." type="text" value="" name="search" id="search" />
<input class="sb-search-submit" type="submit" value="" />
<span class="sb-icon-search"></span>
</form>
</div>
</div>
I think your problem here is the h1 as it's a block level element.
Add this to your h1 CSS and it should let the search bar go to the right of it.
h1 {
display: inline-block;
}
Keep the float: right; on your .sb-search element too.
It's very easy to do with Flexbox
.searchbar {
background-color: #8BCAC7;
display: flex;
justify-content: space-between;
align-items: center;
}
https://jsfiddle.net/cb3fu9wj/
justify-content specifies the alignment along the main axis. It defines how the free space is distributed between elements.
align-items specifies the alignment along the cross axis.
Here's the complete guide.
Here's a possible example of what you're looking for : See this fiddle
CSS :
.searchbar { background-color: teal; color: #fff; overflow: hidden; padding: 0 10px;}
.searchbar .sb-search { float: right; margin: 5px 0; }
.searchbar h1 { float: left; font-size: 14px; margin: 10px 0 5px; }

Add image inside search box?

How can I add an image inside this search box? I'd like the image to be positioned inside and to the left of the palceholder text...
Here is the fiddle
HTML:
<div class="searchbar">
<h1>Welcome...</h1>
<div id="sb-search" class="sb-search">
<div class="search-wrapper">
<input class="search-input" placeholder="Search..." type="text" value="" name="search" id="search"/>
<img class="search-pic"src="img/search-icon.png"/>
</div>
</div>
</div>
thanks
Add this to your CSS which will position the image inside the input field.
.search-wrapper {
position: relative;
}
.search-wrapper img {
position: absolute;
top: 0px;
left: 0px;
}
Then you just need to use padding and change the top and left values to move everything about so it fits nicely and nothing is overlapped.
You might also need to set a width and height to the image so it's not too big for the input field.
You can solve it like this:
#mixin searchbar-font {}
#mixin searchbar-styles {
border: none;
outline: none;
color: $header-bg-color;
padding: 20px 65px 20px 20px;
background: transparent;
flex:1;
}
#mixin search-bar-input {
border: none;
outline: none;
}
.search-input {
border: none;
outline: none;
color: $header-bg-color;
padding: 20px 65px 20px 20px;
background: transparent;
flex:1;
}
.search-wrapper {
position: relative;
background: white;
display: flex;
align-items: center;
.search-input {
#include searchbar-font;
#include searchbar-styles;
}
.search-submit {
#include search-bar-input;
}
}
<div class="searchbar">
<h1>Welcome...</h1>
<div id="sb-search" class="sb-search">
<div class="search-wrapper">
<img class="search-pic" src="img/search-icon.png" />
<input class="search-input" placeholder="Search..." type="text" value="" name="search" id="search" />
</div>
</div>
</div>
Attached Fiddle
Technically you need to set your parent tag's position to relative, then set the image inside's position to absolute. Then you can overlay the image on your Input field. Also, one more thing to remember is you might want to set you z-index. Just in case, your image does not get behind of your input field. Make sure you are giving enough space to for your image by setting the input's padding left to somewhere around your image's width.
.search-wrapper{
.search-input{
padding-left: {image.width}px;
}
img{
position:absolute; left:0; top:0;
}
}
This should do the work.
<div class="search-container">
<input type="text" placeholder="Search...">
<img src="search-icon.png" alt="search icon">
</div>a
.search-container {
display: flex;
align-items: center;
position: relative;
}
input[type="text"] {
border: 1px solid gray;
border-radius: 20px;
padding: 10px 40px 10px 20px;
font-size: 16px;
width: 500px;
}
img {
position: absolute;
right: 20px;
top: 50%;
transform: translateY(-50%);
height: 20px;
width: 20px;
}
<div class="search-container">
<input type="text" placeholder="Search...">
<img src="search-icon.png" alt="search icon">
</div>
.search-container {
display: flex;
align-items: center;
position: relative;
}
input[type="text"] {
border: 1px solid gray;
border-radius: 20px;
padding: 10px 40px 10px 20px;
font-size: 16px;
width: 500px;
}
img {
position: absolute;
right: 20px;
top: 50%;
transform: translateY(-50%);
height: 20px;
width: 20px;
}

css for 2 inc/dec buttons by an input that reposition properly when resizing screen

I want to display an input box in html and 2 small buttons to the right, one on top of each other. Something like this
https://jsfiddle.net/danaya/yw94f0Lt/3/
The html code is simple
<div class="list">
<div class="name">product</div>
<div class="input">
<input type="text" size="3" value="1">
<div class="inc">+</div>
<div class="dec">-</div>
</div>
<div class="price">2.99</div>
</div>
And this is the css
.list {
display: flex;
}
.name,
.input,
.price {
padding: 10px 10px;
border: 1px solid red;
}
.name {
width: 50%;
}
.input,
.price {
text-align: right;
width: 25%;
}
.input {
position: relative;
top: -5px;
}
input {
line-height: 25px;
}
.inc,
.dec {
display: block;
position: absolute;
width: 13px;
height: 13px;
background-color: #999;
text-align: center;
color: #fff;
line-height: 12px;
}
.inc {
top: 11px;
left: 40px;
}
.dec {
top: 25px;
left: 40px;
}
As it is right now, when I resize the window, the div.input is resized and so the buttons, being related to the input, lose their position by the input element.
I need to keep the flex display in the .list element, but other than that I can change anything. I also need the buttons to not increase the width of the div.input element, that's why I'm using the position:relative.
Any ideas?
Thanks
Would this work for you?
.list {
display: flex;
align-items: center;
}
.name,
.price {
padding: 0 10px;
}
.input, input {
box-sizing: border-box; /*to set the equal height to bot .input and input*/
height: 31px; /*13 + 13 (buttons) + 5 (paddings for buttons) = 31px */
}
.input {
position: relative;
/*width: 25%; Use this if you want to increate the width of your div.input*/
}
input {
padding-right: 15px; /* 15px set so that input characters do not go underneath the + and - buttons */
width: 100%; /* set 100% so that input will take 100% width of its parent size */
}
.inc,
.dec {
box-sizing: border-box;
display: block;
position: absolute;
width: 13px;
height: 13px;
background-color: #999;
text-align: center;
color: #fff;
line-height: 12px;
}
.inc {
top: 2px;
right: 2px;
}
.dec {
bottom: 2px;
right: 2px;
}
<div class="list">
<div class="name">product</div>
<div class="input">
<input type="text" size="3" value="1">
<span class="inc">+</span>
<span class="dec">-</span>
</div>
<div class="price">2.99</div>
</div>

How do I keep a button appended to an input even at a smaller page width?

I am trying to append a button to a text input.
It works when I am in desktop mode, but when you change the size to a mobile-viewing size the button separates from the input.
Here is my fiddle.
I am using purecss:
input {
font-size: 16px;
padding-right: 50px;
border-radius: 0px;
height: 30px;
}
.pure-button {
margin-left: -45px;
height: 30px;
width: 40px;
padding: 1px;
}
span {
cursor: pointer;
display: inline-block;
height: 11px;
width: 8px;
text-align: center;
white-space: nowrap;
align-self: flex-start;
background: red;
background-position: 0 0;
margin: 1px;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/pure/0.6.0/pure-min.css" rel="stylesheet"/>
<div class="pure-g">
<div class="pure-u-1">
<form class="pure-form">
<fieldset>
<input type="text" class="pure-input-1-2" />
<button type="submit" class="pure-button pure-button-primary">
<span></span>
</button>
</fieldset>
</form>
</div>
</div>
There is a media query that is applying tules to to the input and the button from 0px - 480px. If you remove or override these, your fields will behave the same way as > 480px screen widths.
The library you're using is adding display: block to the input in a media query. That's forcing the button to the next line.
Add this to your CSS:
input, button {
display: inline-block !important;
margin: 0 !important;
}
The !important is needed to override the PURECSS code. Otherwise, alter the code in the source.
I also removed all whitespace between the elements in the code:
<input type="text" class="pure-input-1-2" /><button type="submit" class="pure-button pure-button-primary"><span></span></button>
This is one method for removing spaces between inline-block elements.
revised fiddle
Please try the below code within your existing code, hope this will help you.
.pure-form fieldset{
position: relative;
width: 50%;
padding: 0 45px 0 0;
margin: 10px;
box-sizing: border-box;
}
input {
font-size: 16px;
border-radius: 0px;
height: 30px;
}
.pure-form .pure-input-1-2{
width: 100%;
}
.pure-button {
position: absolute;
right: 0;
top: 0;
height: 30px;
width: 40px;
padding: 1px;
margin: 0 !important;
}
span {
cursor: pointer;
display: inline-block;
height: 11px;
width: 8px;
text-align: center;
white-space: nowrap;
align-self: flex-start;
background: red;
background-position: 0 0;
margin: 1px;
}
<div class="pure-g">
<div class="pure-u-1">
<form class="pure-form">
<fieldset>
<input type="text" class="pure-input-1-2" />
<button type="submit" class="pure-button pure-button-primary">
<span></span>
</button>
</fieldset>
</form>
</div>
</div>

Add span to side of center align element

I'm trying to implement some designs in CSS, but having a bit of trouble figuring out how to align this <span> correctly.
I am trying to achieve the <input> and <button> elements being centrally aligned, but the <span> element being absolutely to the right of the <input>, example:
It's important to make sure that the <span> does not affect the alignment of the other elements. The <input> and <button> should always be exactly in the middle of the parent.
Would be great if I could do this in CSS only. This is what I have so far:
div {
position: relative;
text-align: center;
background: #B7B7B7;
width: 400px;
}
input {
padding: 5px;
margin: 10px 0;
text-align: center;
font-size: 1.2em;
width: auto;
}
.verify {
display: block;
width: 20px;
height: 20px;
background: red;
position: absolute;
top: 0; /* Not sure how to calculate these? */
right: 0; /* Input.X + Input.Width + 15px ?? */
}
<div>
<input placeholder="Enter code" maxlength="8" size="8"/><br />
<span class="verify"></span>
<button>Register</button>
</div>
Additional Info:
It only has to work in Chrome
I can make all elements a fixed width if required
I can make DOM changes if required
I would prefer not to hardcode X/Y co-ordinates for the <span>...I might want to change the input/button dimensions later
Wrap the input and the span inside a div with position: relative and display:inline
The span .verify will get absolutely positioned, leaving the input element to it's original position (centered aligned)
By giving a top:50% and then margin-top: -10px (half of its height), it will get in the middle of it's parent height.
.wrp {
position: relative;
text-align: center;
background: #B7B7B7;
width: 400px;
}
.inpWrp {
display: inline;
position:relative;
}
input {
padding: 5px;
margin: 10px 0;
text-align: center;
font-size: 1.2em;
width: auto;
}
.verify {
display: block;
width: 20px;
height: 20px;
background: red;
position: absolute;
margin-top: -10px;
top: 50%; /* Not sure how to calculate these? */
right: -20px; /* Input.X + Input.Width + 15px ?? */
}
<div class="wrp">
<div class="inpWrp">
<input placeholder="Enter code" maxlength="8" size="8"/>
<span class="verify"></span>
</div>
<br />
<button>Register</button>
</div>
You can wrap your input element in span and using pseudo-element :after to create the square. No need of position absolute:
div {
position: relative;
text-align: center;
background: #B7B7B7;
width: 400px;
}
input {
padding: 5px;
margin: 10px 0;
text-align: center;
font-size: 1.2em;
width: auto;
vertical-align: middle;
}
.verify:after {
content: "";
width: 20px;
height: 20px;
background: red;
display: inline-block;
vertical-align: middle;
}
<div>
<span class="verify">
<input placeholder="Enter code" maxlength="8" size="8"/>
</span>
<br />
<button>Register</button>
</div>
After #kapantzak comment you can use position absolute like:
div {
position: relative;
text-align: center;
background: #B7B7B7;
width: 400px;
}
input {
padding: 5px;
margin: 10px 0;
text-align: center;
font-size: 1.2em;
width: auto;
}
.verify:after {
content: "";
width: 20px;
height: 20px;
background: red;
display: inline-block;
position: absolute;
top: 17px;
}
<div>
<span class="verify">
<input placeholder="Enter code" maxlength="8" size="8"/>
</span>
<br />
<button>Register</button>
</div>
Try this...
.main_container {
position: relative;
text-align: center;
background: #B7B7B7;
width: 400px;
}
input {
padding: 5px;
margin: 10px 0;
text-align: center;
font-size: 1.2em;
width: auto;
}
.verify {
display: inline-block;
width: 20px;
height: 20px;
background: red;
position: relative;
top: 2px;
left: 10px;
}
<div class="main_container">
<div><input placeholder="Enter code" maxlength="8" size="8"/>
<span class="verify"></span></div>
<button>Register</button>
</div>