Aligning paragraphs and sub-paragraphs horizontally - css

Is there a way to present data as follows using css?
An article is divided into paragraphs, and each paragraph has a (usually smaller) box/sub-paragraph to the right of it, horizontally aligned with its respective paragraph.

Yes, it is possible. Here is an example of how you can achieve this http://jsfiddle.net/sptzH/1/
HTML:
<section class="content">
<article class="row">
<p>Paragraph A</p>
<div class="teaser">
Text related to A Text related to A Text related to A Text related to A Text related to A Text related to A
</div>
</article>
<article class="row">
<p>Paragraph B Paragraph B Paragraph B Paragraph B</p>
<div class="teaser">
Text related to B
</div>
</article>
</section>
CSS:
.content {
width: 500px;
}
.row {
clear: both;
padding: 10px;
border-top: solid 1px #000;
}
.row:after {
content: "";
display: table;
clear: both;
}
.row p {
width: 60%;
float: left;
box-sizing: border-box;
-moz-box-sizing: border-box;
padding: 0;
margin: 0;
font-size: 50px;
}
.row .teaser {
width: 40%;
float: left;
box-sizing: border-box;
-moz-box-sizing: border-box;
padding: 6px;
border: dotted 1px #999;
}

Using some CSS you could do something like the following. Example
CSS
.wrapper {
width: 500px;
overflow: hidden;
margin-top: auto;
margin-right: auto;
margin-bottom: 30px;
margin-left: auto;
}
.wrapper .paragraph {
width: 225px;
float: left;
height: 150px;
line-height: 150px;
border: medium solid #000;
text-align: center;
vertical-align: middle;
}
.wrapper .text {
float: right;
width: 225px;
height: 100px;
line-height: 100px;
border: medium solid #000;
text-align: center;
vertical-align: middle;
}
HTML
<div class="wrapper">
<div class="paragraph">Paragraph</div>
<div class="text">Related Text</div>
</div>
<div class="wrapper">
<div class="paragraph">Paragraph</div>
<div class="text">Related Text</div>
</div>

Related

Relative positioned div next to other div makes div offset from top [duplicate]

This question already has answers here:
Align inline-block DIVs to top of container element
(5 answers)
How to remove the space between inline/inline-block elements?
(41 answers)
Closed 8 months ago.
I have a panel with a bunch of items in list-like fashion. I want 3 different panels, but two on the left next to each other. I styled the panels the way I want, but when I copy-paste it to create another, it makes the div, but offsets it from the top.
Here's what I have right now:
html, body {
height: 100%;
width: 100%;
margin: 0px;
padding: 0px;
overflow: hidden;
color: #ededed;
font-family: Roboto;
}
.panel {
display: inline-block;
width: 15vw;
height: 100%;
border-right: 1px solid #272b3a;
background-color: #e0e0e0;
color: #000000;
margin: 0;
padding: 0;
padding-top: 20px;
padding-left: 15px;
position: relative;
margin-top: 0px;
}
.folder {
display: inline-flex;
align-items: center;
cursor: pointer;
margin: 0;
padding:0;
}
.folder-icon {
width: 30px;
}
.folder-name {
margin: 0;
margin-left: 6px;
top: 12px;
}
.add-folder {
cursor: pointer;
margin-left: -15px;
position: absolute;
bottom: 30px;
text-align: center;
width: calc(100% - 15px);
display:flex;
align-items: center;
justify-content: center;
}
.add-folder-text {
font-size: 15px;
margin: 0;
margin-bottom: 10px;
padding-left: 20%;
padding-right: 20%;
padding-top: 5%;
padding-bottom: 5%;
border-radius: 30px;
}
<div class="panel">
<div class="folder">
<p class="folder-name">Item 1</p>
</div>
<div class="folder">
<p class="folder-name">Item 2</p>
</div>
<div class="folder">
<p class="folder-name">Item 3</p>
</div>
<div class="folder">
<p class="folder-name">Item 4</p>
</div>
<div class="add-folder">
<p class="add-folder-text plus">Add folder</p>
</div>
</div>
<div class="panel">
<div class="folder">
<p class="folder-name">Social Networking</p>
</div>
<div class="add-folder">
<p class="add-folder-text plus">Add folder</p>
</div>
</div>
I added display: flex to the <body> CSS selector and is working.
because normally the body has a display: block by default. and flex put the element one near the other on the X-axis (and have other behaviors that solve this problem).
body {
display: flex; /*if you want you can use also "inline-flex" like you do for the other elements on your CSS file*/
}
html,
body {
height: 100%;
width: 100%;
margin: 0px;
padding: 0px;
overflow: hidden;
color: #ededed;
font-family: Roboto;
/* what I added */
display: flex;
}
.panel {
display: inline-block;
width: 15vw;
height: 100%;
border-right: 1px solid #272b3a;
background-color: #e0e0e0;
color: #000000;
margin: 0;
padding: 0;
padding-top: 20px;
padding-left: 15px;
position: relative;
margin-top: 0px;
}
.folder {
display: inline-flex;
align-items: center;
cursor: pointer;
margin: 0;
padding: 0;
}
.folder-icon {
width: 30px;
}
.folder-name {
margin: 0;
margin-left: 6px;
top: 12px;
}
.add-folder {
cursor: pointer;
margin-left: -15px;
position: absolute;
bottom: 30px;
text-align: center;
width: calc(100% - 15px);
display: flex;
align-items: center;
justify-content: center;
}
.add-folder-text {
font-size: 15px;
margin: 0;
margin-bottom: 10px;
padding-left: 20%;
padding-right: 20%;
padding-top: 5%;
padding-bottom: 5%;
border-radius: 30px;
}
<div class="panel">
<div class="folder">
<p class="folder-name">Item 1</p>
</div>
<div class="folder">
<p class="folder-name">Item 2</p>
</div>
<div class="folder">
<p class="folder-name">Item 3</p>
</div>
<div class="folder">
<p class="folder-name">Item 4</p>
</div>
<div class="add-folder">
<p class="add-folder-text plus">Add folder</p>
</div>
</div>
<div class="panel">
<div class="folder">
<p class="folder-name">Social Networking</p>
</div>
<div class="add-folder">
<p class="add-folder-text plus">Add folder</p>
</div>
</div>

Creating Nested Divs

I'm having trouble with creating a nested divs like in the attached image.
Image
I would love if some one can show me how.
.demo-container {
padding: 30px;
border: 1px solid #e2e4e7;
background-color: #f5f7f8;
text-align: left;
display: inline-block;
vertical-align: top;
}
.header {
display: block;
padding: 15px 25px 0;
overflow: hidden;
}
<div id="warp">
<div class="header">
New Alerts
</div>
<div class="demo-container">
</div>
</div>
You need to set height and width to your parent #wrap , see full snippet below:
snippet
* {
box-sizing: border-box
}
#wrap {
height: 200px;
width: 200px;
text-align: center;
}
.header {
display: block;
padding: 15px 25px;
background: blue;
color: white;
}
.demo-container {
width: 100%;
padding: 30px;
border: 1px solid #e2e4e7;
background-color: #f5f7f8;
display: inline-block;
vertical-align: middle;
color:black;
}
<div id="wrap">
<div class="header">
New Alerts
</div>
<div class="demo-container">
X Alerts
</div>
</div>

Height of left and right sides are uneven - CSS

With the following code, I'm trying to get the leftside and rightside to be the same height despite the fact that I have lots of info on the left and a little bit on the right. I want there to be vacant space under the text on the rightside. Have I coded wrong or am I missing something? Thanks.
#sides {
padding-bottom: 40px;
margin-bottom; 40px;
background-color: white;
}
#leftside {
width: 62%;
display: inline-table;
background-color: #000000;
float: left;
padding-right: 20px;
padding-left: 5%;
box-sizing: border-box;
}
#rightside {
width: 38%;
display: flex;
background-color: #808080;
float: left;
padding-left: 20px;
box-sizing: border-box;
flex-direction: column;
}
<div id="sides">
<div id="leftside">
<h1>TONS O' TEXT</h1>
</div>
<div id="rightside">
<h1>TINY AMOUNT OF TEXT</h1>
</div>
</div>
Remove display: inline-table; from #leftside

How to make contents fit to divs using css

How to make the inside divs fit to the contents in the below html
I tried with display:inline-block but it moves the 2nd div to the bottom.
<div class="ms-table">
<div class="tableCol-75">
</div>
<div class="tableCol-25">
</div>
</div>
There you go:
.ms-table {
width: 80%;
}
.tableCol-70 {
float: left;
width: 70%;
border: 1px solid black;
margin-right: 10px;
}
.tableCol-25 {
float: left;
width: 25%;
border: 1px solid blue;
}
<div class="ms-table">
<div class="tableCol-70">
My name is abc and I live in ams.
</div>
<div class="tableCol-25">
I love junk food even though it is unhealthy
</div>
</div>
use display: table
*{
padding: 0;
margin: 0;
box-sizing: border-box;
}
.ms-table{
display: table;
width: 100%;
height: 100px;
}
.table-cell{
display: table-cell;
vertical-align: top;
padding: 15px;
}
.tableCol-75{
width: 75%;
background: #ccc;
}
.tableCol-25{
width: 25%;
background: #000;
color: #fff;
}
<div class="ms-table">
<div class="table-cell tableCol-75">75%</div>
<div class="table-cell tableCol-25">25%</div>
</div>
use display: inline-block;
*{
padding: 0;
margin: 0;
box-sizing: border-box;
}
.ms-table{
width: 100%;
min-height: 100px;
}
.table-cell{
display: inline-block;
vertical-align: top;
padding: 15px;
}
.tableCol-75{
width: 75%;
background: #ccc;
}
.tableCol-25{
width: 25%;
background: #000;
color: #fff;
}
<div class="ms-table">
<div class="table-cell tableCol-75">75%</div><!--
--><div class="table-cell tableCol-25">25%</div>
</div>

Vertical and Horizontal center align within a div

I need some help here. I been trying to get it right for hours and i can't find an efficient solution.
<div id="Header">
<img src='http://3.bp.blogspot.com/-rN0cMMTn_Mw/ToQ6VTghSOI/AAAAAAAAAfs/xl1XMFyn7Jo/s640/18_5_orig.jpg'
/>
<h1>siajdasdasdasd</h1>
<p>sdhaosidasdas</p>
Example of what im trying to do
i want to have a liquid header with an image aligned to the left and a title aligned to the center, but both of em have to align to the middle of the height, no mather if i increase img /div's height
Had to add few more divs but it works. http://jsfiddle.net/74Rnq/23/
HTML:
<div id="Header">
<div class="wrap">
<img src='http://3.bp.blogspot.com/-rN0cMMTn_Mw/ToQ6VTghSOI/AAAAAAAAAfs/xl1XMFyn7Jo/s640/18_5_orig.jpg'/>
<div class="text">
<h1>siajdasdasdasd</h1>
<p>sdhaosidasdas</p>
</div>
</div>
</div>
CSS:
#Header {
position: relative;
height: 200px;
padding: 15px;
background: #DBE6EC;
border-bottom: 1px solid #595959;
overflow: auto;
}
#Header h1, p {
text-align: center;
letter-spacing: -1px;
text-align: center;
font-size: 2em;
color: #1F1F1F;
}
#Header p {
font-size: 1em;
}
#Header img {
float: left;
max-height:100px;
}
#Header .wrap {
display: block;
position: absolute;
width: 100%;
top: 50%;
margin-top: -50px; /* Half of wrap div height */
}
#Header .wrap .text {
position: absolute;
top: 50%;
margin-top: -27.5px; /* Half of text div height */
width: 100%;
}
For modern browsers you can do it via display:table, table-row table cell:
Modify your html like this:
<div id="Header" class="table">
<div class="row">
<div class="cell">
<img src='http://3.bp.blogspot.com/-rN0cMMTn_Mw/ToQ6VTghSOI/AAAAAAAAAfs/xl1XMFyn7Jo/s640/18_5_orig.jpg'/>
</div>
<div class="cell main">
<h1>siajdasdasdasd</h1>
<p>sdhaosidasdas</p>
</div>
</div>
</div>
#Header {
background: #DBE6EC;
border-bottom: 1px solid #595959;
position:relative;
padding:15px;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
.table {
display:table;
width:100%;
}
.row {
display:table-row;
}
.cell {
display:table-cell;
vertical-align:middle;
}
.cell.main {
width:100%;
}
The updated fiddle is here. This solution won't work in ie7. There is a older workaround for vertical align middle, if you have to support ie7.
Make the container div display: table-cell and each child div display: table-cell. Then you can give the child divs vertical-align: middle and they will always be vertically centered.
HTML:
<div id="Header">
<div id="image">
<img src='http://3.bp.blogspot.com/-rN0cMMTn_Mw/ToQ6VTghSOI/AAAAAAAAAfs/xl1XMFyn7Jo/s640/18_5_orig.jpg' />
</div>
<div id="title">
<h1>siajdasdasdasd</h1>
<p>sdhaosidasdas</p>
</div>
</div>
and CSS:
#Header {
padding: 15px;
background: #DBE6EC;
border-bottom: 1px solid #595959;
display: table;
}
#Header h1, p {
text-align: center;
letter-spacing: -1px;
font-size: 2em;
color: #1F1F1F;
}
#Header p {
font-size: 1em;
}
#Header img {
float: left;
max-height:100px;
}
#title{
display: table-cell;
vertical-align: middle;
width: 100%;
}
#image{
display: table-cell;
vertical-align: middle;
}
Aaand here's the jsFiddle.

Resources