Image in circle above text div - html

I'm trying to place an image in a circle div that's placed above a section containing text like in the image shown:
How can this be done using CSS? Thank you.

Run the Code Here
https://www.w3schools.com/code/tryit.asp?filename=GHOLRSYI9PEK
.flex-wrapper{
background-color: lightgray;
padding: 30px;
padding: 30px 30px 30px 100px;
}
.flex-container {
display: flex;
background-color: #f1f1f1;
}
.flex-container > div {
margin: 10px;
padding: 10px;
font-size: 16px;
}
.flex-container{
-webkit-box-shadow: 0 0 10px 1px rgba(0,0,0,0.2);
-moz-box-shadow: 0 0 10px 1px rgba(0,0,0,0.2);
box-shadow: 0 0 10px 1px rgba(0,0,0,0.2);
}
.avatar-wrapper{
min-width: 150px;
position: relative;
margin-left: -50px !important;
margin: 10px;
padding: 10px;
font-size: 16px;
height: 150px;
display: flex;
align-items: center;
justify-content: center;
}
.avatar-wrapper:after{
content: '';
height: calc(100% + 40px);
width: calc(100% + 40px);
position: absolute;
background: purple;
top: -20px;
left: -20px;
border-radius: 50%;
z-index: 0;
}
.avatar-wrapper > img{
width: 150px;
height: 150px;
z-index: 1;
position: relative;
border-radius: 50%;
}
<div class="flex-wrapper">
<div class="flex-container">
<div class="col avatar-wrapper">
<img src="https://via.placeholder.com/200" alt="sample">
</div>
<div class="col text">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur</div>
</div>
</div>

img{ border-radius:50%; z-index:1 }
.container{
z-index:0;
margin-left:-100px;
box-shadow: 0px 0px 10px 1px lightgrey;
padding:5px;
width:50%;
}
.text{
text-decoration:underline blue;
margin-left:100px;
}
<div style="display:flex;">
<img src="https://via.placeholder.com/250">
<div class="container">
<div class="text">
I'm trying to place an image in a circle div that's placed above a section containing text like in the image shown:
</div>
</div>
</div>
Here is your solution. Just add your Image url in img tag

Related

Child div with negative left margin not allowing parent div to center

I have the following div created, but because I'm using negative left margin to offset the icon, I can't center the entire div. We can get away with it on desktop since you can't really tell too easily that the whole div is shifted to the left a bit, but on mobile, the left side of the round icon gets cut off. How can I center the entire div?
.icon-text-box {
border: 1px solid red;
}
.icon-box {
background: #fff;
border-radius: 33px;
margin: 6rem auto;
padding: 4rem 4rem 4rem 7rem;
box-shadow: 0 3px 6px -2px rgb(0 0 0 / 20%), 0 6px 12px rgb(0 0 0 / 10%);
position: relative;
display: flex;
align-self: center;
max-width: 900px;
}
.icon-box p {
font-size: 22px;
margin-bottom: 0;
}
.icon-box-icon {
position: absolute;
left: -90px;
overflow: hidden;
display: flex;
align-self: center;
height: 177px;
}
.icon-box-icon img {
border-radius: 40px;
}
<div class="container-fluid mw-972 icon-text-box">
<div class="icon-box">
<div class="icon-box-icon">
<img src="https://www.freepnglogos.com/uploads/spotify-logo-png/spotify-simple-green-logo-icon-24.png" />
</div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
</div>
</div>
Instead of auto margin you can use a different idea to center and at the same time add some margin on small screen
margin: 6rem max(90px,(100% - 900px)/2);
Full code:
.icon-text-box {
border: 1px solid red;
}
.icon-box {
background: #fff;
border-radius: 33px;
margin: 6rem max(90px,(100% - 900px)/2);
padding: 4rem 4rem 4rem 7rem;
box-shadow: 0 3px 6px -2px rgb(0 0 0 / 20%), 0 6px 12px rgb(0 0 0 / 10%);
position: relative;
display: flex;
}
.icon-box p {
font-size: 22px;
margin-bottom: 0;
}
.icon-box-icon {
position: absolute;
left: -90px;
top: 50%;
transform: translateY(-50%);
overflow: hidden;
display: flex;
height: 177px;
}
.icon-box-icon img {
border-radius: 40px;
}
<div class="container-fluid mw-972 icon-text-box">
<div class="icon-box">
<div class="icon-box-icon">
<img src="https://www.freepnglogos.com/uploads/spotify-logo-png/spotify-simple-green-logo-icon-24.png" />
</div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
</div>
</div>
Also like below if you want margin on one side:
.icon-text-box {
border: 1px solid red;
}
.icon-box {
background: #fff;
border-radius: 33px;
margin: 6rem max(0px,(100% - 900px)/2) 6rem max(90px,(100% - 900px)/2);
padding: 4rem 4rem 4rem 7rem;
box-shadow: 0 3px 6px -2px rgb(0 0 0 / 20%), 0 6px 12px rgb(0 0 0 / 10%);
position: relative;
display: flex;
}
.icon-box p {
font-size: 22px;
margin-bottom: 0;
}
.icon-box-icon {
position: absolute;
left: -90px;
top: 50%;
transform: translateY(-50%);
overflow: hidden;
display: flex;
height: 177px;
}
.icon-box-icon img {
border-radius: 40px;
}
<div class="container-fluid mw-972 icon-text-box">
<div class="icon-box">
<div class="icon-box-icon">
<img src="https://www.freepnglogos.com/uploads/spotify-logo-png/spotify-simple-green-logo-icon-24.png" />
</div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
</div>
</div>

Give different card element specific width size

I am using css grid where I have a card inside a sidebar div that is inside a container dive. I am also using a inner-container div where I put 3 cards. The sidebar div card has proper width but the cards inside the inner-container do not adjust to 200px. How can I give the inner-container cards a specific width.
HTML
<aside class="sidebar">
<h2><b>Latest Blog Post</b></h2>
<div class="card">
<img class="card-image" src="images/christmas.jpeg" alt="christmas-markets" width="100%">
<div class="card-text">
<p>German Christmas Markets</p>
</div>
</div>
</aside>
<article class="main">
<h1>An American Living in Germany</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. </p>
<div class=".inner-container">
<div class="card"><img class="card-image" src="images/pubic-transit.jpeg" alt="public-transit" width="100%">
<div class="card-text">
<p>Public Transit</p>
</div></div>
<div class="card"><img class="card-image" src="images/rothenburg.jpeg" alt="christmas-markets" width="100%">
<div class="card-text">
<p>Rothenburg ob der Tauber</p>
</div></div>
<div class="card"><img class="card-image" src="images/black-forest.jpeg" alt="public-transit" width="100%">
<div class="card-text">
<p>The Black Forest</p>
</div></div>
</div>
</article>
CSS
.card {
box-shadow: 0 8px 8px 8px rgba(0,0,0,0.2);
transition: 0.3s;
width: 90%;
height: auto;
border-radius: 5px;
margin-top: 20px;
}
.card-text {
padding: 2px;
margin-left: 5px;
margin-bottom: 2px;
margin-top: 5px;
line-height: .5em;
}
.card-text a {
color: crimson;
font-size: 1.2em;
}
.card-image {
width: 100%;
bottom: 0px;
}
.inner-container {
height: 50%;
width: 80%;
display: grid;
grid-template-columns: 200px 200px 200px;
grid-template-rows: 200px 200px 200px;
grid-template-areas:
"b b b";
}
.inner-container div {
grid-area: b;
}
.inner-container .card{
box-shadow: 0 8px 8px 8px rgba(0,0,0,0.2);
transition: 0.3s;
width: 200px;
height: auto;
border-radius: 5px;
margin-top: 20px;
}
.inner-container .card-text {
padding: 2px;
margin-left: 5px;
margin-bottom: 2px;
margin-top: 5px;
line-height: .5em;
}
.inner-container .card-text a {
color: crimson;
font-size: 1.2em;
}
.inner-container .card-image {
width: 100%;
bottom: 0px;
}
You've got a typo in your code which is why CSS isn't firing for that class.
<div class=".inner-container">
should be
<div class="inner-container">
Also took the liberty of adding grid-area:auto; to css to make it render properly for you:
Working fiddle: https://jsfiddle.net/ne6vrwyq/
.card {
box-shadow: 0 8px 8px 8px rgba(0,0,0,0.2);
transition: 0.3s;
width: 90%;
height: auto;
border-radius: 5px;
margin-top: 20px;
}
.card-text {
padding: 2px;
margin-left: 5px;
margin-bottom: 2px;
margin-top: 5px;
line-height: .5em;
}
.card-text a {
color: crimson;
font-size: 1.2em;
}
.card-image {
width: 100%;
bottom: 0px;
}
.inner-container {
height: 50%;
width: 80%;
display: grid;
grid-template-columns: 200px 200px 200px;
grid-template-rows: 200px 200px 200px;
grid-template-areas:
"b b b";
}
.inner-container div {
grid-area: b;
}
.inner-container .card{
box-shadow: 0 8px 8px 8px rgba(0,0,0,0.2);
transition: 0.3s;
width: 200px;
height: auto;
border-radius: 5px;
margin-top: 20px;
grid-area: auto;
}
.inner-container .card-text {
padding: 2px;
margin-left: 5px;
margin-bottom: 2px;
margin-top: 5px;
line-height: .5em;
}
.inner-container .card-text a {
color: crimson;
font-size: 1.2em;
}
.inner-container .card-image {
width: 100%;
bottom: 0px;
}
<aside class="sidebar">
<h2><b>Latest Blog Post</b></h2>
<div class="card">
<img class="card-image" src="images/christmas.jpeg" alt="christmas-markets" width="100%">
<div class="card-text">
<p>German Christmas Markets</p>
</div>
</div>
</aside>
<article class="main">
<h1>An American Living in Germany</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. </p>
<div class="inner-container">
<div class="card"><img class="card-image" src="images/pubic-transit.jpeg" alt="public-transit" width="100%">
<div class="card-text">
<p>Public Transit</p>
</div></div>
<div class="card"><img class="card-image" src="images/rothenburg.jpeg" alt="christmas-markets" width="100%">
<div class="card-text">
<p>Rothenburg ob der Tauber</p>
</div></div>
<div class="card"><img class="card-image" src="images/black-forest.jpeg" alt="public-transit" width="100%">
<div class="card-text">
<p>The Black Forest</p>
</div></div>
</div>
</article>

flexbox parent is having trouble with children elements

the parent div, .blog_content, has two childern, one is a p element and the other is an image. for some reason they are behaving like block objects and not inline block. what is happenning is they are appearing on top of each other, like block elements would and not beside each other like what im trying to accomplish. i have set widths for them but they seem to be just ignoring them.
ill post the code below.
the relevant html
edit to show the full code
<!doctype html>
<html>
<head>
<title>My blog</title>
<link rel="stylesheet" href="styles/style.css">
</head>
<body>
<nav>
<div id="nav_links">
Home
all posts
Services
About
Contact
</div>
<div id="nav_search">
<form method="post" action="#">
<input id="nav_form_input" type="text" name="nav_search" placeholder="Search">
<input id="nav_search_submit" type="submit" value="GO">
</form>
</div>
</nav>
<main>
<section>
<article>
<h1>My first blog post</h1>
<hr>
<div class="blog_content">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborumLorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. </p>
<img src="images/159.jpg" alt="shit hot 159">
</div>
</article>
</section>
<aside>
</aside>
</main>
</body>
</html>
the relevant css
/* -------------------------------------------------------------------------------------------------------------------------------------*/
/* START OF HEADER.HTML STYLES */
/* -------------------------------------------------------------------------------------------------------------------------------------*/
nav {
position: relative;
height: 40px;
width: 100%;
background-color: rgb(40,50,60);
}
#nav_links {
position: relative;
float: left;
padding-left: 40px;
height: 40px;
display: flex;
flex-flow: row nowrap;
justify-content: flex-start;
align-items: center;
}
#nav_search {
position: relative;
float: right;
padding-right: 80px;
height: 40px;
display: flex;
flex-flow: row nowrap;
justify-content: flex-end;
align-items: center;
}
nav > #nav_links > a {
text-decoration: none;
font-family: arial;
font-size: 12px;
color: rgb(220,220,220);
padding-left: 25px;
text-shadow: 0px 0px 1px grey;
letter-spacing: 1px;
}
#nav_form_input{
border-radius: 10px 0px 0px 10px;
height: 20px;
border: none;
outline: none;
color: rgb(220,220,220);
background-color: rgb(60,70,80);
padding: 5px;
}
#nav_search_submit {
border-radius: 5px;
height: 30px;
border: 1px solid rgb(60,110,30);
background: linear-gradient(rgb(100,160,80), rgb(90,140,60));
font-family: arial;
font-weight: bold;
color: rgb(240,240,240);
}
/* -------------------------------------------------------------------------------------------------------------------------------------*/
/* START OF MAIN.HTML STYLES */
/* -------------------------------------------------------------------------------------------------------------------------------------*/
main {
position: relative;
margin: 0 auto;
display: flex;
flex-flow: nowrap ;
width: 100%;
min-height: 600px;
flex-flow: row nowrap;
justify-content: space-around;
align-items: flex-start;
}
main section {
margin: 20px auto;
width: 65%;
min-height: 400px;
}
main section article {
border-radius: 30px 30px 0px 0px;
background-color: rgb(240,240,240);
height: 400px;
}
main section article h1 {
margin: 0 auto;
padding: 10px 0px 10px 20px;
border-radius: 30px 20px 0px 0px;
border: 2px 2px 0px 2px solid rgb(0,0,255);
color: white;
letter-spacing: 1px;
background: linear-gradient(rgb(80,170,240), rgb(60,140,240));
font-weight: 400;
}
hr {
width: 95%;
color: rgb(120,120,120);
}
.blog_content {
display: inline-flex;
flex-flow: row nowrap;
justify-content: space-between;
width: 100%;
}
main section article p {
overflow: hidden;
text-overflow: ellipsis;
white-space: wrap;
width: 42%;
}
main section article img {
margin: 3%;
width: 42%;
border-radius: 4px;
}
main aside {
margin: 20px auto;
width: 20%;
min-height: 400px;
border: 1px solid black;
}
i have tried using both flex and inline-flex but no joy with either

CSS3 Speechbubble with image

Hi i'm trying to make a responsive speech bubble with an image on top from the examples of Nicolas Gallagher http://nicolasgallagher.com/pure-css-speech-bubbles/demo/.
But getting problems with the responsive part because i have changed the pinched part in the speechbubble to be in the bottom-left part of the bubble/text box.
.pinched > :first-child:before {
content: "";
position: absolute;
bottom: -20px;
right: 0;
width: 70%;
height: 20px;
background:#fff;
/* css3 */
-webkit-border-top-left-radius:15px;
-moz-border-radius-topleft:15px;
border-top-left-radius:15px;
}
I have made an example here:
https://jsfiddle.net/g5k07rL9/
But the example isn't responsive and the pinch not sharp/pointy in the edge.
How do i get the pinch in the left side without getting these bugs?
speechbubble re-sizing window
speechbubble mobile window
Here is the curvy pinched tip css bubble.
* {font-family: arial;}
.bubble {
padding: 1.5em;
background: #CCC;
border: 2px solid #999;
border-radius: 1em;
width: 60%
}
.bubble:after {
top: 42px;
left: 10px;
position: relative;
font-size: 50px;
line-height: 0;
color: #ccc;
}
.circle {
border-radius: 50%;
background: #ccc;
width: 70px;
height: 70px;
position: relative;
left: 15px;
border: 2px solid #999;
}
.pinch {
background: #999;
height: 15px;
width: 100px;
}
.pinch span {
background: #FFF;
display: inline-block;
width: 50px;
height: 15px;
}
.lft {border-top-right-radius: 15px}
.rgt {border-top-left-radius: 15px;}
<div class="bubble">
<div>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</div>
</div>
<div class="pinch"><span class="lft"></span><span class="rgt"></span> </div>
<div class="circle">
</div>
Preview at : https://jsfiddle.net/itsselvam/fuxm42sj/

The color of the div is outside the margin

I set the width of my page on 970px.
Everything is going well, even the paragraph is aligned within the margin but when I apply the color, it is outside the margin.
<div class="container">
<header>
<nav class="navbar navbar-default navegacion">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
<span class="sr-only">Cambiar NavegaciĆ³n</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<strong>Amixer Music</strong>
</div>
<div class="collapse navbar-collapse navbar-ex1-collapse">
<ul class="nav navbar-nav textomenu">
<li>Inicio</li>
<li>Traductor Amixer</li>
<li>Yahoo Fail</li>
</ul>
</div>
</nav>
</header>
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
<img class="img-responsive" src="img/amixermusic2.png" alt="AmixerMusic"/>
</div>
</div>
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 alineado">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</div>
</div>
</div>
// Not stuff like this which is a code comment :-)
html,
button,
input,
select,
textarea {
color: #222;
}
body {
font-size: 16px;
height: 100%;
}
::-moz-selection {
background: #b3d4fc;
text-shadow: none;
}
::selection {
background: #b3d4fc;
text-shadow: none;
}
hr {
display: block;
height: 1px;
border: 0;
border-top: 1px solid #ccc;
margin: 1em 0;
padding: 0;
}
img {
vertical-align: middle;
}
fieldset {
border: 0;
margin: 0;
padding: 0;
}
textarea {
resize: vertical;
}
.chromeframe {
margin: 0.2em 0;
background: #ccc;
color: #000;
padding: 0.2em 0;
}
/*My personal css*/
/* Custom container */
.container{
padding: 0px;
max-width: 970px;
margin-top: 2%;
border: 5px solid #2E2E2E;
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
border-radius: 10px;
-webkit-box-shadow: 0 1px 2px rgba(0,0,0,.05);
-moz-box-shadow: 0 1px 2px rgba(0,0,0,.05);
box-shadow: 0 1px 2px rgba(0,0,0,.05);
}
.imagen
{
width: 100%;
}
.navegacion
{
width: 100%;
margin-bottom: 0%;
}
.texto
{
font-family: 'Nunito', serif;
font-size: 25px;
text-shadow: 4px 4px 4px #aaa;
}
.textomenu
{
font-family: 'Nunito', serif;
font-size: 20px;
}
.alineado
{
background-color: orange;
margin-right: 0%;
margin-left: 0%;
}
.color2
{
background-color: blue;
}
It's because bootstrap auto add -15px to left and right margin of .row:
.row {
margin-left: -15px;
margin-right: -15px;
}
Try to reset it and you should be fine:
.row {
margin: 0
}
Demo