CSS texts from different divs to flow - css

Let's say I have the following divs: JSFIDDLE
<div>
<div class="first">Hello My name is </div>
<div class="second">Something else</div>
</div>
Under a max-width, the first part and second part breaks away to next line. Is there a way to keep the words next to each other?

See the Solution Below
just add display:table; to .genral and display:table-cell; and white-space:nowrap; to .first, .second
.general {
background: #ebeff1;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
margin-bottom: 16px;
max-width: 205px;
display: table; /*Changed*/
}
.first {
margin-right: 7px;
}
/*New Added*/
.first, .second{
display: table-cell;
white-space: nowrap;
}
p.pp {
font-size: 24px;
}
<p class="pp">
When overflow, the words go to next line: Not good.
</p>
<div class="first_sample general">
<div class="first">Hello My name is </div>
<div class="second">something else</div>
</div>
<p class="pp">
If there is a space, then words simply flow to next each other: Good.
</p>
<div class="second_sample general">
<div class="first">Hello My name is </div>
<div class="second">something</div>
</div>
<p class="pp">
The look I am trying to achieve:
</p>
<div class="third_sample general">
<div class="first">Hello My name is something else </div>
</div>

Just use display: inline or inline-block in your first and second divs.
.general {
max-width: 200px;
}
.first,
.second {
display: inline;
}
<div class="first_sample general">
<div class="first">Hello My name is </div>
<div class="second">something else</div>
</div>

You can use white-space:nowrap; property.
.general {
background: #ebeff1;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
margin-bottom: 16px;
max-width: 205px;
display: flex;
}
.first {
margin-right: 7px;
white-space:nowrap;
}
.second {
white-space:nowrap;
}
p.pp {
font-size: 24px;
}
<p class="pp">
When overflow, the words go to next line: Not good.
</p>
<div class="first_sample general">
<div class="first">Hello My name is </div>
<div class="second">something else</div>
</div>
<p class="pp">
If there is a space, then words simply flow to next each other: Good.
</p>
<div class="second_sample general">
<div class="first">Hello My name is </div>
<div class="second">something</div>
</div>
<p class="pp">
The look I am trying to achieve:
</p>
<div class="third_sample general">
<div class="first">Hello My name is something else </div>
</div>

.general {
background: #ebeff1;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
margin-bottom: 16px;
max-width: 405px;
display: inline-block;
}

Related

Overlap outlines in css

I have an HTML structure with many divs next to each other or below each other that all have an outline. The problem is, these outlines do not overlap, but are shown next to each other (or on top of each other). To illustrate, this is what happens:
This is my code, with added nth-child() selectors to clearly show the issue:
.wrapper {
/* getting rid of the 'inline-block whitespace' */
font-size: 0;
white-space: nowrap;
}
.cell {
display: inline-block;
font-size: 2rem;
padding: 2px;
width: 100px;
}
.cell:nth-child(even) {
outline: 6px solid blue;
}
.cell:nth-child(odd) {
outline: 6px solid red;
}
<div class="wrapper">
<div>
<div class="cell">
one
</div>
<div class="cell">
two
</div>
</div>
<div>
<div class="cell">
three
</div>
<div class="cell">
four
</div>
</div>
</div>
My question is: How to make these outlines overlap so no 'doubles' are shown?
Update: using half the margin of the width of the outline on the cells does not always work when the outline width is 1px. For example, when the padding of .cell is 4px this is the result (when you zoom in you will see the two lines).
Update2: it seems this is a bug with Firefox on a 4k display. Running this in Firefox on a display with a HD resolution or in another browser (tested Chrome) works.
apply a margin equal to half the outline:
.wrapper {
/* getting rid of the 'inline-block whitespace' */
font-size: 0;
white-space: nowrap;
}
.cell {
display: inline-block;
font-size: 2rem;
padding: 2px;
width: 100px;
margin: 3px; /* added */
}
.cell:nth-child(even) {
outline: 6px solid blue;
}
.cell:nth-child(odd) {
outline: 6px solid red;
}
<div class="wrapper">
<div>
<div class="cell">
one
</div>
<div class="cell">
two
</div>
</div>
<div>
<div class="cell">
three
</div>
<div class="cell">
four
</div>
</div>
</div>
Or use margin on one side:
.wrapper {
/* getting rid of the 'inline-block whitespace' */
font-size: 0;
white-space: nowrap;
}
.cell {
display: inline-block;
font-size: 2rem;
padding: 2px;
width: 100px;
margin:0 6px 6px 0; /* added */
}
.cell:nth-child(even) {
outline: 6px solid blue;
}
.cell:nth-child(odd) {
outline: 6px solid red;
}
<div class="wrapper">
<div>
<div class="cell">
one
</div>
<div class="cell">
two
</div>
</div>
<div>
<div class="cell">
three
</div>
<div class="cell">
four
</div>
</div>
</div>

Set space between columns, so each column is same size (using foundation)

I'm trying to make some space between my columns, but can't seem to find the right solution.
Code:
<div class="content wrapper">
<div class="row">
<div class="red window border-right column small-12 medium-3">
Section 1
</div>
<div class="green window border-left border-right column small-12 medium-3">
Section 2
</div>
<div class="blue window border border-left border-right column small-12 medium-3">
Section 3
</div>
<div class="yellow window border-left column small-12 medium-3">
Section 4
</div>
</div>
</div>
Have tried setting classes as border-right, border-left on the columns, but then, the left and right column will be bigger in size than the two in the middle (I'm using middle-3, so have 4 columns).
Image:
Css:
.window {
background-color: white;
height: 450px;
}
.window.border-left {
border-left: 8px solid #EAEDEE;
}
.window.border-right {
border-right: 8px solid #EAEDEE;
}
.yellow {
background-color: yellow;
padding: 1rem;
}
.red {
background-color: red;
padding: 1rem;
}
.blue {
background-color: cadetblue;
padding: 1rem;
}
.green {
background-color: green;
padding: 1rem;
}
Is this possible, without applying it global?
please you can try this, i hope you need this.
CSS:
.content.wrapper {
float: left;
width: 100%;
}
.row {
float: left;
margin: 0;
width: 100%;
}
.window {
background-color: white;
height: 450px;
}
.window.border-left {
border-left: 8px solid #EAEDEE;
}
.window.border-right {
border-right: 8px solid #EAEDEE;
}
.yellow {
background-color: yellow;
padding: 1rem;
}
.red {
background-color: red;
padding: 1rem;
}
.blue {
background-color: cadetblue;
padding: 1rem;
}
.green {
background-color: green;
padding: 1rem;
}
.border-right, .border-left {
float: left;
width: 25%;
}
See Bootply Updeted Demo
Could please try this code
<div class="content wrapper">
<div class="row" data-equalizer="">
<div class="column small-12 medium-3">
<div class="red window border-right" data-equalizer-watch="">Section 1</div>
</div>
<div class="border-right column small-12 medium-3">
<div class="green window border-left" data-equalizer-watch="">Section 2</div>
</div>
<div class="border-left border-right column small-12 medium-3">
<div class="blue window border" data-equalizer-watch="">Section 3</div>
</div>
<div class="column small-12 medium-3">
<div class="yellow window border-left" data-equalizer-watch="">Section 4</div>
</div>
</div>
</div>
I have modified only the HTML part. you can use the same css
.row {
.row {
display:flex;
justify-content:space-between;
}
`.row div {
flex:0 1 23%;
}`
be sure to use http://autoprefixer.github.io/
try this...
in a include your head part this link.
this link is zurb foundation css.
https://cdnjs.cloudflare.com/ajax/libs/foundation/6.2.3/foundation-flex.css

My inline-block divs are displayed in strange zig-zag pattern

I'm trying to visualise simple commands and their arguments in HTML. Desired output:
Actual output:
The code I used:
html {
background-color: #222;
}
div.script {
display: table-cell;
vertical-align: top;
}
div.script div.script-command {
display: inline-block;
max-width: 10em;
min-width:3em;
border: 1px solid #66E239;
background-color: rgba(102,226,57, 0.3);
border-radius: 0.5 em;
}
div.script-command p.name {
text-align: center;
font-size: 15pt;
}
div.script-command div.arguments {
padding: 0.5 em;
text-align: center;
}
div.script-command div.arguments .argument {
font-family: "Courier new", consolas;
color: black;
font-size:11pt;
background-color: #CCC;
border: 1px solid white;
padding: 3pt;
margin: 2pt;
display: inline-block;
}
<div class="script">
<div class="script-command">
<p class="name">s
</p>
<hr>
<div class="arguments">
<span class="argument">xxx
</span>
</div>
</div>
<div class="script-command">
<p class="name">aaa
</p>
<hr>
<div class="arguments">
</div>
</div>
<div class="script-command">
<p class="name">s
</p>
<hr>
<div class="arguments">
<span class="argument">gfdgf
</span>
<span class="argument">1000
</span>
<span class="argument">5
</span>
</div>
</div>
<div class="script-command">
<p class="name">dd\;
</p>
<hr>
<div class="arguments">
</div>
</div>
</div>
The wrong alignment happens when the .arguments div is empty. Why does it happen? How do I fix it?
Use vertical-align: top; on your inline-block elements.
You need to set the vertical-alignment of the inline-block element.
If you want to glance at the spec,
This shorthand property specifies how an inline-level box is aligned within the line. Values are the same as for its longhand properties, see below.
Since you have the baseline set as default/not specifically set, it will style to the lowest line, and hence by setting it to top will align the inline-block elements to the top line.
html {
background-color: #222;
}
div.script {
display: table-cell;
vertical-align: top;
}
div.script div.script-command {
display: inline-block;
max-width: 10em;
min-width:3em;
vertical-align: top;
border: 1px solid #66E239;
background-color: rgba(102,226,57, 0.3);
border-radius: 0.5 em;
}
div.script-command p.name {
text-align: center;
font-size: 15pt;
}
div.script-command div.arguments {
padding: 0.5 em;
text-align: center;
}
div.script-command div.arguments .argument {
font-family: "Courier new", consolas;
color: black;
font-size:11pt;
background-color: #CCC;
border: 1px solid white;
padding: 3pt;
margin: 2pt;
display: inline-block;
}
<div class="script">
<div class="script-command">
<p class="name">s
</p>
<hr>
<div class="arguments">
<span class="argument">xxx
</span>
</div>
</div>
<div class="script-command">
<p class="name">aaa
</p>
<hr>
<div class="arguments">
</div>
</div>
<div class="script-command">
<p class="name">s
</p>
<hr>
<div class="arguments">
<span class="argument">gfdgf
</span>
<span class="argument">1000
</span>
<span class="argument">5
</span>
</div>
</div>
<div class="script-command">
<p class="name">dd\;
</p>
<hr>
<div class="arguments">
</div>
</div>
</div>
checkout this fix
div.script div.script-command {
display: inline-block;
max-width: 10em;
min-width:3em;
vertical-align:top;
border: 1px solid #66E239;
background-color: rgba(102,226,57, 0.3);
border-radius: 0.5 em;
}
http://jsfiddle.net/jrpq1xe7/

Create 6 boxes with css

I really need some help with some easy css that I just can't get my head around.
I want to create boxes like in the link below.
I guess I could have the code for just one of them, and then use it over and over again, but how do I create the boxes so that they don't mind the other stuff around them?
Example here: http://s23.postimg.org/qypbfvv0r/boxes.jpg
Here: I have figured out a way of doing this. I hope that this helps you in some way in helping you figure out how to finish your task.
HTML:
<div class="containers">
<p class="heading">Heading</p>
<div class="inner1"></div>
<div class="inner2"></div>
</div>
<div class="containers">
<p class="heading">Heading</p>
<div class="inner1"></div>
<div class="inner2"></div>
</div>
<div class="containers">
<p class="heading">Heading</p>
<div class="inner1"></div>
<div class="inner2"></div>
</div>
CSS:
.containers {
width: 300px;
height: 150px;
border: 1px solid black;
margin-bottom: 10px;
overflow: hidden;
position: relative;
}
.inner1 {
margin-left: 5px;
width: 135px;
height: 80px;
border: 1px solid black;
background-color: blue;
}
.inner2 {
position: relative;
float: right;
top: -60%;
margin-left: 5px;
margin-right: 5px;
width: 135px;
height: 80px;
border: 1px solid black;
background-color: red;
}
.heading {
padding-left: 20px;
}
You can start off using this code. After this you can give border styles and colors to the individual divs.
<div>
<div style="float:right"> Content </div>
<div style="float:left"> Content </div>
</div>
<div style="padding-top:10px">
<div style="float:right"> Content </div>
<div style="float:left"> Content </div>
</div>
<div style="padding-top:10px">
<div style="float:right"> Content </div>
<div style="float:left"> Content </div>
</div>
Hope this helps

Horizontal centering of div within display:table row

I have a layout composed of divs displaying as table, 3 table rows, and up to 5 table cells per row. My problem is twlofold:
1) I can't figure out how to center the table cells within the rows if there are less than five cells in the table., and
2) I can't figure out how to keep the integrity of the shapes when there are less than 5 in a row.
The number of cells in a row will be variable (between 3 and 5), and I have to use divs -- I can't use real tables.
Here is a codepen: http://codepen.io/Jaemaz/full/aCboe
Here is the source:
HTML:
<div class="focus-container">
<div class="focus-row">
<div class="focus-element circle">
<span class="ng-scope">
Option A
</span>
</div>
<div class="focus-element circle">
<span class="ng-scope">
Option B
</span>
</div>
<div class="focus-element circle">
<span class="ng-scope">
Option C
</span>
</div>
<div class="focus-element circle">
<span class="ng-scope">
Option D
</span>
</div>
<div class="focus-element circle">
<span class="ng-scope">
Option E
</span>
</div>
</div>
<div class="focus-row">
<div class="focus-element circle" ng-class="{unknown: unknown, square: square, circle: circle, selected: selected, shouldHaveBeenSelected: shouldHaveBeenSelected, shouldNotHaveBeenSelected: shouldNotHaveBeenSelected}" ng-click="click()" ng-transclude="" focuschoice="" identifier="F" enabled="true">
<span class="ng-scope">
Option F
</span>
</div>
</div>
</div>
CSS:
.focus-container {
width: 560px;
height: auto;
display: table;
background-color: #000;
border-spacing: 15px;
table-layout: fixed;
-moz-user-select: none;
-khtml-user-select: none;
-webkit-user-select: none;
user-select: none;
}
.focus-row {
width: 100%;
height: 100%;
display: table-row;
}
.focus-element {
width: 90px;
height: 90px;
display: table-cell;
color: #fff;
background: #808080;
border: 2px solid #BFBFBF;
vertical-align: middle;
text-align: center;
font-family: "Ubuntu", Arial, Helvetica, sans-serif;
font-size: 14px;
text-shadow: 0px 2px 1px rgba(0, 0, 0, 1);
max-width: 94px;
}
.focus-element.circle {
-moz-border-radius: 94px;
-webkit-border-radius: 94px;
border-radius: 94px;
}
Screen Shot:
Tables won't do that, but tables in table will. 1) Use single-cell rows in outer table and a new table within each cell, and center the inner table within the row. 2) You might use fixed (or some relative) width and height on each cell within inner tables.
ADDED:
This will work for display:table as well as old-school table.
Outermost table should only have one cell in each row, and in that cell place the inner table.
Building on #Jojje 's suggestion, the answer lies in creating an extra "inner" level (display:table) within the div structure. Solution is on CodePen here: http://codepen.io/Jaemaz/pen/spbKf
In case Codepen goes away, here is sample HTML and CSS:
HTML
<div class="focus-container">
<div class="focus-row">
<div class="inner">
<div class="focus-element circle">
<span>ahem</span>
</div>
</div>
</div>
<div class="focus-row">
<div class="inner">
<div class="focus-element circle">
<span>hello</span>
</div>
<div class="focus-element circle">
<span>there</span>
</div>
</div>
</div>
<div class="focus-row">
<div class="inner">
<div class="focus-element circle">
<span>what</span>
</div>
<div class="focus-element circle">
<span class="content">is</span>
</div>
<div class="focus-element circle">
<span>happening</span>
</div>
<div class="focus-element circle">
<span>happening</span>
</div>
<div class="focus-element circle">
<span>happening</span>
</div>
</div>
</div>
</div>
CSS
.focus-container {
width: 560px;
background-color: #000;
padding: 5px;
}
.focus-container .focus-row {
height: 110px;
background-color: #000
}
.focus-container .focus-row .inner {
display: table;
margin: 0 auto;
height: 110px;
}
.focus-container .focus-row .inner .focus-element {
float: left;
text-align: center;
margin: 0 auto;
width: 94px;
height: 94px;
background-color: #009900;
}
.focus-container .focus-row .inner .focus-element span {
margin-top: 40px;
display: block;
}
.focus-container .focus-row .inner .circle {
-moz-border-radius: 94px;
-webkit-border-radius: 94px;
border-radius: 94px;
margin: 8px;

Resources