0

I'm a newbie in HTML CSS. I need to create view sample photo: enter image description here

I used code:

<!DOCTYPE html>
<html>
<head>
<style> 
attachment{
border-radius:10px;
padding:8px;
display:block;
background:#dadada;
}
attachment::before{
content:"</>";
}
</style>
</head>
<body>
<attachment id="7ffdba46c1b64aba89b5176469c2bd5b">Code snippet </br> Text, 12 lines</attachment>
</body>
</html>

But my result is: enter image description here

How I can move </> to center vertical and all content in attachment tag will alight left </> same photo? Thank you very much!

4 Answers 4

1

Try this:

<!DOCTYPE html>
<html>
<head>
<style> 

attachment{
border-radius: 10px;
padding: 20px;
display: flex;        /* Newly added */
background: #dadada;
align-items: center; /* Newly added */
line-height:2;      /* Newly added */
}
attachment::before{
content:"</>";
padding: 20px;     /* Newly added */
}

</style>
</head>
<body>
<attachment id="7ffdba46c1b64aba89b5176469c2bd5b">
Code snippet </br> Text, 12 lines
</attachment>
</body>
</html>
Sign up to request clarification or add additional context in comments.

2 Comments

thank you, but why background:#dadada; not working?
that is due to " // Newly added " sorry i wrongly commented the line. now i updated to " /* Newly added */ "
0

Try:

<body>
<div>
<table>
<tr style="margin-top: 50%; margin=left: 50%;">
<td>
<attachment id="7ffdba46c1b64aba89b5176469c2bd5b">
</td>
<td>
Code snippet </br> Text, 12 lines</attachment>
</td>
</tr>
</table>
</div>
</body>

hope it works!

1 Comment

thank you, but I can't change html, I need change css.
0

To move the </> to center vertical, use the following style rules:

attachment::before {
  content:"</>";
  position: absolute;
  top: 50%;
  left: 20px;
  transform: translateY(-50%);
}

Additionaly you need to add some more tags:

* {
  box-sizing: border-box;
  font-family: sans-serif;
}

.wrapper {
  position: relative;
  border-radius: 10px;
  background: #dadada;
  padding: 0.8em 4em;
  font-size: 1.3em;
}

attachment {
  display:block;
}

attachment::before {
  content:"</>";
  position: absolute;
  top: 50%;
  left: 20px;
  transform: translateY(-50%);
}
<div class="wrapper">
  <attachment id="7ffdba46c1b64aba89b5176469c2bd5b">
    <p>Code snippet</p>
    <p>Text, 12 lines</p>
  </attachment>
</div>

2 Comments

thank you, but I can't change HTML, I need change CSS. I have a solution from Mr.Par tha.
Note that display: flex won't work on IE 11 or earlier versions.
0

Add these few CSS in your code. It will help.

<!DOCTYPE html>
<html>
<head>
    <style> 
        attachment {
            border-radius: 10px;
            padding: 8px;
            display: flex;
            background: #dadada;
            line-height: 2;        /* New css */
            align-items: center;   /* New css */
        }
        attachment::before{
            content:"</>";
            padding-right: 20px:   /* New css */
        }
    </style>
</head>
<body>
    <attachment id="7ffdba46c1b64aba89b5176469c2bd5b">Code snippet </br> Text, 12 lines</attachment>
</body>
</html>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.