I am currently converting an old page away from using a <table> layout and have been trying to implement the behaviour using flexbox. The aim is to have 3 columns, the first two centred horizontally and vertically, with the last column containing a lot of text, which is displaying ok.
I am trying to use a media query to wrap the third column under the first two when the browser width is small as follows:
The code snippet below achieves the correct layout but will obviously fail on small widths and just produce a single column:
I am guessing this needs flex-wrap somehow?
Are multiple rows also possible with a single container row? Or is it best to have one container per row?
.row {
display: flex;
justify-content: center;
padding: 5px;
margin: 2px;
border: 1px solid #000;
font-size: 0.7em;
}
.col1, .col2, .col3 {
background-color: #999;
padding: 8px;
margin: 2px;
}
.col1, .col2 {
flex: 1;
/* Horizontal centring */
text-align: center;
/* Add vertical centring */
display: flex;
flex-direction: column;
justify-content:center;
}
.col3 {
flex: 3;
background-color:#fff;
}
#media(max-width: 400px){
.row {display: block;}
}
<div class="row">
<div class="col1">
Column 1
</div>
<div class="col2">
Column 2
</div>
<div class="col3">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse suscipit tortor vel orci pulvinar, eu euismod sem maximus. Mauris tempus sem eget massa tristique, ut maximus tortor volutpat. In efficitur.
</div>
</div>
<div class="row">
<div class="col1">
Column 1
</div>
<div class="col2">
Column 2
</div>
<div class="col3">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse suscipit tortor vel orci pulvinar, eu euismod sem maximus. Mauris tempus sem eget massa tristique, ut maximus tortor volutpat. In efficitur.
</div>
</div>
You can get rid of the row element with some tricks, specially if you know beforehand the width of the col1 and col2 elements. Notice the width of the col3 element is quite artificial:
.row {
display: flex;
flex-wrap: wrap;
width: 95%;
border: solid 1px red;
}
.col1,
.col2 {
background-color: lightblue;
padding: 10px;
background-clip: content-box;
}
.col3 {
flex-basis: calc(100% - 194px);
padding: 5px;
}
.col1,
.col2,
.col3 {
margin: 10px 0px;
}
.col1 {
border: solid 1px black;
border-right-width: 0px;
margin-left: 10px;
}
.col2 {
border: solid 1px black;
border-left-width: 0px;
border-right-width: 0px;
}
.col3 {
border: solid 1px black;
border-left-width: 0px;
}
<div class="row">
<div class="col1">
Column 1
</div>
<div class="col2">
Column 2
</div>
<div class="col3">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse suscipit tortor vel orci pulvinar, eu euismod sem maximus. Mauris tempus sem eget massa tristique, ut maximus tortor volutpat. In efficitur.
</div>
<div class="col1">
Column 1
</div>
<div class="col2">
Column 2
</div>
<div class="col3">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse suscipit tortor vel orci pulvinar, eu euismod sem maximus. Mauris tempus sem eget massa tristique, ut maximus tortor volutpat. In efficitur.
</div>
<div class="col1">
Column 1
</div>
<div class="col2">
Column 2
</div>
<div class="col3">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse suscipit tortor vel orci pulvinar, eu euismod sem maximus. Mauris tempus sem eget massa tristique, ut maximus tortor volutpat. In efficitur.
</div>
<div class="col1">
Column 1
</div>
<div class="col2">
Column 2
</div>
<div class="col3">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse suscipit tortor vel orci pulvinar, eu euismod sem maximus. Mauris tempus sem eget massa tristique, ut maximus tortor volutpat. In efficitur.
</div>
<div class="col1">
Column 1
</div>
<div class="col2">
Column 2
</div>
<div class="col3">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse suscipit tortor vel orci pulvinar, eu euismod sem maximus. Mauris tempus sem eget massa tristique, ut maximus tortor volutpat. In efficitur.
</div>
<div class="col1">
Column 1
</div>
<div class="col2">
Column 2
</div>
<div class="col3">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse suscipit tortor vel orci pulvinar, eu euismod sem maximus. Mauris tempus sem eget massa tristique, ut maximus tortor volutpat. In efficitur.
</div>
</div>
Also, a solution for the normal layout, including 40% flex-basis for col1 and col2. They should be 50%, but since there are some margins and paddings, it's better to be on the low side and the the flex-grow compensate it
.row {
display: flex;
justify-content: center;
padding: 5px;
margin: 2px;
border: 1px solid #000;
font-size: 0.7em;
}
.col1,
.col2,
.col3 {
background-color: #999;
padding: 8px;
margin: 2px;
}
.col1,
.col2 {
flex: 1;
/* Horizontal centring */
text-align: center;
/* Add vertical centring */
display: flex;
flex-direction: column;
justify-content: center;
}
.col3 {
flex: 3;
background-color: #fff;
}
#media(max-width: 400px) {
.row {
flex-wrap: wrap;
}
.col1,
.col2 {
flex-basis: 40%;
}
.col3 {
flex-basis: 80%;
}
}
<div class="row">
<div class="col1">
Column 1
</div>
<div class="col2">
Column 2
</div>
<div class="col3">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse suscipit tortor vel orci pulvinar, eu euismod sem maximus. Mauris tempus sem eget massa tristique, ut maximus tortor volutpat. In efficitur.
</div>
</div>
<div class="row">
<div class="col1">
Column 1
</div>
<div class="col2">
Column 2
</div>
<div class="col3">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse suscipit tortor vel orci pulvinar, eu euismod sem maximus. Mauris tempus sem eget massa tristique, ut maximus tortor volutpat. In efficitur.
</div>
</div>
You would give your .row definition flex-wrap: wrap; and set a min-width value for column 3. When it gets below that width it will drop down as you have indicated above.
Related
I have the following requirements
The two boxes on the left should always be 50/50 split
The Image on the right should stretch to accommodate the text height on the left
The text on the left should never clip, the box should just enlarge to fit the text
Right now the problem is that the text on the top overflows into the bottom div like this
I've added sample code to show this problem
.section-8 {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: horizontal;
-webkit-box-direction: normal;
-webkit-flex-direction: row;
-ms-flex-direction: row;
flex-direction: row;
}
.div-block-230 {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
width: 40%;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
}
.div-block-231 {
width: 20%;
min-height: 300px;
background-color: #06c;
}
.div-block-232 {
width: 40%;
}
.div-block-233 {
height: 50%;
}
.div-block-234 {
height: 50%;
}
<body>
<div class="section-8">
<div class="div-block-230">
<div class="div-block-233">
<div>
Duis in tellus velit. Mauris vel nunc ac mi imperdiet imperdiet. Suspendisse ultrices Lorem ipsum dolor sit Duis in tellus velit. Mauris vel nunc ac mi imperdiet imperdiet. Suspendisse ultrices Lorem ipsum dolor sitDuis in tellus velit. Mauris vel nunc
ac mi imperdiet imperdiet. Suspendisse ultrices Lorem ipsum dolor sitDuis in tellus velit. Mauris vel nunc ac mi imperdiet imperdiet. Suspendisse ultrices Lorem ipsum dolor sitDuis in tellus velit. Mauris vel nunc ac mi imperdiet imperdiet.
Suspendisse ultrices Lorem ipsum dolor sitDuis in tellus velit. Mauris vel nunc ac mi imperdiet imperdiet. Suspendisse ultrices Lorem ipsum dolor sit
<br/>
</div>
</div>
<div class="div-block-234">
<div>This is some text inside of a div block.</div>
</div>
</div>
<div class="div-block-231"></div>
<div class="div-block-232"></div>
</div>
</body>
CSS Grid will do the job well. The layout will be simplified:
<div class="grid-container">
<div>Top text block</div>
<div>Bottom text block</div>
<div>The right blue column</div>
</div>
With CSS grid you'll apply min 50% to the rows grid-template-rows: minmax(50%, 1fr); and that will give you the desired result.
Finally, we'll make the blue column to span on 2 rows. So it always occupies the full height of the container.
Here's the full solution. EDIT: Forgot minmax(50%, 1fr) for the second row.
.container {
display: grid;
grid-auto-flow: column;
grid-auto-columns: 1fr;
grid-template-columns: 1fr;
grid-template-rows: minmax(50%, 1fr) minmax(50%, 1fr);
}
.blue-column {
background-color: blue;
grid-row-start: span 2;
grid-row-end: span 2;
}
<div class="container">
<div style="background-color: yellow;">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse varius enim in eros elementum tristique. Duis cursus, mi quis viverra ornare, eros dolor interdum nulla, ut commodo diam libero vitae erat. Aenean faucibus nibh et justo cursus id rutrum lorem imperdiet. Nunc ut sem vitae risus tristique posuere.</p>
</div>
<div style="background-color: red;">
<div>This is some text inside of a div block.</div>
</div>
<div class="blue-column"></div>
</div>
Here is my solution:
https://jsfiddle.net/mn927ugt/101/
css:
.container {
display: flex;
flex-direction: row;
justify-content: space-between;
height: 100%;
width: 100%;
}
.text-container {
display: flex;
flex-direction: column;
width: 50%;
align-content: space-between;
}
.lorem-ipsum {
margin-bottom: 10px;
}
p {
margin: 0;
}
.image-container {
display: flex;
flex-direction: row;
justify-content: space-around;
width: 50%;
}
.image {
background-color: blue;
width: 50%;
}
.empty-div {
width: 50%;
}
html:
<body>
<div class="container">
<div class="text-container">
<p class="lorem-ipsum">
Duis in tellus velit. Mauris vel nunc ac mi imperdiet imperdiet. Suspendisse ultrices Lorem ipsum dolor sit Duis in tellus velit. Mauris vel nunc ac mi imperdiet imperdiet. Suspendisse ultrices Lorem ipsum dolor sitDuis in tellus velit. Mauris vel nunc ac mi imperdiet imperdiet. Suspendisse ultrices Lorem ipsum dolor sitDuis in tellus velit. Mauris vel nunc ac mi imperdiet imperdiet. Suspendisse ultrices Lorem ipsum dolor sitDuis in tellus velit. Mauris vel nunc ac mi imperdiet imperdiet. Suspendisse ultrices Lorem ipsum dolor sitDuis in tellus velit. Mauris vel nunc ac mi imperdiet imperdiet. Suspendisse ultrices Lorem ipsum dolor sit
</p>
<p class="text">
This is some text inside of a div block.
</p>
</div>
<div class="image-container">
<div class="image"></div>
<div class="empty-div"></div>
</div>
</div>
</body>
Update:
Vertically aligned textboxes and added empty div
I'm trying to code this hero treatment.
The title and paragraph text is contained to a grid that has a max-width of 1200px and auto left and right margins.
The top and bottom borders should come from the left edge, but stop at the end of the centered 1200px text box.
I've coded them as HRs thinking that may be more helpful to style.
<div class="hero">
<img src="https://via.placeholder.com/1600x800" alt="">
<div class="hero-text">
<hr>
<div class="contain-to-grid">
<h1>Title</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut eget laoreet dolor. Etiam quis leo venenatis, suscipit nisi id, luctus urna. Aenean iaculis justo vel consectetur mollis. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut eget laoreet dolor. Etiam quis leo venenatis, suscipit nisi id, luctus urna. Aenean iaculis justo vel consectetur mollis.</p>
</div>
<hr>
</div>
</div>
and here's my CSS (this is currently just making the HRs go full-width)
.hero {position: relative;}
.hero img {width: 100%; height: auto;}
.hero-text {position: absolute; bottom: 30px; width: 100%;}
.hero-text hr {border-color: #000; margin: 30px 0;}
.contain-to-grid {width: 100%; max-width: 1200px; margin: 0 auto;}
I'm stumped. Any ideas on how to code this? It does need to be responsive.
Just added '.inner' div and added css. Hope this help you.
.hero {
position: relative;
}
.hero img {
width: 100%;
height: auto;
}
.hero-text {
position: absolute;
bottom: 30px;
width: 100%;
}
.hero-text hr {
border-color: #000;
margin: 30px 0;
}
.contain-to-grid {
width: 100%;
max-width: 1200px;
margin: 0 auto;
}
.inner {
float: left;
width: 100%;
border-top: 2px solid #000;
border-bottom: 2px solid #000;
}
<div class="hero">
<img src="https://via.placeholder.com/1600x800" alt="">
<div class="hero-text">
<div class="contain-to-grid">
<div class="inner">
<h1>Title</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut eget laoreet dolor. Etiam quis leo venenatis, suscipit nisi id, luctus urna. Aenean iaculis justo vel consectetur mollis. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut eget
laoreet dolor. Etiam quis leo venenatis, suscipit nisi id, luctus urna. Aenean iaculis justo vel consectetur mollis.</p>
</div>
</div>
</div>
</div>
I was wondering if the layout I draw on the following image is possible using flexbox and this HTML structure:
<div class="box">
<img src="url..." alt="" />
<h5>Lorem Ipsum</h5>
<p>Lorem Ipsum Dolor Sit Amet...</p>
</div>
It would be great if this could be done with flexbox and without adding more boxes inside.
For fixed image width and height, it's possible. The main idea is in the following snippet.
.box {
display: flex;
flex-direction: column;
flex-wrap: wrap;
align-content: space-between;
height: 300px;
}
.img {
width: 300px; height: 300px;
}
h5, p {
/* 100% - image width - margin between */
width: calc(100% - 300px - 16px);
}
Since the height of the parent is the same as the height of the image, the content overflows and gets wrapped to the right. Then we have to manually set the width because it's otherwise going to 100% of the parent.
.box {
background-color: #ddd;
padding: 16px;
margin-bottom: 24px;
display: flex;
flex-direction: column;
flex-wrap: wrap;
height: 300px;
align-content: space-between;
}
.img {
background-color: #333;
color: #ddd;
width: 300px;
height: 300px;
}
h5, p {
padding: 0;
margin: 0;
background-color: #ccc;
/* 100% - image width - margin between */
width: calc(100% - 300px - 16px);
}
h5 {
font-size: 18px;
margin-bottom: 8px;
}
.box:nth-child(even) .img {
order: 3;
}
<div class="box">
<div class="img"><img></div>
<h5>Lorem Ipsum</h5>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur mollis cursus hendrerit. Suspendisse potenti. Aliquam posuere ex ut lacus euismod dictum. Proin et ligula posuere leo viverra tempor a in tellus</p>
</div>
<div class="box">
<div class="img"><img></div>
<h5>Lorem Ipsum</h5>
<p>Lorem Ipsum Dolor Sit Amet...</p>
</div>
<div class="box">
<div class="img"><img></div>
<h5>Lorem Ipsum</h5>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur mollis cursus hendrerit. Suspendisse potenti. Aliquam posuere ex ut lacus euismod dictum. Proin et ligula posuere leo viverra tempor a </p>
</div>
Full-height paragraph
You might want to extend your paragraph all the way to the bottom (maybe add some links there). It's easy to extend it so you can turn p into flexbox to snap something to the bottom, for example (this example not in the demo below, you can only notice this by the gray background).
.box {
/* ... */
justify-content: space-between;
}
p {
flex-grow: 1;
}
.box {
background-color: #ddd;
padding: 16px;
margin-bottom: 24px;
display: flex;
flex-direction: column;
flex-wrap: wrap;
height: 300px;
align-content: space-between;
justify-content: space-between;
}
.img {
background-color: #333;
color: #ddd;
width: 300px;
height: 300px;
}
h5, p {
padding: 0;
margin: 0;
background-color: #ccc;
/* 100% - image width - margin between */
width: calc(100% - 300px - 16px);
}
h5 {
font-size: 18px;
margin-bottom: 8px;
}
p {
flex-grow: 1;
}
.box:nth-child(even) .img {
order: 3;
}
<div class="box">
<div class="img"><img></div>
<h5>Version 2</h5>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur mollis cursus hendrerit. Suspendisse potenti. Aliquam posuere ex ut lacus euismod dictum. Proin et ligula posuere leo viverra tempor a in tellus</p>
</div>
<div class="box">
<div class="img"><img></div>
<h5>Lorem Ipsum</h5>
<p>Lorem Ipsum Dolor Sit Amet...</p>
</div>
<div class="box">
<div class="img"><img></div>
<h5>Lorem Ipsum</h5>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur mollis cursus hendrerit. Suspendisse potenti. Aliquam posuere ex ut lacus euismod dictum. Proin et ligula posuere leo viverra tempor a in tellus. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur mollis cursus hendrerit. Suspendisse potenti. </p>
</div>
Both versions above breaks when the text cannot fit (try changing browser window size).
Doesn't show all, but never breaks
You can set the max-height for the paragraph if you don't want it to break and clip the text which cannot fit with overflow: hidden.
p {
max-height: 250px;
overflow: hidden;
}
.box {
background-color: #ddd;
padding: 16px;
margin-bottom: 24px;
display: flex;
flex-direction: column;
flex-wrap: wrap;
height: 300px;
align-content: space-between;
justify-content: space-between;
}
.img {
background-color: #333;
color: #ddd;
width: 300px;
height: 300px;
}
h5, p {
padding: 0;
margin: 0;
background-color: #ccc;
/* 100% - image width - margin between */
width: calc(100% - 300px - 16px);
}
h5 {
font-size: 18px;
margin-bottom: 8px;
}
p {
flex-grow: 1;
}
.box:nth-child(even) .img {
order: 3;
}
p {
max-height: 250px;
overflow: hidden;
}
<div class="box">
<div class="img"><img></div>
<h5>Version 3</h5>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur mollis cursus hendrerit. Suspendisse potenti. Aliquam posuere ex ut lacus euismod dictum. Proin et ligula posuere leo viverra tempor a in tellus</p>
</div>
<div class="box">
<div class="img"><img></div>
<h5>Lorem Ipsum</h5>
<p>Lorem Ipsum Dolor Sit Amet...</p>
</div>
<div class="box">
<div class="img"><img></div>
<h5>Lorem Ipsum</h5>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur mollis cursus hendrerit. Suspendisse potenti. Aliquam posuere ex ut lacus euismod dictum. Proin et ligula posuere leo viverra tempor a in tellus. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur mollis cursus hendrerit. Suspendisse potenti. Aliquam posuere ex ut lacus euismod dictum. Proin et ligula posuere leo viverra tempor a in tellus. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur mollis cursus hendrerit. Suspendisse potenti. Aliquam posuere ex ut lacus euismod dictum. Proin et ligula posuere leo viverra tempor a in tellus. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur mollis cursus hendrerit. Suspendisse potenti. Aliquam posuere ex ut lacus euismod dictum. Proin et ligula posuere leo viverra tempor a in tellus. </p>
</div>
A following html markup creates a QA section in my site.
I want it to be this way - sentence in Q section should be positioned on the same line as "Q" symbol; Sentences in A section should be moved slightly to the right and each sentence should start from new line.
Like this:
But for now it looks this way:
<html>
<head>
<style type="text/css">
.qa b {
font-size: 50px;
}
.qa .answer_box {
margin-left: 90px;
display: inline;
}
.qa p {
font-size: 25px;
}
</style>
</head>
<div class="qa">
<div class="question">
<b>Q</b>
<p>
Do you believe in SEO?
</p>
</div>
<div class="answer">
<b>A</b>
<div class="answer_box">
<p>
Yes I Do
</p>
<p>
SEO is a very powerful technique to increase your site ranking in Google.
</p>
<p>
Also it just cool and so so so.
</p>
</div>
</div>
</div>
Would be grateful for your help.
Use float and a padding/margin maneuver, with the b tag replaced with a strong and place within the first p tag per block:
p strong {
float: left;
margin-left: -1.5em;
font-size: 3em;
}
p {
padding-left: 5em;
}
<p>
<strong>Q:</strong>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non turpis cursus, viverra libero a, ultricies enim. Cras quis ornare urna, condimentum luctus lorem. Aliquam et odio et magna pretium molestie. Fusce pulvinar nisi id mi pharetra scelerisque. Sed mollis accumsan tincidunt. Quisque libero erat, gravida sed rutrum et, volutpat non dui. Etiam eget leo in ipsum consectetur iaculis. Vestibulum dictum leo quis tristique feugiat. Donec vestibulum odio placerat, tincidunt orci vel, sagittis nibh. Integer ultricies ultrices ornare. Duis neque ligula, facilisis sit amet metus eget, adipiscing rhoncus justo. Nam fermentum suscipit mauris, nec volutpat augue condimentum ac. Mauris consequat ante sed lacus vehicula scelerisque. In non gravida ligula, at dapibus ligula.
</p>
<p>
<strong>A:</strong>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non turpis cursus, viverra libero a, ultricies enim.
</p>
<p>Cras quis ornare urna, condimentum luctus lorem. Aliquam et odio et magna pretium molestie. Fusce pulvinar nisi id mi pharetra scelerisque. Sed mollis accumsan tincidunt. Quisque libero erat, gravida sed rutrum et, volutpat non dui. Etiam eget leo in ipsum consectetur iaculis. Vestibulum dictum leo quis tristique feugiat. Donec vestibulum odio placerat, tincidunt orci vel, sagittis nibh. Integer ultricies ultrices ornare. Duis neque ligula, facilisis sit amet metus eget, adipiscing rhoncus justo. Nam fermentum suscipit mauris, nec volutpat augue condimentum ac. Mauris consequat ante sed lacus vehicula scelerisque. In non gravida ligula, at dapibus ligula.</p>
http://jsfiddle.net/userdude/cZJhU/5/
Keep in mind you'll want to use classes to add these styles, not element-level selectors like p and p strong. This is for demonstration purposes only.
NOTE
For those claiming it does not look like what the OP asked for, here is what it appears like in every browser I look at it with:
I just rewrote your code as I couldn't deal with it - this looks exactly how you'd like it to be:
http://jsfiddle.net/f8NjK/
<div class="wrapper">
<div class="leftcol">
<strong>Q</strong>
</div>
<div class="rightcol">
<p>Do you believe in SEO?</p>
</div>
<div class="leftcol">
<strong>A</strong>
</div>
<div class="rightcol">
<p>Yes I do</p>
<p>SEO is a very powerful technique to increase your site ranking in Google.</p>
<p>Also it just cool and so and so</p>
</div>
</div>
CSS:
strong {
font-size: 50px;
}
.wrapper {
width:100%;
}
.leftcol {
width:10%;
display:inline-block;
}
.rightcol {
width:80%;
vertical-align:top;
display:inline-block;
}
I put a container. check this fiddle for live demo. http://jsfiddle.net/KdPfz/1/
.container
{
width: 100%;
height: 60px;
}
.letter
{
font-size: 50px;
float: left;
}
.sentence
{
width: 350px;
margin-top: 20px;
margin-left: 20px;
font-size: 20px;
float: left;
z-index: 5;
}
Like this?
<html>
<head>
<style type="text/css">
.qa b {
font-size: 50px;
}
.qa .answer_box {
margin-left: 90px;
display: inline;
}
.qa p {
font-size: 25px;
display: block;
}
.answer_box p {
margin-left: 50px;
}
</style>
</head><body>
<div class="qa">
<div class="question">
<b>Q</b>
<p style="display: inline-block;">
Do you believe in SEO?
</p>
</div>
<div class="answer">
<b>A</b>
<div class="answer_box">
<p style="display: inline-block;">
Yes I Do
</p>
<p>
SEO is a very powerful technique to increase your site ranking in Google.
</p>
<p>
Also it just cool and so so so.
</p>
</div>
</div>
</div>
If you inject a display: inline-block; style into your first p tag, leave the rest to the p tags natural block format, and a conditional margin for the answer block.
This may be more what you are looking for - a fiddle - I re-wrote your html to avoid using styling elements
<div class="qa">
<div class="question">
<div class="bold-letters">Q</div>
<div class="questions">
<p>Do you believe in SEO?</p>
</div>
</div>
<div class="answer">
<div class="answer_box">
<div class="bold-letters">A</div>
<div class="answers">
<p>
Yes I Do
</p>
<p>
SEO is a very powerful technique to increase your site ranking in Google.
</p>
<p>
Also it just cool and so so so.
</p>
</div>
</div>
</div>
and some short css
.bold-letters, .answers, .questions{
display:inline-block;
}
.bold-letters{
font-size:50px;
vertical-align:top;
margin-right: 30px;
}
.questions{
vertical-align:bottom;
}
I was writing this while the other answers popped up
http://jsfiddle.net/tprats108/ugaYM/
css:
.qa {
font-size: 25px;
}
.qa .heading {
font-weight: bold;
font-size: 50px;
float: left;
}
.qa .response {
float: left;
margin-left: 20px;
}
.clear {
clear: both;
}
html:
<div class="qa">
<div class="question">
<div class="heading">Q</div>
<div class="response">
<p>Do you believe in SEO?</p>
</div>
</div>
<div class="clear"></div>
<div class="answer">
<div class="heading">A</div>
<div class="response">
<p>Yes I Do</p>
<p>SEO is a very powerful technique to increase your site ranking in Google.</p>
<p>Also it just cool and so so so.</p>
</div>
</div>
</div>
i am trying to set 3 divs inside the parent div, the parent div will resize after the biggest height of the child divs but i also want the other 2 child divs to take the same size as the biggest one in height.
<div id="parent">
<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
</div>
the parent div will be 600px width and no height given so it will expand depending of the child div biggest height.
#parent {
width: 600px;
overflow: auto;
}
.child {
width: 200px;
float: left;
}
This is what i got so far but if the child divs have different heights, the parent div height is the biggest of the child div heights, but the other 2 child divs dont take the height of the parent ( of the biggest child div in height).
Thank you in advance,
Daniel!
This: http://matthewjamestaylor.com/blog/equal-height-columns-cross-browser-css-no-hacks and this: http://buildinternet.com/2009/07/four-methods-to-create-equal-height-columns/ may help.
One way would be to use the new feature from CSS display: grid
#parent {
display: grid;
width: 100%;
grid-template-columns: auto auto auto;
/* Just for styling */
text-align: center;
}
.child {
/* Just for styling */
box-sizing: border-box;
background-color: lightyellow;
border: 2px dashed red;
padding: 20px;
}
<div id="parent">
<div class="child">This is first</div>
<div class="child">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse volutpat dolor ante, eu ultricies eros molestie nec. Fusce laoreet laoreet nibh, vel vehicula nunc varius ut</div>
<div class="child">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse volutpat dolor ante, eu ultricies eros molestie nec. Fusce laoreet laoreet nibh, vel vehicula nunc varius utLorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse volutpat dolor ante, eu ultricies eros molestie nec. Fusce laoreet laoreet nibh, vel vehicula nunc varius ut</div>
</div>
Or another one would be the display: flex.
#parent {
display: flex;
flex-flow: row nowrap;
}
.child {
width: 33.3333%; /* Force the column to be a third of the parent width */
/* Just for styling */
box-sizing: border-box;
background-color: lightyellow;
border: 2px dashed red;
text-align: center;
padding: 20px;
}
<div id="parent">
<div class="child">The first one</div>
<div class="child">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse volutpat dolor ante, eu ultricies eros molestie nec. Fusce laoreet laoreet nibh, vel vehicula nunc varius ut</div>
<div class="child">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse volutpat dolor ante, eu ultricies eros molestie nec. Fusce laoreet laoreet nibh, vel vehicula nunc varius utLorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse volutpat dolor ante, eu ultricies eros molestie nec. Fusce laoreet laoreet nibh, vel vehicula nunc varius ut</div>
</div>