I've been working on a design that has been giving me some trouble. This is how it should look
My code is very similar to this design but I'm not able to get it to fit properly.
I currently have it set up with a media query to scale the images down and stack under the section of text as the screen size gets smaller; however, while the window size is in the process of getting smaller, it drops the images under the text and leaves a large white space.
Additionally, at full resolution, there is a gap between the images and the text but I can't seem to get them to sit beside each other. Is there something I could be doing that will make this design easier to achieve?
.redText{
background-color: #f0f0f0;
max-width: 400px;
display: block;
float: left;
padding-left: 10%;
}
.redText h1{
font-size: 40px;
color: #424242;
padding: 45px 20px 40px 20px;
}
.redText h2{
color: #d0112b;
padding: 0px 20px 40px 20px;
margin-top: -66px;
border-bottom: 10px solid #d0112b;
}
.redText p{
font-size: 18px;
line-height: 24px;
color: #424242;
padding: 0px 20px 110px 20px;
}
.redMore a{
text-decoration: none;
}
.blueText{
background-color: #f0f0f0;
max-width: 400px;
display: block;
float: right;
padding-right: 10%
}
.blueText h1{
font-size: 40px;
color: #424242;
padding: 45px 20px 40px 20px;
}
.blueText h2{
color: #0a5587;
padding: 0px 20px 40px 20px;
margin-top: -66px;
border-bottom: 10px solid #0a5587;
}
.blueText p{
font-size: 18px;
line-height: 24px;
color: #424242;
padding: 0px 20px 110px 20px;
}
.blueMore a{
text-decoration: none;
}
.space{
float: right;
}
.wrapper{
overflow: hidden;
}
.redImg img{
float: right;
max-width: 100%;
}
.blueImg img{
float: left;
max-width: 100%;
}
#media screen and (max-width: 480px) {
.redImg img{
float: none;
margin-left: 0;
width: auto;
}
.blueImg img{
float: none;
margin-right: 0;
width: auto;
}
}
<div class="wrapper">
<div class="redText">
<h1>RETAIL</h1><br>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed laoreet porta libero, nec efficitur neque scelerisque at. Maecenas a ligula nec ante tincidunt pellentesque in quis libero. Nulla lorem ante, pulvinar at ultricies ut, tempor vel mi.</p><br>
<div style="clear: both"></div>
<div class="redMore">
<h2>LEARN MORE<span class="space">></span></h2>
</div>
</div>
<div class="redImg"><img src="images/work/retail.jpg"></div>
</div>
<div class="wrapper">
<div class="blueText">
<h1>INDUSTRIAL</h1><br>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed laoreet porta libero, nec efficitur neque scelerisque at. Maecenas a ligula nec ante tincidunt pellentesque in quis libero. Nulla lorem ante, pulvinar at ultricies ut, tempor vel mi.</p><br>
<div style="clear: both"></div>
<div class="blueMore">
<h2>LEARN MORE<span class="space">></span></h2>
</div>
</div>
<div class="blueImg"><img src="images/work/industrial.jpg"></div>
</div>
<div class="wrapper">
<div class="redText">
<h1>COMMERCIAL</h1><br>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed laoreet porta libero, nec efficitur neque scelerisque at. Maecenas a ligula nec ante tincidunt pellentesque in quis libero. Nulla lorem ante, pulvinar at ultricies ut, tempor vel mi.</p><br>
<div style="clear: both"></div>
<div class="redMore">
<h2>LEARN MORE<span class="space">></span></h2>
</div>
</div>
<div class="redImg"><img src="images/work/commercial.jpg"></div>
</div>
<div class="wrapper">
<div class="blueText">
<h1>HOTELS</h1><br>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed laoreet porta libero, nec efficitur neque scelerisque at. Maecenas a ligula nec ante tincidunt pellentesque in quis libero. Nulla lorem ante, pulvinar at ultricies ut, tempor vel mi.</p><br>
<div style="clear: both"></div>
<div class="blueMore">
<h2>LEARN MORE<span class="space">></span></h2>
</div>
</div>
<div class="blueImg"><img src="images/work/hotels.jpg"></div>
</div>
There is several way to approach your problem:
Use % in width of your element instead of number px: Go with 50%-50% for the block of image and the block of text, use display:inline-block to put them next to each other
Use a CSS Framework like Bootstrap or Foudation, a best example to use in your case is media
EDIT1
Update with codepen: http://codepen.io/thovo/pen/EKwYpq
Related
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 am struggling with the setting three responsive columns in a row using Bootstrap 4.
.buttons {
border: 1px solid #e86225;
color: #e86225 !important;
padding: 10px 20px;
font-size: 14px;
}
.buttons:hover {
border: 1px solid #ffffff;
background-color: #e86225;
color: #ffffff !important;
transition: background-color 1s, border 1s, color 1s;
}
.container-custom {
padding-top: 80px;
padding-bottom: 80px;
}
.custom-link {
padding: 15px 0;
}
.container p {
margin: 25px 0;
max-width: 400px;
}
#media(max-width: 767px){
.container-custom {
padding-top: 50px;
padding-bottom: 50px;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">
<div class="container">
<div class="row container-custom justify-content-center">
<h2>Blog</h2>
<div class='d-flex flex-wrap pt-5'>
<div class="col-sm-12 col-md-4">
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSHBMzMRL0g3ELio_DdCRvdajdF812AQPP2AbmM_jYr_66CnwgS" alt="">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque nibh sem, ultricies sit amet tellus ut, iaculis interdum ante. Quisque at nibh ac diam faucibus congue.
</p>
<div class="custom-link">
Read more >
</div>
</div>
<div class="col-sm-12 col-md-4">
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQh3Afn3A1FKb24tpO6eAdqr8hCdnafjqwCNqgjdSAWK1igoWfk" alt="">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque nibh sem, ultricies sit amet tellus ut, iaculis interdum ante. Quisque at nibh ac diam faucibus congue.
</p>
<div class="custom-link">
Read more >
</div>
</div>
<div class="col-sm-12 col-md-4">
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQFsb6TxovKdTNx-8gdo1R01nZXxRRauett2KQ_ci76VgjK2hR7" alt="">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque nibh sem, ultricies sit amet tellus ut, iaculis interdum ante. Quisque at nibh ac diam faucibus congue.
</p>
<div class="custom-link">
Read more >
</div>
</div>
</div>
</div>
The problem is when media screen width is smaller than 767px, they are going to the left. I want to make image in the middle of column, the beginning of the text should be at the beginning of the imaeg and the end of text at the end of image, button should be at the beginning of the image too like here:
enter image description here
Just add width:100% to your images so they take all the space on the column
.buttons {
border: 1px solid #e86225;
color: #e86225 !important;
padding: 10px 20px;
font-size: 14px;
}
.buttons:hover {
border: 1px solid #ffffff;
background-color: #e86225;
color: #ffffff !important;
transition: background-color 1s, border 1s, color 1s;
}
.container-custom {
padding-top: 80px;
padding-bottom: 80px;
}
.custom-link {
padding: 15px 0;
}
.container p {
margin: 25px 0;
max-width: 400px;
}
img{
width:100%;
}
#media(max-width: 767px){
.container-custom {
padding-top: 50px;
padding-bottom: 50px;
}
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">
<div class="container">
<div class="row container-custom justify-content-center">
<h2>Blog</h2>
<div class='d-flex flex-wrap pt-5'>
<div class="col-sm-12 col-md-4">
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSHBMzMRL0g3ELio_DdCRvdajdF812AQPP2AbmM_jYr_66CnwgS" alt="">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque nibh sem, ultricies sit amet tellus ut, iaculis interdum ante. Quisque at nibh ac diam faucibus congue.
</p>
<div class="custom-link">
Read more >
</div>
</div>
<div class="col-sm-12 col-md-4">
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQh3Afn3A1FKb24tpO6eAdqr8hCdnafjqwCNqgjdSAWK1igoWfk" alt="">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque nibh sem, ultricies sit amet tellus ut, iaculis interdum ante. Quisque at nibh ac diam faucibus congue.
</p>
<div class="custom-link">
Read more >
</div>
</div>
<div class="col-sm-12 col-md-4">
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQFsb6TxovKdTNx-8gdo1R01nZXxRRauett2KQ_ci76VgjK2hR7" alt="">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque nibh sem, ultricies sit amet tellus ut, iaculis interdum ante. Quisque at nibh ac diam faucibus congue.
</p>
<div class="custom-link">
Read more >
</div>
</div>
</div>
</div>
The image width could be the issue. Add img { width: 100%; } and class="img-fluid" to your img tags.
Add to css:
img { width: 100%; }
HTML:
<img class="img-fluid" src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQh3Afn3A1FKb24tpO6eAdqr8hCdnafjqwCNqgjdSAWK1igoWfk" alt="">
or something similar so the images look like the layout in your attached image.
Example codepen using your code: https://codepen.io/brooksrelyt/pen/MZdLYj
Aloha - I have been recreating this tutorial - [CSS Positioning][1] -
[1]: http://www.barelyfitz.com/screencast/html-training/css/positioning/ to really understand the tutorial. It's at step 7 in the tutorial that I have bumped into something that I can't figure out. In step 7 of the tutorial you will see that the text "id = div-1" sits above the "div-1a" which is floated left.
If you take a look at my code pen - http://codepen.io/DarrenHaynes/pen/gLoYpp/ - You will see that the text "id = div-1" is aligning to the right of the "div-1a". I am not expecting this since "div-1" is the parent of "div-1a". Thus I can't figure out how to get my codepen to replicate the tutorial.
My code on codepen:
HTML:
<div id="div-before">
id = div-before
</div>
<div id="div-1">
id = div-1
<div id="div-1a">
id = div-1a
<br>
<br> Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Integer pretium dui sit amet felis. Integer sit amet diam. Phasellus ultrices viverra velit.
</div>
<div id="div-1b">
id = div-1b<br><br> Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Integer pretium dui sit amet felis. Integer sit amet diam. Phasellus ultrices viverra velit. Nam mattis, arcu ut bibendum commodo, magna nisi tincidunt tortor, quis accumsan
augue ipsum id lorem.
</div>
<div id=div-1c>
id = div-1c
</div>
</div>
<div id="div-after">
id = div-after
</div>
CSS:
#div-before,
#div-after {
margin: 0 auto;
width: 400px;
font-size: 20px;
background-color: #8888DD;
padding: 2px 5px;
}
#div-1 {
position: relative;
margin: 0 auto;
width: 400px;
color: white;
padding: 20px 10px 10px 10px;
background-color: black;
}
#div-1a {
float: left;
width: 200px;
padding: 3px;
background-color: red;
}
#div-1b {
padding: 3px;
background-color: green;
}
#div-1c {
padding: 3px;
background-color: #33D;
}
You can wrap your heading for "div-1" around a 'p' tag:
<div id="div-before">
id = div-before
</div>
<div id="div-1">
<p>id = div-1</p>
<div id="div-1a">
id = div-1a
<br>
<br> Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Integer pretium dui sit amet felis. Integer sit amet diam. Phasellus ultrices viverra velit.
</div>
<div id="div-1b">
id = div-1b<br><br> Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Integer pretium dui sit amet felis. Integer sit amet diam. Phasellus ultrices viverra velit. Nam mattis, arcu ut bibendum commodo, magna nisi tincidunt tortor, quis accumsan
augue ipsum id lorem.
</div>
<div id=div-1c>
id = div-1c
</div>
</div>
<div id="div-after">
id = div-after
</div>
CSS:
#div-before,
#div-after {
margin: 0 auto;
width: 400px;
font-size: 20px;
background-color: #8888DD;
padding: 2px 5px;
}
#div-1 {
position: relative;
margin: 0 auto;
width: 400px;
color: white;
padding: 20px 10px 10px 10px;
background-color: black;
}
#div-1a {
float: left;
width: 200px;
padding: 3px;
background-color: red;
}
#div-1b {
padding: 3px;
background-color: green;
}
#div-1c {
padding: 3px;
background-color: #33D;
}
Here's the Codepen: http://codepen.io/anon/pen/xRJNdZ
Please see this Fiddle...
I have two columns. Left column holds paragraph titles. Right column holds the actual paragraphs. I'm trying to align the paragraph title, with the top line of each paragraph and I'm having the hardest time doing it without using unnecessary and sloppy line breaks.
.col1 {float: left; width: 300px; border: 1px solid black; padding: 10px;}
.col2 {float: left; width: 300px; border: 1px solid black; padding: 10px;}
.line1 { height: auto; margin: 10px 0 20px 0; }
.line2 { height: auto; margin: 10px 0 20px 0; }
.line3 { height: auto; margin: 10px 0 20px 0; }
Thoughts?
This is a perfect example of when good ol' <table> elements are still useful! Also, notice that if the overall width is not big enough, your paragraphs wrap under all the titles completely.
The proper way to do this is to use a definition list
See: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/dl
<dl>
<dt>Firefox</dt>
<dt>Mozilla Firefox</dt>
<dt>Fx</dt>
<dd>A free, open source, cross-platform, graphical web browser
developed by the Mozilla Corporation and hundreds of volunteers.</dd>
<!-- other terms and definitions -->
</dl>
If you did want to do this in div elements and not dt, have a look at this fiddle
HTML
<div class='wrapper'>
<div class="col1">
Paragraph 1
</div>
<div class="col2">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean eros est, pellentesque in leo at, molestie mattis sem. Phasellus at est in ligula malesuada ullamcorper nec et massa.
</div>
<div style='clear:both;'></div>
<div class="col1">
Paragraph 2
</div>
<div class="col2">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean eros est, pellentesque in leo at, molestie mattis sem. Phasellus at est in ligula malesuada ullamcorper nec et massa.
</div>
<div style='clear:both;'></div>
<div class="col1">
Paragraph 3
</div>
<div class="col2">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean eros est, pellentesque in leo at, molestie mattis sem. Phasellus at est in ligula malesuada ullamcorper nec et massa.
</div>
<div style='clear:both;'></div>
</div>
CSS
body{
width:100%;
}
.wrapper{
border: 1px solid black;
}
.col1, .col2 {
float: left; width: 300px; padding: 10px;
}
.col2{
border-left:1px solid black;
}
I have a <ul> <li> and I require the use of display: inline-block;. This is required in order to "float" the li's whilst the last element is 100% wide of it's parent container and there could be any amount of li's (floating would mean the amount of li's is finite depending on the width of it's containing element). So the total width of the <ul> will be greater than the width of the viewport.
This is fine except I require the "floated" elements to multiline and I expect all elements which are not multi lined to be 100% height of the <ul>.
I can achieve what I want by setting the height of the <ul> in JS but this is something I really do not want to do.
Here is a JS fiddle.
http://jsfiddle.net/d5WBv/3/
Does anyone have a solution. I'm not sure if flexbox or display: table; can solve this but I cannot seem to get it to....
Thanks!
I guess, you mean that the li's all should have the same height?
If so, you could display them as table-cells:
ul {
display: table;
width: 100%;
}
li {
vertical-align: top;
display: table-cell;
padding: 10px;
margin: 0;
}
Also, check the updated fiddle.
I have a CSS solution for you, check out this Working Fiddle
DownSide: it requires to Double the ul li elements,
(one of them is for taking the real space in the document flow, (he don't render as we want but so will be hidden), and one of them is showed, on top of the other, with the display you want.
HTML:
<div class="Container">
<ul class="Hidden">
<li>This stays on one line</li>
<li>And this</li>
<li>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed auctor libero neque, nec tristique metus rutrum et. Integer semper libero quis magna placerat, a posuere sem congue.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed auctor libero neque, nec tristique metus rutrum et. Integer semper libero quis magna placerat, a posuere sem congue.</li>
</ul>
<ul class="Visible">
<li>This stays on one line</li>
<li>And this</li>
<li>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed auctor libero neque, nec tristique metus rutrum et. Integer semper libero quis magna placerat, a posuere sem congue.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed auctor libero neque, nec tristique metus rutrum et. Integer semper libero quis magna placerat, a posuere sem congue.</li>
</ul>
</div>
CSS:
*
{
padding: 0;
margin: 0;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
.Container
{
position: relative;
}
.Hidden
{
visibility: hidden;
}
.Visible
{
position: absolute;
top: 0;
height: 100%;
}
ul
{
white-space: nowrap;
background-color: #cccccc;
font-size: 0;
}
li
{
display: inline-block;
padding: 10px;
border-right: 1px solid red;
background-color: #2c2c2c;
text-align: center;
color: #fefefe;
white-space: normal;
vertical-align: top;
font-size: 16px;
height: 100%;
}
li:last-child
{
width: 100%;
border-right: 1px solid #2b2b2b;
}