I have tried to make like this block but wasn't able to make as in the design. How can I make it? Can you help me? Here is desired block
and code I have tried:
.section-1 {
background: green;
height: 100px;
}
.section-2 {
display: flex;
align-items: center;
}
.col-img {
margin-top: -40px;
position: relative;
}
.col-img:after {
top: 40px;
position: absolute;
right: 100%;
width: 10px;
background: purple;
content: '';
bottom: 0;
}
.col-img img{
width: 100%;
vertical-align: top;
}
.section-2 .col {
width: 50%;
}
<div class="section-1">
</div>
<div class="section-2">
<div class="col">
<p>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Harum voluptatem beatae quia facilis nobis, dolore quidem nostrum! Blanditiis eveniet dolor a, laudantium repudiandae rem commodi ea adipisci. Eius, obcaecati rerum.</p>
</div>
<div class="col col-img">
<img src="http://via.placeholder.com/650x650" alt="">
</div>
</div>
I would consider multiple background and some border like this like this:
body {
margin:0;
}
.box {
padding:40px calc(100% - 250px) 10px 20px;
box-sizing:border-box;
border-top:30px solid lightblue;
border-bottom:5px solid yellow;
height:350px;
background:
linear-gradient(120deg, lightblue 280px,transparent 280px)0 0/100% 40px no-repeat,
linear-gradient(120deg,white 250px,yellow 250px,yellow 280px,transparent 280px)0 0/100% 100% no-repeat,
url(https://lorempixel.com/1000/1000/) 0 0/cover no-repeat;
}
<div class="box">
lorem ipsum lorem ipsumlorem ipsum lorem ipsum lorem ipsum
</div>
Or more easier way with more element and some transformation:
body {
margin:0;
}
.box {
box-sizing:border-box;
border-top:30px solid lightblue;
border-bottom:5px solid yellow;
height:100vh;
display:flex;
background:url(https://lorempixel.com/1000/1000/) 0 0/cover no-repeat;
}
.content {
padding:20px 5px 0 30px;
box-sizing:border-box;
width:40%;
border-top:20px solid lightblue;
background:linear-gradient(yellow,yellow) 100% 0/10px 100% no-repeat;
transform:skew(-20deg);
transform-origin:top left;
background-color:#fff;
}
.content span{
display:inline-block;
transform:skew(20deg);
}
<div class="box">
<div class="content">
<span> lorem ipsum lorem ipsum lorem ipsum lorem ipsum</span>
</div>
</div>
You will want to use the CSS3 transform property, to skew your image. You can use either the skewX() or skewY() functions, or you can rotate().
.col-img {
transform:rotate(25deg);
}
Hope this helps.
Related
I have a layout where the border starts from middle of the image and merges with the below border
I have tried the following things:
Used background image as border but it cannot acheive the same thing.
I have ried to use :before & :after but unable to make it same like this.
Is there a way to make this??
You could playing around with the css position properties.
Hope it helps:
html
<main>
<section class="hero">
<div class="image-wrapper">
<img src="https://via.placeholder.com/450x150.png" alt="test image">
</div>
<div class="line-1"></div>
</section>
<section class="about">
<div class="content">
<h1>About us</h1>
<p>
Lorem ipsum dolor, sit amet consectetur adipisicing elit. Esse, sequi aspernatur inventore, ullam sapiente assumenda dignissimos dolorum voluptatibus nam est vel maxime cum quas. Blanditiis vel obcaecati voluptatibus qui alias.
</p>
</div>
<div class="line-2"></div>
</section>
</main>
and here is the css
:root{
--background-color: #ffffff;
--border: 2px solid green;
--border-radius: 8px;
--offset-left: 120px;
--offset-bottom: 30px;
}
main{
width: 90%;
max-width:1200px;
padding: 0 12px;
margin: 0 auto;
background-color: var(--background-color);
}
.hero{
position: relative;
}
.image-wrapper{
position: relative;
z-index:2;
}
.image-wrapper img{
width:100%;
height:auto;
}
.line-1{
position: absolute;
z-index:1;
width:calc(50% + var(--offset-left));
height:50%;
bottom: calc(var(--offset-bottom) * (-1));
left: calc(var(--offset-left) * (-1));
border-top: var(--border);
border-left: var(--border);
border-bottom: var(--border);
border-top-left-radius: var(--border-radius);
border-bottom-left-radius: var(--border-radius);
}
.about{
position: relative;
top: calc(var(--offset-bottom) / 2);
}
.content{
position: relative;
z-index:2;
text-align: center;
}
.content h1{
display: inline-block;
background-color: var(--background-color);
line-height:1;
padding: 0 10px;
font-size: 24px;
}
.content p{
text-align: left;
margin-top:30px;
}
.line-2{
position: absolute;
z-index:1;
width:calc(50% + var(--offset-left));
height:100%;
top: calc(var(--offset-bottom) / 2);
left: 50%;
border-top: var(--border);
border-right: var(--border);
border-top-right-radius: var(--border-radius);
}
Here is a working pen to play around.
Can someone please help me?!
I'm trying to code a PSD file to HTML and CSS, but I'm struggling with one of the sections. Here's an image of what I want to do:
Click Here
The problem is I don't know how to put the image in the timeline line. I tried to add the image in the ::after psuedo, but I don't think this is the right way of doing that.
This is my HTML Code :
<section class="about">
<div class="wrapper">
<h3>About Us</h3>
<p>Lorem ipsum dolor sit amet consectetur.</p>
<div class="container left">
<div class="content">
<h5>JULY 2010<br> Our Humble Beginnings</h5>
<p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Rerum officia labore fugit nihil nulla laboriosam praesentium harum ut, odio ea facere, recusandae reprehenderit repellat.</p>
</div>
</div>
<div class="container right">
<div class="content">
<h5>January 2011<br> Facing Startups Battles</h5>
<p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Rerum officia labore fugit nihil nulla laboriosam praesentium harum ut, odio ea facere, recusandae reprehenderit repellat.</p>
</div>
</div>
</div>
</section>
This is my CSS code:
.about .wrapper{
padding: 80px 10%;
text-align: center;
position: relative;
}
.about .wrapper::after{
content: '';
position: absolute;
top: 200px;
bottom: 0;
width: 6px;
background: red;
}
.about h5{
line-height: 1.5;
font-size: 1em;
padding-bottom: .5em;
}
.about .container{
position: relative;
width: 50%;
top: 60px;
margin: 0 0 60px 0;
}
.about .container::after{
content: 'How Can I Add an Image Here in this circle?';
position: absolute;
width: 200px;
height: 200px;
border-radius: 50%;
top: 20px;
right: -104px;
background-color: blue; /* Just because there is no image */
background-image: url(assets/img/about-1.png);
background-repeat: no-repeat;
background-size: cover;
z-index: 2;
}
.left{
text-align: right;
}
.right{
text-align: right;
}
.content{
padding: 30px 0px 80px 0px;
}
.left .content{
padding-right: 140px;
}
.right .content{
padding-left: 140px
}
.right{
text-align: left;
left: 50%;
}
.right:after {
left: -104px;
}
I think this is called a timeline, there is a lot of tutorials talking about how to do something like this, but I don't know how to make the images in the timeline line. Can you please help me do this?
Thanks
To build this, you could use css grid layout (guide: https://css-tricks.com/snippets/css/complete-guide-grid/)
Treat each of the content+image as a row in the layout. And each row as a container for a grid.
You can visually break every row down to 3 columns. One column for left-side content, the second one for the image and the third one for right-side content.
Example css grid for a layout like this:
.grid-container {
display: grid;
grid-template-columns: 1fr 10em 1fr;
grid-template-rows: 1fr;
grid-template-areas: "content-left image content-right";
text-align: center;
}
.content-left { grid-area: content-left; background: lightblue; }
.image { grid-area: image; background: lightgreen; }
.content-right { grid-area: content-right; background: lightblue; }
<div class="grid-container">
<div class="content-left">Left content</div>
<div class="image">Image</div>
<div class="content-right">Right content</div>
</div>
(grid generated with: https://grid.layoutit.com/)
To alternate between content on the left and on the right, you can use css even/odd selectors (How can I style even and odd elements?) to set which grid area is used for the element.
Example:
I've built an example of a timeline layout for this answer which you can find at https://codepen.io/hendrysadrak/pen/VwLEraz
Try this:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<link rel="stylesheet" type="text/css" href="main.css" />
<title></title>
</head>
<body>
<section class="about">
<div class="wrapper">
<div>
<h3>About Us</h3>
<p>Lorem ipsum dolor sit amet consectetur.</p>
</div>
<div id="container">
<div class="row">
<div id="col1" class="col right">
<h5>JULY 2010<br> Our Humble Beginnings</h5>
<p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Rerum officia labore fugit nihil nulla laboriosam praesentium harum ut, odio ea facere, recusandae reprehenderit repellat.</p>
</div>
<div id="col2" class="col"><img class="img" src="assets/img/about-1.png"/></div>
</div>
<div class="row2" >
<div id="col3" class="col"><img class="img" src="assets/img/about-1.png"/></div>
<div id="col4" class="col left">
<h5>JULY 2010<br> Our Humble Beginnings</h5>
<p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Rerum officia labore fugit nihil nulla laboriosam praesentium harum ut, odio ea facere, recusandae reprehenderit repellat.</p>
</div>
</div>
</div>
</div>
</section>
</body>
</html>
in main.css file:
.about .wrapper{
padding: 80px 10%;
text-align: center;
}
.about h5{
line-height: 1.5;
font-size: 1em;
padding-bottom: .5em;
}
.row {
width: 59%;
margin-right: 41%;
display: flex;
}
.row2 {
width: 59%;
display: flex;
margin-left: 41%;
}
.col {
flex:1;
}
.col.left {
text-align: left;
}
.col.right {
text-align: right;
}
#col2 {
flex-basis: 30%;
}
#col1 {
flex-basis: 70%;
}
#col3 {
flex-basis: 30%;
}
#col4 {
flex-basis: 70%;
}
.img {
margin: 10% 5%;
width: 90%;
border-radius: 50%;
}
#container {
background-image: linear-gradient(lightgrey,lightgrey);
background-size: 2px 100%;
background-repeat: no-repeat;
background-position: center center;
}
put this in assets/img/about-1.png
Used a css template and edited, now between the 3 columns there is a small margin gap which id like to get rid of. tried readjusting the columun sizes but the margin gap still exists. Is there a more simple way I could have achieved the same page, if so how?? Yes im a newbie :P
* {
box-sizing: border-box;
}
body {
margin: 0;
}
/* Style the header */
.header {
background-color: #F1C40F;
padding: 20px;
text-align: center;
}
/* Style the footer */
.footer {
background-color: #F1C40F;
padding: 10px;
text-align: center;
/* Create three unequal columns that floats next to each other */
.column {
float: left;
padding: 10px;
}
/* top, middle and bottom column */
.columntopmiddlebottom {
width: 30%;
}
/* Responsive layout - makes the three columns stack on top of each other
instead of next to each other */
#media screen and (max-width: 600px) {
.column.side,
.column.middle {
width: 100%;
}
}
.auto-style2 {
text-align: center;
}
}
.auto-style2 {
margin-top: 31px;
}
<div class="header">
<h1>Header</h1>
<p>Resize the browser window to see the responsive effect.</p>
</div>
<div class="row" style="height: 717px">
<div class="columntopmiddlebottom" style="background-color:#F7DC6F;
style=" height: 211px>
<h2>People</h2>
<p style="height: 214px">1</p>
</div>
<div class="columntopmiddlebottom" style="background-color:#F7DC6F;
style=" height: 212px>
<h2 style="height: 21px">2</h2>
<p style="height: 171px">info</p>
</div>
<div class="columntopmiddlebottom" style="background-color:#F7DC6F;
style=" height: 212px>
<h2 style="height: 37px">3</h2>
<p style="height: 193px">info</p>
</div>
</div>
Gaps under and above each column appears, dont want the gaps.
Try this:
.columntopmiddlebottom * {
margin-block-start: 0;
margin-block-end: 0;
}
A usefull trick when writing CSS is using the browsers development tools:
In Google when you right click on an element and press Inspect you can see which CSS is on that element. If you can't find the problem you are looking for you can try pressing CTRL + SHIFT + C and go over the elements to find your problem.
Good luck!
It is about https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Box_Model/Mastering_margin_collapsing
The top and bottom margins of blocks are sometimes combined (collapsed) into a single margin whose size is the largest of the individual margins (or just one of them, if they are equal), a behavior known as margin collapsing. Note that the margins of floating and absolutely positioned elements never collapse.
reset margin to hn and p .
* {
box-sizing: border-box;
}
h2,
p {
margin: 0;/* reset margin to avoid collapsing . Note , padding or border on the parent will keep margin inside*/
}
body {
margin: 0;
}
/* Style the header */
.header {
background-color: #F1C40F;
padding: 20px;
text-align: center;
}
/* Style the footer */
.footer {
background-color: #F1C40F;
padding: 10px;
text-align: center;
/* Create three unequal columns that floats next to each other */
.column {
float: left;
padding: 10px;
}
/* top, middle and bottom column */
.columntopmiddlebottom {
width: 30%;
}
/* Responsive layout - makes the three columns stack on top of each other
instead of next to each other */
#media screen and (max-width: 600px) {
.column.side,
.column.middle {
width: 100%;
}
}
.auto-style2 {
text-align: center;
}
}
.auto-style2 {
margin-top: 31px;
}
<div class="header">
<h1>Header</h1>
<p>Resize the browser window to see the responsive effect.</p>
</div>
<div class="row" style="height: 717px">
<div class="columntopmiddlebottom" style="background-color:#F7DC6F;
style=" height: 211px>
<h2>People</h2>
<p style="height: 214px">1</p>
</div>
<div class="columntopmiddlebottom" style="background-color:#F7DC6F;
style=" height: 212px>
<h2 style="height: 21px">2</h2>
<p style="height: 171px">info</p>
</div>
<div class="columntopmiddlebottom" style="background-color:#F7DC6F;
style=" height: 212px>
<h2 style="height: 37px">3</h2>
<p style="height: 193px">info</p>
</div>
</div>
you can use this package https://necolas.github.io/normalize.css/ in css to remove margin and padding for element
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
header {
background-color: #F1C40F;
height: 200px;
text-align: center;
padding: 50px 0;
}
.one {
background-color: #F7DC6F;
height: 200px;
text-align: center;
padding: 50px 0;
}
.two {
background-color: #F1C40F;
height: 200px;
text-align: center;
padding: 50px 0;
}
.three {
background-color: #F7DC6F;
height: 200px;
text-align: center;
padding: 50px 0;
}
.four {
background-color: #F1C40F;
height: 200px;
text-align: center;
padding: 50px 0;
}
footer{
background-color: #F7DC6F;
height: 200px;
text-align: center;
padding: 50px 0;
}
<header>
<h1>Header</h1>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Earum eum minus aliquam dolorum sit molestiae architecto.</p>
</header>
<section class="one">
<h2>Section One</h2>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Earum eum minus aliquam dolorum sit molestiae architecto.</p>
</section>
<div class="two">
<h2>Gallery</h2>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Earum eum minus aliquam dolorum sit molestiae architecto.</p>
</div>
<article class="three">
<h2>News</h2>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Earum eum minus aliquam dolorum sit molestiae architecto.</p>
</article>
<aside class="four">
<h2>Aside NavBar</h2>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Earum eum minus aliquam dolorum sit molestiae architecto.</p>
</aside>
<footer >
<h2>Aside NavBar</h2>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Earum eum minus aliquam dolorum sit molestiae architecto.</p>
</footer>
Another simple version using Flexbox.
* {
box-sizing: border-box;
margin: 0;
}
.header {
background-color: #F1C40F;
padding: 20px;
text-align: center;
}
.row {
background-color: #fff;
text-align: center;
display: flex;
flex-direction: row;
}
.column {
flex-grow: 1;
padding: 10px;
background-color:#F7DC6F;
height: 200px
}
#media screen and (max-width: 800px) {
.row {
flex-direction: column;
}
}
<div class="header">
<h1>Header</h1>
<p>Resize the browser window to see the responsive effect.</p>
</div>
<div class="row">
<div class="column">
<h2>People</h2>
<p>1</p>
</div>
<div class="column">
<h2>2</h2>
<p>info</p>
</div>
<div class="column">
<h2>3</h2>
<p>info</p>
</div>
</div>
I am keeping a circle inside a flex parent. the flex parent resize well. How can i resize the content inside the parent?
I tried to set the circle size by fluid, but fails too.
.parent {
display: flex;
justify-content: space-between;
border: 1px solid red;
align-items: center;
}
.child {
border-right: 1px solid gray;
width: 50%;
}
.last {
text-align: center;
}
.circle {
border: 1px solid gray;
border-radius: 50%;
width: 100px;
height: 100px;
display: inline-block;
margin: 0 auto;
}
/* my try but not works*/
/*
.circle{
border:1px solid gray;
border-radius:50%;
width:50%; not works!
height:50%; not works!
display:inline-block;
margin:0 auto;
}
*/
<div class="parent">
<div class="first child">
<p>Some text</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ad voluptate laborum at soluta maiores molestiae minus pariatur voluptas tempore illo, alias, atque deserunt, ex architecto necessitatibus vel nobis fugit consequuntur.</p>
</div>
<div class="child last">
<div class="circle"></div>
</div>
</div>
use this
.circle {
border: 1px solid gray;
border-radius: 50%;
width: 40%;
padding-bottom: 40%;
height:auto;
display: inline-block;
margin: 0 auto;
}
.parent {
display: flex;
justify-content: space-between;
border: 1px solid red;
align-items: center;
}
.child {
border-right: 1px solid gray;
width: 50%;
}
.last {
text-align: center;
}
.circle {
border: 1px solid gray;
border-radius: 50%;
width: 40%;
padding-bottom: 40%;
height:auto;
display: inline-block;
margin: 0 auto;
}
/* my try but not works*/
/*
.circle{
border:1px solid gray;
border-radius:50%;
width:50%; not works!
height:50%; not works!
display:inline-block;
margin:0 auto;
}
*/
<div class="parent">
<div class="first child">
<p>Some text</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ad voluptate laborum at soluta maiores molestiae minus pariatur voluptas tempore illo, alias, atque deserunt, ex architecto necessitatibus vel nobis fugit consequuntur.</p>
</div>
<div class="child last">
<div class="circle"></div>
</div>
</div>
I have three div
div.main = encloses two child div
div.head = uses about 10%~20% of div.main height
div.body = uses about 80%~90% of div.main height
I want div.body to fill the remaining height space left after allocating div.head's height.
I would like to do this with position: relative; as much as possible.
I am using percent values for the height and width and not pixels as screen resolutions may vary. I want it to resize itself automatically depending on the screen resolution of who may see it.
I noticed that if I use pixel values it works but not for percent.
In the following code I have created a main div with color red(just to divide it), and the 2 divs inside it, one head and one body with color yellow and green respectively.
I hope this is what you want -
<html>
<head>
<title>try</title>
<style type="text/css">
.main {
position: relative;
height:100%;
width:100%;
border:5px solid black;
background-color: red;
}
.head{
position: relative;
height:20%;
width:100%;
background-color: yellow;
}
.body{
position: relative;
height:80%;
width:100%;
background-color: green;
}
</style>
</head>
<body>
<div class="main"> //main div having height & width 100%
<div class="head"> //head with color yellow of 20%
</div>
<div class="body"> //head with color yellow of 80%
</div>
</div>
</body>
Position relative won't help you here..it doesn't size things by itself nor is it flexible as you seem to think.
I can think of a couple of way to do this (there may be others).
Table Display
* {
margin: 0;
padding: 0;
}
body {
text-align: center;
}
main {
height: 250px;
border:1px solid grey;
width: 250px;
display: inline-table;
/* usually just "table"...this is just to put the two tables side by side */
margin: 25px;
}
header {
display: table-row;
background: lightblue;
border-bottom:1px solid red;
}
.body {
display: table-row;
height: 100%;
background: lightgreen;
}
<main>
<header><p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Iusto, sed?</p>
</header>
<div class="body ">I'm the body</div>
</main>
<main>
<header><p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Similique porro sunt placeat incidunt, quo vero. Assumenda deserunt excepturi fugit incidunt?</p>
</header>
<div class="body ">I'm the body</div>
</main>
Flexbox
body {
text-align: center;
}
main {
height: 250px;
border:1px solid grey;
width: 250px;
display: inline-flex;
/* usually just "flex" ....this is to put the elements side by side */
flex-direction: column;
margin: 10px;
vertical-align: top;
}
header {
background: lightblue;
border-bottom:1px solid red;
}
.body {
flex:1;
background: lightgreen;
}
<main>
<header><p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Iusto, sed?</p>
</header>
<div class="body"></div>
</main>
<main>
<header><p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Similique porro sunt placeat incidunt, quo vero. Assumenda deserunt excepturi fugit incidunt?</p>
</header>
<div class="body "></div>
</main>