Prevent text from wrapping under the input field - html

I have card with Input and some text wrapped in span right to it. When text is long it wraps under the checkbox
Codepen: http://codepen.io/padmacnu/pen/bpKOVB
div {
font: 12px arial;
width: 250px;
height: 50px;
background: gray;
border: 1px solid #111111;
}
<div>
<input type="checkbox">
<span>text is too long and wraps under the checkbox</span>
</div>

You can do it like this: http://codepen.io/dirtysmith/pen/QNxzGM
div {
font: 12px arial;
width: 250px;
height: 50px;
background: gray;
border: 1px solid #111111;
}
input{
width:20px;
position:relative;
left: 0px;
vertical-align:middle;
}
span{
width:200px;
position:relative;
left: 0px;
display:inline-block;
vertical-align:middle;
}

You can float the input and make the span a block which establishes a block formatting context.
div {
font: 12px arial;
width: 250px;
height: 50px;
background: gray;
border: 1px solid #111111;
}
input {
float: left;
}
span {
display: block;
overflow: hidden; /* Establish BFC */
}
<div>
<input type="checkbox">
<span>text is too long and wraps under the checkbox text is too long and wraps under the checkbox</span>
</div>
Alternatively, you can use flexbox:
div {
font: 12px arial;
width: 250px;
height: 50px;
background: gray;
border: 1px solid #111111;
display: flex;
}
span {
flex: 1; /* Fill remaining space left by the input */
}
<div>
<input type="checkbox">
<span>text is too long and wraps under the checkbox text is too long and wraps under the checkbox</span>
</div>

float: left on the input worked
Flex also worked like charm
div {
font: 12px arial;
width: 250px;
height: 50px;
background: gray;
border: 1px solid #111111;
}
input {
float: left;
}
<div>
<input type="checkbox">
<span>text is too long and wraps under the checkbox</span>
</div>
http://codepen.io/padmacnu/pen/bpKOVB

Related

How to show the fieldset border through a section of the label?

I have a form with fieldsets, and would like to keep the border, but would like the border to be shown between some text legends. I can't get the legend to have a transparent background to let the border through (to be blocked by some text elements).
legend {
display:flex;
justify-content:space-between;
width: 100%;
background-color: transparent;
}
legend div {
background-color: white;
margin-left:0.5em;
margin-right:0.5em;
}
<form>
<fieldset>
<legend><div>Form Item</div><div>(extra 1)</div></legend>
<label>Input:</label><input></input>
</fieldset>
</form>
Extra div hack. If there is a way to do this without the extra div, that would be great.
I guess if I force the fieldset border (chrome's default border is 2px groove threedface), it works ok.
fieldset {
border: 1px solid black;
}
legend {
display:flex;
justify-content:space-between;
width: 100%;
position: relative;
}
legend div {
background-color: white;
margin-left:0.5em;
margin-right:0.5em;
}
legend div.line {
flex: 1 1 auto;
background-color: transparent;
}
legend div.line:before {
position: absolute;
z-index: -1;
content: '';
left: 0px;
right: 0px;
top: 50%;
border-top: 1px solid black;
}
<form>
<fieldset>
<legend><div>Form Item</div><div class="line"></div><div>(extra 1)</div></legend>
<label>Input:</label><input></input>
</fieldset>
</form>
background can approximate this without an extra div. You simply need to find the correct color:
fieldset {
border: 1px solid black;
}
legend {
display: flex;
justify-content: space-between;
width: 100%;
background: linear-gradient(black 0 0)center/100% 1px no-repeat;
}
legend div {
background-color: white;
padding:0 0.5em;
}
<form>
<fieldset>
<legend>
<div>Form Item</div>
<div>(extra 1)</div>
</legend>
<label>Input:</label><input>
</fieldset>
</form>

Putting text on a border with css html

How can i hide border behind MON and give some space like in this pic
https://www.screencast.com/t/SJmg63NZuF
div {
height: 100px;
width: 100px;
border: 2px solid black;
}
h2 {
width: 50px;
margin-top: -15px;
margin-left: 0px;
padding: 0 10px;
}
<div>
<h2>MON</h2>
<p>7am - yeah</p>
</div>
I think you're trying to achieve this. The convention of using <legend> tags which is a child of <fieldset> is usually applied and used for forms but you can achieve the same as shown below. I tweaked the code a bit and added a background to show you how you may achieve what you're looking for as the screenshot you posted.
Hope, it helps.
body {
background-image: url("https://ak9.picdn.net/shutterstock/videos/21522739/thumb/1.jpg");
}
fieldset {
width: 100px;
border: 2px solid white;
text-align: center;
}
h2 {
color: white;
}
p {
color: white;
}
<fieldset>
<legend align="center">
<h2>MON</h2>
</legend>
<p>7am - yeah</p>
<p>8am - yeah</p>
<p>9am - yeah</p>
</fieldset>
Looks like you just need to set the background color from transparent.
div {
height: 100px;
width: 100px;
border: 2px solid black;
background: white;
}
h2 {
width: 50px;
margin-top: -15px;
margin-left: 8px;
padding: 0 14px 0 10px;
background: white;
}
<div>
<h2>MON</h2>
<p>7am - yeah</p>
</div>

CSS to avoid a container from resizing to fit bold text

Kind of a convoluted title, but easy enough to demonstrate
#txt {
padding: 5px;
}
#txt:hover {
font-weight: bold;
}
#test {
display: inline-block;
border: solid 1px black;
min-width: 100px;
}
<div id="test">
<div id="txt">This is some text</div>
</div>
So I have the above situation.
Is there anything I can do with CSS that will avoid the container (test) from resizing when I hover over the text? Like take up the padding or margin for the resize. Or set the width so that it is enough to handle the bolded text (but still be dynamic).
Here is an idea, use the before and after attributes to size the element based on the bold text width. Unfortunately, this requires a change to your markup.
#txt {
line-height: 1.4em;
padding: 5px;
text-align: center;
}
#txt::before {
content: attr(data-content);
display: block;
font-weight: bold;
height: 0px;
visibility: hidden;
}
#txt::after {
content: attr(data-content);
font-weight: normal;
}
#txt:hover::after {
font-weight: bold;
}
#test {
display: inline-block;
border: solid 1px black;
min-width: 100px;
}
<div id="test">
<div id="txt" data-content="This is some text"></div>
</div>
Alternately, use text-shadow to bold your text.
#txt {
padding: 5px;
}
#txt:hover {
text-shadow: 0.5px 0px 0px #555, -0.5px 0px 0px #555;
}
#test {
display: inline-block;
border: solid 1px black;
min-width: 100px;
}
<div id="test">
<div id="txt">This is some text</div>
</div>

In a table-cell, how to set the background color and put content in the middle?

The next image is currently what I have.
And this is what should be:
As you can see, the dots on the third column are not aligned. It should meet the next requirement:
As you can imagine, I might use two divs because of the two borders.
This next code is what I have tried all day long, I cannot achieve to position the dots in the middle with the background-color stretched (considering the two border colors). What am I wrong? Should I remove everything and change it by a flexbox? I'll appreciate your help.
Html code:
You have 4 items in your cart
<article class="cart-item">
<div class="left">
<img src="images/item1.jpg"></img>
</div>
<div class="center">
<h4 class="title">Dexter Men's Max Bowling Shoes (Right Handed Only)</h4>
<span class="description">Shipping 3-day with UPS</span>
<span class="description">Color: Gray</span>
<span class="description">Size: 28.5</span>
<span class="price">$60.00</span>
</div>
<div class="right">
<div class="grouped-dots">
<span></span>
<span></span>
<span></span>
</div>
</div>
</article>
Css code
.cart-item
{
border-bottom: 1px solid #CCCCCC;
border-top: 1px solid #CCCCCC;
display: table;
height: 100%;
overflow: hidden;
}
.cart-item>div
{
display: table-cell;
}
.left,.center
{
padding-bottom: 10px;
padding-top: 10px;
}
.left
{
padding-left: 15px;
padding-right: 15px;
width: 33.33%;
}
.left img
{
max-width: 100%;
}
.center
{
padding-right: 15px;
text-align: left;
vertical-align: top;
width: auto;
}
.right
{
border-left: 1px solid #CCCCCC;
border-right: 1px solid #CCCCCC;
vertical-align: middle;
width: 15px;
}
.right .grouped-dots
{
background-color: #F5F5F5;
border-left: 1px solid #FFFFFF;
border-right: 1px solid #FFFFFF;
display: block;
height: 100%;
}
.cart-item .grouped-dots span::after
{
color: #CCCCCC;
content: '.';
font-family: 'Open Sans',sans-serif;
font-size: 40px;
line-height: 0;
}
This approach is using table and table-cells as display values. If you think I'm in the wrong path, please let me know.
It's because of this style:
.right .grouped-dots {
height: 100%;
}
Since its as tall as its parent, there's no room for it to move vertically to the "middle."
Remove that style, and move its background color to .right:
.right {
background-color: #F5F5F5;
}
Fiddle

Hover edit icon on span (when its content is longer than span)

I try to view show modal window. This window contain multiple span. But there are limited by width and height. And when span content is smaller, than span width: all is OK, I can see this icon.
But when text is to big I could not see this icon. And I didn't have any ideas, how to do this on pure CSS without using Javascript (jQuery).
HTML:
<div class="wrapper">
<span class="first">First</span>
<br/>
<span class="second">Second contain a lot of text. Really long span is here</span>
</div>
CSS:
.wrapper{
width: 300px;
height: 500px;
background: green;
overflow: hidden;
}
span{
display: inline-block;
width: 236px;
height: 30px;
line-height: 30px;
font-size: 16px;
padding: 0px;
margin: 10px 20px;
padding: 0 16px 0 8px;
white-space: nowrap;
overflow: hidden;
background: #fc0;
text-overflow: ellipsis;
border: 1px solid green;
border-radius: 4px;
}
span:hover{
border: 1px solid blue;
cursor: pointer;
}
span:hover::after{
font: normal normal normal 12px FontAwesome;
line-height: 30px;
content: "\f040";
float: right;
}
First screen, first span: it's OK
Second screen, second span: it's not normal
Third screen, second span: so must be
Have any ideas? Also padding, margin must be "user-friendly" and the same in both cases.
Try it here:
http://codepen.io/anon/pen/KpMdvx
.wrapper {
width: 300px;
height: 500px;
background: green;
overflow: hidden;
}
span {
display: inline-block;
width: 236px;
height: 30px;
line-height: 30px;
font-size: 16px;
padding: 0px;
margin: 10px 20px;
padding: 0 16px 0 8px;
white-space: nowrap;
overflow: hidden;
background: #fc0;
text-overflow: ellipsis;
border: 1px solid green;
border-radius: 4px;
}
span:hover {
border: 1px solid blue;
cursor: pointer;
}
span:hover::before {
font: normal normal normal 12px FontAwesome;
line-height: 30px;
content: "\f040";
float: right;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet" />
<div class="wrapper">
<span class="first">First</span>
<br/>
<span class="second">Second contain a lot of text. Really long span is here</span>
</div>
Because your text has a whitespace: nowrap; setting and is reaching the end of the box, this won't work without using position: absolute; on the icon. Just give the span position: relative; and apply an extra right-padding on hover.