SVG img inline with a multi line text "block" - html

My question is principally similar to this one: SVG img on the same line of text in inline-block container
I have a SVG image, which I want to build into the text, which "displaces" the text from the left side. The text is at least two lines long and it's a <h1> if it matters.
What I've tried to far:
Set the height and/or width just like in that question
Wrapping it in a paragraph (<p>)
Wrapping it in a div with a specified width and/or height
According to https://stackoverflow.com/a/64892423 I tried to add justify-self: start; - has no effect as well...
How do I solve this primitive problem? Help is appreciated.
<div class=company-content>
<p>
<div style="width:10%; height:10%; display:inline-grid;">
<img src="graphics/filenamehere.svg" style=" display:inline-flex; height:3rem;" />
</div>
<h1>Lorem Ipsum Text here</h1>
</p>
UPDATE
Minimal reproducable example:
/* Add a random picture */
var img = document.createElement('img');
img.src = 'https://unsplash.it/200/300/?random';
document.body.appendChild(img);
/* Add some lorem ipsum text next to the picture */
var lorem = document.createElement('div');
lorem.innerHTML = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam euismod, nunc eget euismod tincidunt, nunc nisi tincidunt augue, nec consectetur nunc nisi eu nunc. Nullam eget nunc eu nisl sagittis porttitor. Nullam euismod, nunc eget euismod tincidunt, nunc nisi tincidunt augue, nec consectetur nunc nisi eu nunc. Nullam eget nunc eu nisl sagittis porttitor.';
document.body.appendChild(lorem);
/* Make the picture sit on the left side of the text inline with the text */
img.style.float = 'left';
/* Make the text a h1 header */
lorem.style.fontSize = '1.5em';
lorem.style.fontWeight = 'bold';
This works, but not in my code, which uses a h1 tag...
UPDATE 2
My not properly working code:
.company-content {
width: 79%;
display: inline-grid;
/*margin-left: 75px;*/
}
<div class=company-content>
<p>
<div style="width:10%; height:10%; display:inline-grid; float:left;"><img src="https://picsum.photos/500" style=" display:flex; width:3rem; height:3rem; align-items:center; float:left;" /> </div>Lorem Ipsum blablabla bla bla bla bla</p>

Use this code for image and text same line for your requirement.
<div class=company-content>
<p>
<div style="width:60%; height:10%; display:flex; align-items: center; justify-content: center;
margin: 0 auto;">
<img src="graphics/filenamehere.svg" />
<h1 style="margin: 0;">Lorem Ipsum Text here</h1>
</div>
</p>
</div>

Related

How can I pin HTML buttons to the bottom of their cards? [duplicate]

This question already has answers here:
How can I position my div at the bottom of its container?
(25 answers)
Closed 16 days ago.
I am trying to make a listing website. I am using the Jekyll Moonwalk theme as a base and heavily adapting it to my needs.
This is my first website project, so I am figuring it out as I go. Right now, I am trying to make my HTML button elements "pin" to the bottom of their container, instead of being at the bottom of the text, so they all are in line. Right now it looks like this:
Image
The red line is roughly where I want the bottom of all the buttons to me.
I have tried ChatGPT's suggestion, but it didn't work.
<div style="position: relative;">
<button style="position: absolute; bottom: 0;">Click Me</button>
</div>
You can use display flex for the boxes to arrange them like this, justify the content using space-between will always keep the buttons at the end.
here box is your card
.box{
display: flex;
flex-direction: column;
justify-content: space-between;
width: 280px;
height: 320px;
border: 1px solid #000000;
}
<div class="box">
<div class="head">
<!--header content-->
<h1> hello</h1>
</div>
<div class="body">
<!--bodycontent-->
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec facilisis libero nec nunc consectetur, non euismod ex vestibulum. Aliquam porttitor egestas sem.
</p>
</div>
<div class"bottom">
<!--button-->
<button> Tell me more</button>
</div>
</div>
style parent div of button position:relative
syle button position: absolute; bottom:0
.container{
display:flex;
}
.box{
position:relative;
outline: 1px solid black;
height: 300px;
margin:5px;
padding:5px;
display:flex;
flex-direction: column;
align-items: center;
}
button{
position:absolute;
bottom: 10px
}
<div class="container">
<div class="box">
<div class="head">
<!--header content-->
<h1> hello</h1>
</div>
<div class="body">
<!--bodycontent-->
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec facilisis
libero nec nunc consectetur, non euismod ex vestibulum. Aliquam porttitor
egestas sem.
</p>
</div>
<div class"bottom">
<!--button-->
<button> Tell me more</button>
</div>
</div>
<div class="box">
<div class="head">
<!--header content-->
<h1> hello</h1>
</div>
<div class="body">
<!--bodycontent-->
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec facilisis
libero nec nunc consectetur, non euismod ex vestibulum. Aliquam porttitor
egestas sem.
</p>
</div>
<!--button-->
<button> Tell me more</button>
</div>
</div>

Apply css only on the wrapped part of text

I have an HTML component that has an image floating to the left and text on the right. When the text's height is larger than the image, the text will wrap to the left. I want to add some padding between the image and the wrapped text. I could add a bottom padding to the image, but I don't want the padding to show up when the text is not wrapped. Here is what the component should look like when the text is no wrapped. The image should not have a bottom padding:
Here is what it should look like when the text is wrapped. There should be some padding between the image and the wrapped text:
Is there a way to do this through css?
An idea in case the image height is fixed or known:
.container {
border:2px solid;
min-height:200px; /* same as image height */
font-size:19px;
}
.container img {
float:left;
margin:0 20px 20px 0;
}
<div class="container">
<img src="https://picsum.photos/id/1014/200/200" > Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque fermentum quis mi vitae molestie. Sed scelerisque fringilla interdum. Duis ac purus nisl. Nulla vehicula vehicula turpis id convallis. Etiam nec nisl nibh. Mauris lorem mauris, vehicula nec massa in, accumsan egestas eros. Integer vehicula nulla sed enim laoreet maximus. Vestibulum at interdum sem. Sed interdum volutpat massa,
</div>
Yes, you can do it. Follow this example for HTML and css.
body {
margin: 20px;
text-align: center;
}
img {
float: left;
margin: 0px 10px 5px 10px;
}
p {
text-align: justify;
font-size: 20px;
}
<!DOCTYPE html>
<html>
<head>
<title>
Wraping an Image with the text
</title>
</head>
<body>
<div class="square">
<div>
<img src= "https://upload.wikimedia.org/wikipedia/commons/thumb/b/b6/Image_created_with_a_mobile_phone.png/1024px-Image_created_with_a_mobile_phone.png" alt="Longtail boat in Thailand" width="300px">
</div>
<p>
How many times were you frustrated while looking
out for a good collection of programming/algorithm
/interview questions? What did you expect and what
did you get? This portal has been created to
provide well written, well thought and well
explained solutions for selected questions.
An IIT Roorkee alumnus and founder of GeeksforGeeks.
He loves to solve programming problems in most
efficient ways. Apart from GeeksforGeeks, he has
worked with DE Shaw and Co. as a software developer
and JIIT Noida as an assistant professor. It is a
good platform to learn programming. It is an
educational website. Prepare for the Recruitment
drive of product based companies like Microsoft,
Amazon, Adobe etc with a free online placement
preparation course.
</p>
</div>
</body>
</html>

Can’t get the text to appear below the Image

I am trying to make the text appear below the image but it is not budging at all. My goal is it make the text appear below the image in the container
.left-col p {
text-align: justify;
width: 300px;
}
.left-col img {
margin: 0 auto;
left: 5%;
width: 300px;
height: 130px;
position: absolute;
text-align: center;
}
</head>
<body>
<div class="header">
<h1>The 3 Column Layout</h1>
</div>
<div class="container">
<div class="left-col">
<img src="Cyber.jpg" width="200" height=150"/>
<p>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec iaculis neque nec luctus maximus. Donec eu eleifend libero, nec scelerisque metus. Morbi volutpat turpis pretium
</p>
Instead of using position absolute, remove it. Reason is that the element is positioned relative to its first positioned (not static) ancestor element. So, you could of course mess with top, right and left values to make it work but it would not be responsive at all.
Read more about it here: MDN Position CSS
The default value of position is static, this way the elements renders in a specific order(its what you want, render img and p after).
This is the pen if you need:
<div class="header">
<h1>The 3 Column Layout</h1>
</div>
<div class="container">
<div class="left-col">
<img src="https://via.placeholder.com/200x150" width="200" height="150" />
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec iaculis neque nec luctus maximus. Donec eu eleifend libero, nec scelerisque metus. Morbi volutpat turpis pretium </p>
</div>
</div>
.left-col p{
text-align: justify;
width:300px;
}
.left-col img{
width:300px;
height: 130px;
}
Also, instead of setting width 300px to paragraph and img, you could set only one time to your .left-col div. I have also removed other properties that you were not using.
another note is that you forgot the " on height attribute.
In css there is use [ position absolute ] For the image and is not used in the text You must set the position in the image and the text or leave it to the default setting I deleted it from the image properties in css
.left-col p{
text-align: justify;
width:300px;
}
.left-col img{
margin: 0 auto;
left: 5%;
width:300px;
height: 130px;
text-align:center;
}
<body>
<div class="header">
<h1>The 3 Column Layout</h1>
</div>
<div class="container">
<div class="left-col">
<img src="Cyber.jpg" width="200" height=150"/>
<p><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec iaculis neque nec luctus maximus. Donec eu eleifend libero, nec scelerisque metus. Morbi volutpat turpis pretium </p>
</body>
Remove the line 'position: absolute;' from CSS. Complete (close) the DIV and P tags. You may introduce '.container{...}' where you may position (or whatever) the image-and-text together. You may wish to use 'margin: 0;' to glue the text to the image. Good luck!

How to display a <p> within a <div>element with the display property of inline-block?

This is what I am currently working on...
.scake_one {
color: #cc3300;
display: inline-block;
}
.scake_two {
color: #cc3300;
display: inline-block;
}
.scake_three {
color: #cc3300;
display: inline-block;
}
<div class="scake_one">
<h1>CAKE ONE</h1>
<p>Lorem ipsum etiam porttitor ultrices
<br>tortor tempus vehicula.</p>
</div>
<div class="scake_two">
<h1>CAKE TWO</h1>
<p>Lorem ipsum eu quisque velit
<br>quam convallis massa tellus.</p>
</div>
<div class="scake_three">
<h1>CAKE THREE</h1>
<p>Lorem ipsum sed mauris aenean
<br>pretium pulvinar.</p>
</div>
I was able to use this property well with an other section that had < h1 > and < li > elements. I was able to used inline-block because they are block level elements? I saw this info on the w3 site
http://www.w3schools.com/htmL/html_blocks.aspI also saw that < div > tags are also block level elements. I can't seem to understand why it isn't working.
Here you go! You need float-left, and the width needs to tell it to take up a third of the screen.
Also, just as a style thing, you can give all of your "scake" the same class name, because the CSS styling is the same for each one. Then if you change the style on one, it'll update it for all of them.
.scake {
color: #cc3300;
display: inline-block;
float: left;
max-width: 32%;
margin-left: .5%;
margin-right: .5%;
}
<div class="scake">
<h1>CAKE ONE</h1>
<p>Lorem ipsum etiam porttitor ultrices
<br>tortor tempus vehicula.</p>
</div>
<div class="scake">
<h1>CAKE TWO</h1>
<p>Lorem ipsum eu quisque velit
<br>quam convallis massa tellus.</p>
</div>
<div class="scake">
<h1>CAKE THREE</h1>
<p>Lorem ipsum sed mauris aenean
<br>pretium pulvinar.</p>
</div>

Trying to vertically align two columns in zurb foundation

I'm using Zurb Foundation with Sass Compass, but this could a problem for anything in css.
So, I have code like this
<div class="row">
<div class="small-6 column">...</div>
<div class="small-6 column">...</div>
</div>
The columns have content of differing height determined by how much text and images I want to put in there. The row has no explicit height and determined by the height of the tallest column. Now the tallest column will be shown as is, but the other one which is shorter, I'd like it's content to be centered vertically. I have looked around for this and I've tried using display: table and relative positioning, but none of them offers what I need.
Wrap the vertical aligned text in a div with the same height as its parent and display:table-cell it (after displaying its parent as a table):
HTML
<div class="row">
<div class="small-6 column">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam et iaculis justo. Mauris bibendum convallis est, vel blandit quam tempor aliquet. Cras euismod nibh et nisl congue, eget tincidunt mauris consectetur. Donec eu risus lectus. Integer at ipsum sed turpis fringilla adipiscing vitae vel enim.</div>
<div class="small-6 column"><div class="v_align">Some text</div></div>
<div class="clear"></div>
</div>
<div style="width:200px; height:100px; background:#0f0; color:#fff;">dfbvd bdfhgf hfg hghf gfdh hfgghfd hgf</div>
CSS
.row{
width:300px;
height:auto;
}
.clear{clear:both;}
.column:first-child{
color:#f00;
background:#ccc;
}
.column:nth-child(2){
background:#999;
color:#00f;
display:table;
}
.column{
width:150px;
float:left;
}
.v_align{
display:table-cell;
vertical-align:middle;
}
JS
$(document).ready(function(){
var rowHeight = $(".row").height();
console.log(rowHeight);
$(".column").height(rowHeight);
$(".v_align").height(rowHeight);
});
Check the result: http://jsfiddle.net/gespinha/h6aPf/6/