英文:
How to position an image in a CSS designed Bar graph
问题
我正在创建一个柱状图,并希望能够在每个柱子内部放置图像,而不改变柱子的大小。我已经找到了一种通过文本实现这一点的方法,但无法用图像实现相同的效果。这是否可能?或者将图像放在柱子的左边,就像传统的柱状图一样,会更灵活吗?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<title>SF6</title>
</head>
<body>
<main>
<section id="tall">
<article class="tall">
<div>
<p>Sages <img src="./badge/some_stuff_for_richard5.png" height="50"><span></span><span class="tall"></span></p>
</div>
</article>
<article class="tall">
<div>
<p>prophet<span></span><span class="tall"></span></p>
</div>
</article>
<article class="tall">
<div>
<p>renegade<span></span><span class="tall"></span></p>
</div>
</article>
</section>
</main>
</body>
</html>
html {
font-size: 100%;
font-family: sans-serif;
}
body {
background-color: #1a1a2e;
}
html,
body,
main {
padding: 0;
margin: 0;
box-sizing: border-box;
}
main {
overflow: hidden;
position: relative;
height: 100vh;
width: 100vw;
display: flex;
justify-content: center;
align-items: center;
}
section {
background: #1a1a2e;
}
section article.tall {
width: 500px;
height: auto;
}
section article.tall p {
color: #ffffff;
padding: 10px;
position: relative;
box-sizing: border-box;
z-index: 2;
overflow: hidden;
}
section article.tall p img {
color: #ffffff;
padding: 10px;
position: relative;
box-sizing: border-box;
z-index: 2;
overflow: hidden;
}
section article.tall div span:nth-child(1) {
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
margin: auto;
background: #0f3460;
z-index: -2;
height: 100%;
width: 100%;
}
section article.tall div span:nth-child(2) {
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
margin: auto;
background: rgb(94, 227, 255);
background: linear-gradient(90deg, rgba(94, 227, 255, 1) 0%, rgba(11, 113, 230, 1) 100%);
z-index: -1;
height: 100%;
width: 100%;
}
英文:
I am creating a bar graph and i want to be able to position the image inside each bar without altering the bars size. I have found a way to implement this through text but i can not do the same with an image. Is this possible? Or would it be more flexible if i put the image to the left of the bar instead like a traditional bar graph?.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<title>SF6</title>
</head>
<body>
<main>
<section id="tall">
<article class="tall">
<div>
<p>Sages <img src ="./badge/some_stuff_for_richard5.png" height="50" ><span></span><span class="tall"></span></p>
</div>
<article class="tall">
<div>
<p>prophet<span></span><span class="tall"></span></p>
</div>
<article class="tall">
<div>
<p>renegade<span></span><span class="tall"></span></p>
</div>
</article>
</section>
</main>
</body>
</html>
html{
font-size: 100%;
font-family: sans-serif;
}
body{
background-color: #1a1a2e ;
}
html,
body,
main{
padding: 0;
margin: 0;
box-sizing: border-box;
}
main{
overflow: hidden;
position: relative;
height: 100vh;
width: 100vw;
display: flex;
justify-content:center ;
align-items: center;
}
section{
background: #1a1a2e
}
section article.tall{
width: 500px;
height: auto;
}
section article.tall p {
color:#ffffff;
padding: 10px;
position:relative;
box-sizing: border-box;
z-index: 2;
overflow: hidden;
}
section article.tall p img{
color:#ffffff;
padding: 10px;
position:relative;
box-sizing: border-box;
z-index: 2;
overflow: hidden;
}
section article.tall div span:nth-child(1){
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
margin:auto;
background: #0f3460;
z-index: -2;
height: 100%;
width: 100%;
}
section article.tall div span:nth-child(2){
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
margin:auto;
background: rgb(94,227,255);
background: linear-gradient(90deg, rgba(94,227,255,1) 0%, rgba(11,113,230,1) 100%);
z-index: -1;
height: 100%;
width: 100%;
}
答案1
得分: 1
你可以使用Flex并进行一些更改来实现你想要的效果,但我不太明白你的需求,所以我根据你的问题写出了我理解的内容。
<main>
<section id="tall">
<article class="tall">
<div>
<p>Sages <img src="./badge/some_stuff_for_richard5.png" style="margin-left: 10px;"><span></span><span class="tall"></span></p>
</div>
</article>
<article class="tall">
<div>
<p><img src="./badge/some_stuff_for_richard5.png" style="margin-right: 10px;">prophet<span></span><span class="tall"></span></p>
</div>
</article>
<article class="tall">
<div>
<p>renegade<img src="./badge/some_stuff_for_richard5.png" style="margin-left: 10px;"><span></span><span class="tall"></span></p>
</div>
</article>
</section>
</main>
html{
font-size: 100%;
font-family: sans-serif;
}
body{
background-color: #1a1a2e ;
}
html,
body,
main{
padding: 0;
margin: 0;
box-sizing: border-box;
}
main{
overflow: hidden;
position: relative;
height: 100vh;
width: 100vw;
display: flex;
justify-content:center ;
align-items: center;
}
section{
background: #1a1a2e
}
section article.tall{
width: 500px;
height: auto;
}
section article.tall p {
display: flex;
align-items: center;
color:#ffffff;
padding: 10px;
position:relative;
box-sizing: border-box;
z-index: 2;
overflow: hidden;
height: 38px;
}
section article.tall p img{
display: block;
color:#ffffff;
position:relative;
box-sizing: border-box;
z-index: 2;
overflow: hidden;
height: 30px;
}
section article.tall div span:nth-child(1){
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
margin:auto;
background: #0f3460;
z-index: -2;
height: 100%;
width: 100%;
}
section article.tall div span:nth-child(2){
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
margin:auto;
background: rgb(94,227,255);
background: linear-gradient(90deg, rgba(94,227,255,1) 0%, rgba(11,113,230,1) 100%);
z-index: -1;
height: 100%;
width: 100%;
}
英文:
You can use Flex and get what you want with some changes, but I didn't understand what you wanted, so I wrote what I got from your question.
<main>
<section id="tall">
<article class="tall">
<div>
<p>Sages <img src ="./badge/some_stuff_for_richard5.png" style="margin-left: 10px;"><span></span><span class="tall"></span></p>
</div>
<article class="tall">
<div>
<p><img src ="./badge/some_stuff_for_richard5.png" style="margin-right: 10px;">prophet<span></span><span class="tall"></span></p>
</div>
<article class="tall">
<div>
<p>renegade<img src ="./badge/some_stuff_for_richard5.png" style="margin-left: 10px;"><span></span><span class="tall"></span></p>
</div>
</article>
</section>
</main>
html{
font-size: 100%;
font-family: sans-serif;
}
body{
background-color: #1a1a2e ;
}
html,
body,
main{
padding: 0;
margin: 0;
box-sizing: border-box;
}
main{
overflow: hidden;
position: relative;
height: 100vh;
width: 100vw;
display: flex;
justify-content:center ;
align-items: center;
}
section{
background: #1a1a2e
}
section article.tall{
width: 500px;
height: auto;
}
section article.tall p {
display: flex;
align-items: center;
color:#ffffff;
padding: 10px;
position:relative;
box-sizing: border-box;
z-index: 2;
overflow: hidden;
height: 38px;
}
section article.tall p img{
display: block;
color:#ffffff;
position:relative;
box-sizing: border-box;
z-index: 2;
overflow: hidden;
height: 30px;
}
section article.tall div span:nth-child(1){
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
margin:auto;
background: #0f3460;
z-index: -2;
height: 100%;
width: 100%;
}
section article.tall div span:nth-child(2){
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
margin:auto;
background: rgb(94,227,255);
background: linear-gradient(90deg, rgba(94,227,255,1) 0%, rgba(11,113,230,1) 100%);
z-index: -1;
height: 100%;
width: 100%;
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论