Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

HTML & CSS Css styling: how to have picture and text next to each other

Maja0802

Well-Known Coder
Hey there!

Hope you can help me (I am sure you can as usual! :))

I want to make a design identical to first screenshoot (the picture with the dog in) (Not the same font-family, though).

I made the design with the mountain. I don't know how to move the header and the paragraph up next to the picture. It is like display: inline-block is not working. at least no on the paragraph and for the header I cannot move it up using margin-top:

Thanks

[CODE lang="css" title="HTML and CSS"]<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>hey there</title>
<!--font 'Open Sans'-->
<link href="https://fonts.googleapis.com/css2?family=Open+Sans&display=swap" rel="stylesheet">
<!--font 'JetBrains Mono''
<link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono&display=swap" rel="stylesheet">-->
<link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono&display=swap" rel="stylesheet">

<script src="https://unpkg.com/typewriter-effect@latest/dist/core.js"></script>


<style>

h1 {
color: rgb(239, 61, 74);
line-height: 55px;
margin-left: 200px;
font-size: 40px;
line-height: 1.2;
margin-top: 0px;
margin-left:200px;
display: inline-block;
}

h1 span {
background-color: rgb(38, 102, 145);
display: inline;
font-family: "JetBrains Mono", Sans-serif;
text-align: right;
display: inline-block;
}

.header:hover {
color: rgb(50, 142, 168);
}

p {
font-family: "JetBrains Mono";
margin-right: 150px;
margin-left: 200px;
line-height: 1.5;
font-size: 17.5px;
display: inline-block;
}


img {
width: 500px;
height: 500px;
margin-left: 200px;
margin-top: 100px;
}

</style>

<!--Grundprincip !1-->

<img src="bjerg.jpg" alt="Girl in a jacket">

<h1> <span class ="header">OM OS</span></h1>

<p> <span><strong>Det indre panel af Røvhuller</strong> er en koncept hvor</span></p>

</head>

<body>
</body>

</script>

</html>
[/CODE]
 

Attachments

  • Skærmbillede 2021-01-07 kl. 21.02.30.png
    Skærmbillede 2021-01-07 kl. 21.02.30.png
    2.2 MB · Views: 5
  • Skærmbillede 2021-01-07 kl. 21.03.10.png
    Skærmbillede 2021-01-07 kl. 21.03.10.png
    1.6 MB · Views: 5
Hello!
You could put the header/text inside a div and give the img and the div a width of 50%, then place the <div> and the <img> side-by-side (By giving the CSS style 'display: flex;' to their common parent or something like that).
 
Thanks! Like this?

I struggle to get the text up next to the picture even though it is 50% width.

[CODE lang="css" title="css and HTML"]<style>

h1 {
color: rgb(239, 61, 74);
line-height: 55px;
margin-left: 200px;
font-size: 40px;
line-height: 1.2;
margin-top: 0px;
margin-left:200px;
display: inline-block;
}

h1 span {
background-color: rgb(38, 102, 145);
display: inline;
font-family: "JetBrains Mono", Sans-serif;
text-align: right;
display: inline-block;
}

.header:hover {
color: rgb(50, 142, 168);
}

p {
font-family: "JetBrains Mono";
margin-right: 150px;
margin-left: 200px;
line-height: 1.5;
font-size: 17.5px;
display: inline-block;
}


img {
width: 500px;
height: 500px;
margin-left: 200px;
margin-top: 100px;
}

div {
width: 50%;
}

div img {
display: flex;
}

</style>

<!--Grundprincip !1-->

<img src="bjerg.jpg" alt="Girl in a jacket">

<div><h1> <span class ="header">OM OS</span></h1>
<p> <span><strong>Det indre panel af Røvhuller</strong> er en koncept hvor<span class="cursor">_</span></span></p></div>


</head>[/CODE]
 
Thanks! Like this?

I struggle to get the text up next to the picture even though it is 50% width.

[CODE lang="css" title="css and HTML"]<style>

h1 {
color: rgb(239, 61, 74);
line-height: 55px;
margin-left: 200px;
font-size: 40px;
line-height: 1.2;
margin-top: 0px;
margin-left:200px;
display: inline-block;
}

h1 span {
background-color: rgb(38, 102, 145);
display: inline;
font-family: "JetBrains Mono", Sans-serif;
text-align: right;
display: inline-block;
}

.header:hover {
color: rgb(50, 142, 168);
}

p {
font-family: "JetBrains Mono";
margin-right: 150px;
margin-left: 200px;
line-height: 1.5;
font-size: 17.5px;
display: inline-block;
}


img {
width: 500px;
height: 500px;
margin-left: 200px;
margin-top: 100px;
}

div {
width: 50%;
}

div img {
display: flex;
}

</style>

<!--Grundprincip !1-->

<img src="bjerg.jpg" alt="Girl in a jacket">

<div><h1> <span class ="header">OM OS</span></h1>
<p> <span><strong>Det indre panel af Røvhuller</strong> er en koncept hvor<span class="cursor">_</span></span></p></div>


</head>[/CODE]
 

Attachments

  • Skærmbillede 2021-01-07 kl. 21.46.39.png
    Skærmbillede 2021-01-07 kl. 21.46.39.png
    1.6 MB · Views: 4
Hum, give the style display: flex; to the element 'head'.
Ahh the head tag! It is just further up on the page. I did apply the display: flex; and it worked. Great!
But when I make the img { width: 50%;, how do I adjust the size of the picture. I want it to be bigger...and is it necessary for the imp to be wrapped in id at all?


[CODE lang="css" title="css"]<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>hey there</title>
<!--font 'Open Sans'-->
<link href="https://fonts.googleapis.com/css2?family=Open+Sans&display=swap" rel="stylesheet">
<!--font 'JetBrains Mono''
<link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono&display=swap" rel="stylesheet">-->
<link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono&display=swap" rel="stylesheet">

<script src="https://unpkg.com/typewriter-effect@latest/dist/core.js"></script>


<style>

h1 {
color: rgb(239, 61, 74);
line-height: 55px;
margin-left: 200px;
font-size: 40px;
line-height: 1.2;
margin-top: 0px;
margin-left:200px;
display: inline-block;
}

h1 span {
background-color: rgb(38, 102, 145);
display: inline;
font-family: "JetBrains Mono", Sans-serif;
text-align: right;
display: inline-block;
}

.header:hover {
color: rgb(50, 142, 168);
}

p {
font-family: "JetBrains Mono";
margin-right: 150px;
margin-left: 200px;
line-height: 1.5;
font-size: 17.5px;
display: inline-block;
}


img {
width: 50%;
margin-top: 200px;
}

div {
width: 45%;
margin: auto;
display: flex;
}


</style>


<div><img src="bjerg.jpg" alt="Girl in a jacket">

<div>
<h1> <span class ="header">OM OS</span></h1>
<p> <span><strong>Det indre panel af Røvhuller</strong> er en koncept hvor<span class="cursor">_</span></span></p></div>
</div>



</head>

<body>

</body>

</html>
[/CODE]
 

Attachments

  • Skærmbillede 2021-01-07 kl. 22.10.14.png
    Skærmbillede 2021-01-07 kl. 22.10.14.png
    421.3 KB · Views: 3
And also the header is one the same line as the paragraph text...


[CODE lang="css" title="header on same line as text"]<head>
<style>

h1 {
color: rgb(239, 61, 74);
line-height: 55px;
font-size: 40px;
line-height: 1.2;
margin-top: 200px;


}

h1 span {
background-color: rgb(38, 102, 145);
font-family: "JetBrains Mono", Sans-serif;
text-align: right;
}

.header:hover {
color: rgb(50, 142, 168);
}

p {
font-family: "JetBrains Mono";
margin-right: 0px;
margin-left: 0px;
margin-top: 200px;
line-height: 1.5;
font-size: 17.5px;
}


img {
width: 50%;
margin-top: 200px;
}

div {
width: 45%;
margin: auto;
display: flex;
}

</style>

<div><img src="bjerg.jpg" alt="Girl in a jacket">

<div>
<h1> <span class ="header">OM OS</span></h1>
<p> <span><strong>Det indre panel af Røvhuller</strong> er en koncept hvor<span class="cursor">_</span></span></p></div>
</div>



</head>[/CODE]
 
And also the header is one the same line as the paragraph text...


[CODE lang="css" title="header on same line as text"]<head>
<style>

h1 {
color: rgb(239, 61, 74);
line-height: 55px;
font-size: 40px;
line-height: 1.2;
margin-top: 200px;


}

h1 span {
background-color: rgb(38, 102, 145);
font-family: "JetBrains Mono", Sans-serif;
text-align: right;
}

.header:hover {
color: rgb(50, 142, 168);
}

p {
font-family: "JetBrains Mono";
margin-right: 0px;
margin-left: 0px;
margin-top: 200px;
line-height: 1.5;
font-size: 17.5px;
}


img {
width: 50%;
margin-top: 200px;
}

div {
width: 45%;
margin: auto;
display: flex;
}

</style>

<div><img src="bjerg.jpg" alt="Girl in a jacket">

<div>
<h1> <span class ="header">OM OS</span></h1>
<p> <span><strong>Det indre panel af Røvhuller</strong> er en koncept hvor<span class="cursor">_</span></span></p></div>
</div>



</head>[/CODE]
 

Attachments

  • Skærmbillede 2021-01-07 kl. 22.21.32.png
    Skærmbillede 2021-01-07 kl. 22.21.32.png
    393.7 KB · Views: 1
Ahh the head tag! It is just further up on the page. I did apply the display: flex; and it worked. Great!
But when I make the img { width: 50%;, how do I adjust the size of the picture. I want it to be bigger...and is it necessary for the imp to be wrapped in id at all?


[CODE lang="css" title="css"]<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>hey there</title>
<!--font 'Open Sans'-->
<link href="https://fonts.googleapis.com/css2?family=Open+Sans&display=swap" rel="stylesheet">
<!--font 'JetBrains Mono''
<link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono&display=swap" rel="stylesheet">-->
<link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono&display=swap" rel="stylesheet">

<script src="https://unpkg.com/typewriter-effect@latest/dist/core.js"></script>


<style>

h1 {
color: rgb(239, 61, 74);
line-height: 55px;
margin-left: 200px;
font-size: 40px;
line-height: 1.2;
margin-top: 0px;
margin-left:200px;
display: inline-block;
}

h1 span {
background-color: rgb(38, 102, 145);
display: inline;
font-family: "JetBrains Mono", Sans-serif;
text-align: right;
display: inline-block;
}

.header:hover {
color: rgb(50, 142, 168);
}

p {
font-family: "JetBrains Mono";
margin-right: 150px;
margin-left: 200px;
line-height: 1.5;
font-size: 17.5px;
display: inline-block;
}


img {
width: 50%;
margin-top: 200px;
}

div {
width: 45%;
margin: auto;
display: flex;
}


</style>


<div><img src="bjerg.jpg" alt="Girl in a jacket">

<div>
<h1> <span class ="header">OM OS</span></h1>
<p> <span><strong>Det indre panel af Røvhuller</strong> er en koncept hvor<span class="cursor">_</span></span></p></div>
</div>



</head>

<body>

</body>

</html>
[/CODE]

Your <h1> and <p> and displayed side by side because you gave 'display: flex;' to all <div> elements.
 
What you could try; put the image and text within the same container and then in CSS set the image to float left or right depending on which side you want it to float to.


Note: all content that you want to be displayed e.g. <p>, <img> should be placed within your <body> tag.
 
What you could try; put the image and text within the same container and then in CSS set the image to float left or right depending on which side you want it to float to.
This may be a better solution if you do not know flex boxes.
 

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom