How to text-align an svg element inside a div
I would just like to know why text-align: right
is not moving the svg to the right? It is moving the button to the right. I need the svg to sit above the button on the right.
svg {
display: block
}
polygon {
fill: red;
}
.main {
width: 100%;
background-color: green;
text-align: right;
}
<div class="main">
<svg height="20" width="20">
<polygon points="10,0 20,20 0,20"/>
</svg>
<button>Test</button>
</div>
html css
add a comment |
I would just like to know why text-align: right
is not moving the svg to the right? It is moving the button to the right. I need the svg to sit above the button on the right.
svg {
display: block
}
polygon {
fill: red;
}
.main {
width: 100%;
background-color: green;
text-align: right;
}
<div class="main">
<svg height="20" width="20">
<polygon points="10,0 20,20 0,20"/>
</svg>
<button>Test</button>
</div>
html css
add a comment |
I would just like to know why text-align: right
is not moving the svg to the right? It is moving the button to the right. I need the svg to sit above the button on the right.
svg {
display: block
}
polygon {
fill: red;
}
.main {
width: 100%;
background-color: green;
text-align: right;
}
<div class="main">
<svg height="20" width="20">
<polygon points="10,0 20,20 0,20"/>
</svg>
<button>Test</button>
</div>
html css
I would just like to know why text-align: right
is not moving the svg to the right? It is moving the button to the right. I need the svg to sit above the button on the right.
svg {
display: block
}
polygon {
fill: red;
}
.main {
width: 100%;
background-color: green;
text-align: right;
}
<div class="main">
<svg height="20" width="20">
<polygon points="10,0 20,20 0,20"/>
</svg>
<button>Test</button>
</div>
svg {
display: block
}
polygon {
fill: red;
}
.main {
width: 100%;
background-color: green;
text-align: right;
}
<div class="main">
<svg height="20" width="20">
<polygon points="10,0 20,20 0,20"/>
</svg>
<button>Test</button>
</div>
svg {
display: block
}
polygon {
fill: red;
}
.main {
width: 100%;
background-color: green;
text-align: right;
}
<div class="main">
<svg height="20" width="20">
<polygon points="10,0 20,20 0,20"/>
</svg>
<button>Test</button>
</div>
html css
html css
edited Nov 14 '18 at 12:35
asked Nov 14 '18 at 12:19
Freddy Bonda
11110
11110
add a comment |
add a comment |
4 Answers
4
active
oldest
votes
It's because you have the SVG as a block level element. Block's don't text-align. You could float it right, or just simply give it display: inline-block. See below.
svg {
display: inline-block
}
polygon {
fill: red;
}
.main {
width: 100%;
background-color: green;
text-align: right;
}
<div class="main">
<svg height="20" width="20">
<polygon points="10,0 20,20 0,20"/>
</svg>
<div>
<button>Test</button>
</div>
</div>
Edit: You can wrap the button in a div (a block level element). Alternatively, you can just put in a line-break (br) in between the two elements.
I need the arrow to be ABOVE the button on the right side hey
– Freddy Bonda
Nov 14 '18 at 12:30
Edited the answer.
– Eric
Nov 14 '18 at 12:38
add a comment |
svg is not moving right as you are aligning any text as right, not svg as it is set as display: Block instead of display: inline-block;
try:
float: right;
on the svg.
I need the arrow to be ABOVE the button on the right side hey
– Freddy Bonda
Nov 14 '18 at 12:32
add a comment |
As you have editted your post and you want both objects on the right side above eachother I have added one extra div arround it. This div will float:right;
which means that it'll be positioned to the right side of the page.
Everything in the div will just position under each other.
.right-section { float:right; }
svg { margin-left:10px; display:block; }
polygon {
fill: red;
}
.main {
width: 100%;
background-color: green;
text-align: right;
}
<div class="main">
<div class="right-section">
<svg height="20" width="20">
<polygon points="10,0 20,20 0,20"/>
</svg>
<button>Test</button>
</div>
</div>
I have also added margin-left:10px;
to the svg { }
to make sure the arrow is in the center of the button.
add a comment |
@Eric has explained you well why SVG is not moving to the right.
Another solution to resolve your problem is to use flexbox.
/*svg {
display: block
}*/
polygon {
fill: red;
}
.main {
width: 100%;
background-color: green;
/* I added only these rules */
display: flex;
flex-direction: column;
align-items: flex-end;
}
/*svg {
display: block
}*/
polygon {
fill: red;
}
.main {
width: 100%;
background-color: green;
display: flex;
flex-direction: column;
align-items: flex-end;
}
<div class="main">
<svg height="20" width="20">
<polygon points="10,0 20,20 0,20"/>
</svg>
<button>Test</button>
</div>
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53300114%2fhow-to-text-align-an-svg-element-inside-a-div%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
It's because you have the SVG as a block level element. Block's don't text-align. You could float it right, or just simply give it display: inline-block. See below.
svg {
display: inline-block
}
polygon {
fill: red;
}
.main {
width: 100%;
background-color: green;
text-align: right;
}
<div class="main">
<svg height="20" width="20">
<polygon points="10,0 20,20 0,20"/>
</svg>
<div>
<button>Test</button>
</div>
</div>
Edit: You can wrap the button in a div (a block level element). Alternatively, you can just put in a line-break (br) in between the two elements.
I need the arrow to be ABOVE the button on the right side hey
– Freddy Bonda
Nov 14 '18 at 12:30
Edited the answer.
– Eric
Nov 14 '18 at 12:38
add a comment |
It's because you have the SVG as a block level element. Block's don't text-align. You could float it right, or just simply give it display: inline-block. See below.
svg {
display: inline-block
}
polygon {
fill: red;
}
.main {
width: 100%;
background-color: green;
text-align: right;
}
<div class="main">
<svg height="20" width="20">
<polygon points="10,0 20,20 0,20"/>
</svg>
<div>
<button>Test</button>
</div>
</div>
Edit: You can wrap the button in a div (a block level element). Alternatively, you can just put in a line-break (br) in between the two elements.
I need the arrow to be ABOVE the button on the right side hey
– Freddy Bonda
Nov 14 '18 at 12:30
Edited the answer.
– Eric
Nov 14 '18 at 12:38
add a comment |
It's because you have the SVG as a block level element. Block's don't text-align. You could float it right, or just simply give it display: inline-block. See below.
svg {
display: inline-block
}
polygon {
fill: red;
}
.main {
width: 100%;
background-color: green;
text-align: right;
}
<div class="main">
<svg height="20" width="20">
<polygon points="10,0 20,20 0,20"/>
</svg>
<div>
<button>Test</button>
</div>
</div>
Edit: You can wrap the button in a div (a block level element). Alternatively, you can just put in a line-break (br) in between the two elements.
It's because you have the SVG as a block level element. Block's don't text-align. You could float it right, or just simply give it display: inline-block. See below.
svg {
display: inline-block
}
polygon {
fill: red;
}
.main {
width: 100%;
background-color: green;
text-align: right;
}
<div class="main">
<svg height="20" width="20">
<polygon points="10,0 20,20 0,20"/>
</svg>
<div>
<button>Test</button>
</div>
</div>
Edit: You can wrap the button in a div (a block level element). Alternatively, you can just put in a line-break (br) in between the two elements.
svg {
display: inline-block
}
polygon {
fill: red;
}
.main {
width: 100%;
background-color: green;
text-align: right;
}
<div class="main">
<svg height="20" width="20">
<polygon points="10,0 20,20 0,20"/>
</svg>
<div>
<button>Test</button>
</div>
</div>
svg {
display: inline-block
}
polygon {
fill: red;
}
.main {
width: 100%;
background-color: green;
text-align: right;
}
<div class="main">
<svg height="20" width="20">
<polygon points="10,0 20,20 0,20"/>
</svg>
<div>
<button>Test</button>
</div>
</div>
edited Nov 14 '18 at 12:36
answered Nov 14 '18 at 12:24
Eric
1866
1866
I need the arrow to be ABOVE the button on the right side hey
– Freddy Bonda
Nov 14 '18 at 12:30
Edited the answer.
– Eric
Nov 14 '18 at 12:38
add a comment |
I need the arrow to be ABOVE the button on the right side hey
– Freddy Bonda
Nov 14 '18 at 12:30
Edited the answer.
– Eric
Nov 14 '18 at 12:38
I need the arrow to be ABOVE the button on the right side hey
– Freddy Bonda
Nov 14 '18 at 12:30
I need the arrow to be ABOVE the button on the right side hey
– Freddy Bonda
Nov 14 '18 at 12:30
Edited the answer.
– Eric
Nov 14 '18 at 12:38
Edited the answer.
– Eric
Nov 14 '18 at 12:38
add a comment |
svg is not moving right as you are aligning any text as right, not svg as it is set as display: Block instead of display: inline-block;
try:
float: right;
on the svg.
I need the arrow to be ABOVE the button on the right side hey
– Freddy Bonda
Nov 14 '18 at 12:32
add a comment |
svg is not moving right as you are aligning any text as right, not svg as it is set as display: Block instead of display: inline-block;
try:
float: right;
on the svg.
I need the arrow to be ABOVE the button on the right side hey
– Freddy Bonda
Nov 14 '18 at 12:32
add a comment |
svg is not moving right as you are aligning any text as right, not svg as it is set as display: Block instead of display: inline-block;
try:
float: right;
on the svg.
svg is not moving right as you are aligning any text as right, not svg as it is set as display: Block instead of display: inline-block;
try:
float: right;
on the svg.
answered Nov 14 '18 at 12:26
Boywithanafro
13
13
I need the arrow to be ABOVE the button on the right side hey
– Freddy Bonda
Nov 14 '18 at 12:32
add a comment |
I need the arrow to be ABOVE the button on the right side hey
– Freddy Bonda
Nov 14 '18 at 12:32
I need the arrow to be ABOVE the button on the right side hey
– Freddy Bonda
Nov 14 '18 at 12:32
I need the arrow to be ABOVE the button on the right side hey
– Freddy Bonda
Nov 14 '18 at 12:32
add a comment |
As you have editted your post and you want both objects on the right side above eachother I have added one extra div arround it. This div will float:right;
which means that it'll be positioned to the right side of the page.
Everything in the div will just position under each other.
.right-section { float:right; }
svg { margin-left:10px; display:block; }
polygon {
fill: red;
}
.main {
width: 100%;
background-color: green;
text-align: right;
}
<div class="main">
<div class="right-section">
<svg height="20" width="20">
<polygon points="10,0 20,20 0,20"/>
</svg>
<button>Test</button>
</div>
</div>
I have also added margin-left:10px;
to the svg { }
to make sure the arrow is in the center of the button.
add a comment |
As you have editted your post and you want both objects on the right side above eachother I have added one extra div arround it. This div will float:right;
which means that it'll be positioned to the right side of the page.
Everything in the div will just position under each other.
.right-section { float:right; }
svg { margin-left:10px; display:block; }
polygon {
fill: red;
}
.main {
width: 100%;
background-color: green;
text-align: right;
}
<div class="main">
<div class="right-section">
<svg height="20" width="20">
<polygon points="10,0 20,20 0,20"/>
</svg>
<button>Test</button>
</div>
</div>
I have also added margin-left:10px;
to the svg { }
to make sure the arrow is in the center of the button.
add a comment |
As you have editted your post and you want both objects on the right side above eachother I have added one extra div arround it. This div will float:right;
which means that it'll be positioned to the right side of the page.
Everything in the div will just position under each other.
.right-section { float:right; }
svg { margin-left:10px; display:block; }
polygon {
fill: red;
}
.main {
width: 100%;
background-color: green;
text-align: right;
}
<div class="main">
<div class="right-section">
<svg height="20" width="20">
<polygon points="10,0 20,20 0,20"/>
</svg>
<button>Test</button>
</div>
</div>
I have also added margin-left:10px;
to the svg { }
to make sure the arrow is in the center of the button.
As you have editted your post and you want both objects on the right side above eachother I have added one extra div arround it. This div will float:right;
which means that it'll be positioned to the right side of the page.
Everything in the div will just position under each other.
.right-section { float:right; }
svg { margin-left:10px; display:block; }
polygon {
fill: red;
}
.main {
width: 100%;
background-color: green;
text-align: right;
}
<div class="main">
<div class="right-section">
<svg height="20" width="20">
<polygon points="10,0 20,20 0,20"/>
</svg>
<button>Test</button>
</div>
</div>
I have also added margin-left:10px;
to the svg { }
to make sure the arrow is in the center of the button.
.right-section { float:right; }
svg { margin-left:10px; display:block; }
polygon {
fill: red;
}
.main {
width: 100%;
background-color: green;
text-align: right;
}
<div class="main">
<div class="right-section">
<svg height="20" width="20">
<polygon points="10,0 20,20 0,20"/>
</svg>
<button>Test</button>
</div>
</div>
.right-section { float:right; }
svg { margin-left:10px; display:block; }
polygon {
fill: red;
}
.main {
width: 100%;
background-color: green;
text-align: right;
}
<div class="main">
<div class="right-section">
<svg height="20" width="20">
<polygon points="10,0 20,20 0,20"/>
</svg>
<button>Test</button>
</div>
</div>
edited Nov 14 '18 at 12:57
answered Nov 14 '18 at 12:39
JeroenE
509318
509318
add a comment |
add a comment |
@Eric has explained you well why SVG is not moving to the right.
Another solution to resolve your problem is to use flexbox.
/*svg {
display: block
}*/
polygon {
fill: red;
}
.main {
width: 100%;
background-color: green;
/* I added only these rules */
display: flex;
flex-direction: column;
align-items: flex-end;
}
/*svg {
display: block
}*/
polygon {
fill: red;
}
.main {
width: 100%;
background-color: green;
display: flex;
flex-direction: column;
align-items: flex-end;
}
<div class="main">
<svg height="20" width="20">
<polygon points="10,0 20,20 0,20"/>
</svg>
<button>Test</button>
</div>
add a comment |
@Eric has explained you well why SVG is not moving to the right.
Another solution to resolve your problem is to use flexbox.
/*svg {
display: block
}*/
polygon {
fill: red;
}
.main {
width: 100%;
background-color: green;
/* I added only these rules */
display: flex;
flex-direction: column;
align-items: flex-end;
}
/*svg {
display: block
}*/
polygon {
fill: red;
}
.main {
width: 100%;
background-color: green;
display: flex;
flex-direction: column;
align-items: flex-end;
}
<div class="main">
<svg height="20" width="20">
<polygon points="10,0 20,20 0,20"/>
</svg>
<button>Test</button>
</div>
add a comment |
@Eric has explained you well why SVG is not moving to the right.
Another solution to resolve your problem is to use flexbox.
/*svg {
display: block
}*/
polygon {
fill: red;
}
.main {
width: 100%;
background-color: green;
/* I added only these rules */
display: flex;
flex-direction: column;
align-items: flex-end;
}
/*svg {
display: block
}*/
polygon {
fill: red;
}
.main {
width: 100%;
background-color: green;
display: flex;
flex-direction: column;
align-items: flex-end;
}
<div class="main">
<svg height="20" width="20">
<polygon points="10,0 20,20 0,20"/>
</svg>
<button>Test</button>
</div>
@Eric has explained you well why SVG is not moving to the right.
Another solution to resolve your problem is to use flexbox.
/*svg {
display: block
}*/
polygon {
fill: red;
}
.main {
width: 100%;
background-color: green;
/* I added only these rules */
display: flex;
flex-direction: column;
align-items: flex-end;
}
/*svg {
display: block
}*/
polygon {
fill: red;
}
.main {
width: 100%;
background-color: green;
display: flex;
flex-direction: column;
align-items: flex-end;
}
<div class="main">
<svg height="20" width="20">
<polygon points="10,0 20,20 0,20"/>
</svg>
<button>Test</button>
</div>
/*svg {
display: block
}*/
polygon {
fill: red;
}
.main {
width: 100%;
background-color: green;
display: flex;
flex-direction: column;
align-items: flex-end;
}
<div class="main">
<svg height="20" width="20">
<polygon points="10,0 20,20 0,20"/>
</svg>
<button>Test</button>
</div>
/*svg {
display: block
}*/
polygon {
fill: red;
}
.main {
width: 100%;
background-color: green;
display: flex;
flex-direction: column;
align-items: flex-end;
}
<div class="main">
<svg height="20" width="20">
<polygon points="10,0 20,20 0,20"/>
</svg>
<button>Test</button>
</div>
answered Nov 14 '18 at 13:00
ReSedano
2,6502415
2,6502415
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53300114%2fhow-to-text-align-an-svg-element-inside-a-div%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown