The following is the code
<object id="conv1" type="image/svg+xml" data="conv1.svg"></object>
<p align="center">
<button><span>Play/Replay</span></button>
</p>
I want to align the button center with respect to object. How could that be achieved?
If I try to align the button center, it gets aligned with respect to page.
Here is the website link.
http://mathsbeauty.esy.es/temp2.html
If you specify a width on a parent element then it will align correctly.
<div style="width: 504px;">
<object id="conv1" type="image/svg+xml" data="conv1.svg"></object>
<p style="text-align: center;">
<button><span>Play/Replay</span></button>
</p>
</div>
If you are not able to specify a width then you could use the #Lahiru Ashan's solution. If you still require the contents to be left aligned then you could add the following:
<div style="text-align:center; float: left;">
<object id="conv1" type="image/svg+xml" data="conv1.svg"></object>
<p><button><span>Play/Replay</span></button></p>
</div>
give width to p tag as your object width
i have created demo:
<div style="width:504px;height:458px;background-color:red;">
</div>
<p align="center" style="width:504px;">
<button><span>Play/Replay</span>
</button>
</p>
Try this,
<div style="text-align: center;">
<object id="conv1" type="image/svg+xml" data="conv1.svg"></object>
<p align="center">
<button><span>Play/Replay</span></button>
</p>
</div>
You can use flexbox to achive this:
HTML
<div class="container">
<object></object>
<button></button>
</div>
CSS
.container {
display: flex;
flex-direction: column;
align-items: center;
}
Find width of <object> tag and apply width in style of <p> tag as below code.
$( document ).ready(function() {
var width = document.getElementById('conv1').offsetWidth
var p=document.getElementsByTagName('p');
//use index as per `p` tag position in your html.
p[0].style.width = width+"px";
})
hope that help!
Wrap both of them with a div and set the div's width to the SVG's width to center the button.
.container {
width: 500px;
}
https://jsfiddle.net/tug1hudo/
Related
I am creating a website and I am trying to align the button so it is right underneath the image. I have used tags and given a class name so I can then use this in css. However, the only values I know to put for 'text-align' is 'center', 'right' or 'left'. I tried using pixels (like 30px) but that wasn't working. I've provided an image of how part of the website looks like below.
css:
.imgButton{
text-align:right;
}
html:
<img id="course-image2" src ="https://www.dhresource.com/0x0/f2/albu/g8/M00/2D/C9/rBVaVFz-C7KAY4jwAAEi8hE3J14252.jpg/men-suit-men-tuxedo-custom-made-wedding-suits.jpg" width="260" height="500" alt="guy2" class="center"/>
<div class="imgButton">
<button class="check">Gentleman</button>
</div>
Image (note the 'Gentleman' button in the far right corner):
You can achieve this by wrapping both the img and button with a container and using flexbox to set the direction of items to be in a column.
.imgContainer {
display: flex;
flex-direction: column;
}
<div class="imgContainer">
<img id="course-image2" src ="https://www.dhresource.com/0x0/f2/albu/g8/M00/2D/C9/rBVaVFz-C7KAY4jwAAEi8hE3J14252.jpg/men-suit-men-tuxedo-custom-made-wedding-suits.jpg" width="260" height="500" alt="guy2" class="center"/>
<div class="imgButton">
<button class="check">Gentleman</button>
</div>
</div>
What I want:
My image to be resized and centred.
What's happening:
The image is resized, but not centred
My code:
< img style="text-align:center;width:204px;height:204px;" src="image.jpeg" >
What am I doing wrong and how can I prevent this happening with other elements?
Your text-align: center; should be placed on the parent element, not itself.
<div style="text-align: center;">
<img style="width: 204px; height: 204px;" src="image.jpeg">
</div>
In the codes below, I have two <div> tags. I want to align one <div> to the left and the other to the right, with the same height and width. Please help me to do this.
<div id="imgShow">
<panel>
<img class = "hidden" id="orginal" alt = "Goofy pic of me" runat="server" />
<div id="ScrollImg" style="position:relative;width:900px; height:330px;overflow: scroll; top: 3px; left: -1px;left:auto">
<canvas id = "drawing" height="1500" width="1200" >
<p>Canvas not supported</p>
</canvas>
</div>
</panel>
</div>
<div id="divComplete" style="position:relative;width:100px; height:330px;overflow: scroll; top: 3px; right: -1px;right:auto"></div>
Set the floats for each div with CSS: example
.left { width:50%; float:left; height:200px; background:red;}
.right { width:50%; float: right; height:200px; background: blue;}
Try below code:
Demo
<div id="imgShow" style="width:50%; height:330px;overflow: scroll;float:left;">
<panel>
<img class = "hidden" id="orginal" alt = "Goofy pic of me" runat="server" />
<div id="ScrollImg">
<canvas id = "drawing" height="1500" width="1200" >
<p>Canvas not supported</p>
</canvas>
</div>
</panel>
</div>
<div id="divComplete" style="width:50%; height:330px;overflow: scroll;">Canvas not supported</div>
You should use floats:
<style>
#imgShow, #divComplete{
float:left;
width:50%;
}
</style>
If you want both at different widths, simply separate the css selectors and add the desired width.
PS: Avoid using inline CSS unless you need to, transfer these to a separate CSS file and include it in the head section
You can use twitter bootstrap css for styling your divs. Simply addclass="col-xs-6" to each div. Remember class="col-xs-12" is the full width that the div can take based on the width of the parent container. Using -xs- instead of -md- shrinks the div upon resize instead of knocking them down. If you want margins simply add change them to col-xs-5s then add a col-xs-2 div in between. It's also good practice to use parent divs with container-fluid and row classes
I've seen some other posts on this but even using their method on my code doesn't seem to be working for me. What am I doing wrong when trying to center these divs?
This example works fine for me (taken from another SO post).
But this one (which is my code) doesn't behave the same and isn't centered properly.
here is my code that is also in my JSFiddle
.pdf-pageimage-container {
display: block;
margin: 0px auto;
border: 1px solid #EEE;
}
<div class="pdf-pageimage-container" style="position:relative;width:612px;height:792px;">
<img style="width:612px;height:792px;" />
<div>
<div class="pdf-pageimage-container" style="position:relative;width:792px;height:612px;">
<img style="width:792px;height:612px;" />
<div>
<div class="pdf-pageimage-container" style="position:relative;width:612px;height:792px;">
<img style="width:612px;height:792px;" />
<div>
<div class="pdf-pageimage-container" style="position:relative;width:792px;height:612px;">
<img style="width:792px;height:612px;" />
<div>
<div class="pdf-pageimage-container" style="position:relative;width:612px;height:792px;">
<img style="width:612px;height:792px;" />
<div>
<div class="pdf-pageimage-container" style="position:relative;width:812px;height:792px;">
<img style="width:812px;height:792px;" />
<div>
you are not ending div tags.
<img>
can work without "/"
and to align horizontally in center use
<div align="center" class="pdf-pageimage-container" style="position:relative;width:792px;height:612px;"></div>
Your HTML is incorrect. You are opening <div> tags but not closing them with </div>, so you are opening lots of nesting div elements.
You can place them in a wrapper div with a fixed width and then center each of them with auto margin.
Let's say that the wrapper has an ID wrapper and the sub-elements all have the class child. In that case you can for example set the following in your CSS
#wrapper{
width: 800px;
}
.child{
margin: 0 auto;
}
First off I would close the endings of the "div" tags like so just to stay valid with your code.
I'll assume that these divs will stack on top of each other so add this to your "pdf-pageimage-container" css class:
.pdf-pageimage-container {
clear : both;
}
If you want the divs to float next to each other one after another you could use this instead
.pdf-pageimage-container {
float : left;
}
Hope this helps.
I'm using the following code in body section.
<center>Get Started</center>
Is there any alternative for <center> tag?
How can I make it center without using <center> tag?
Add text-align:center;display:block; to the css class. Better than setting a style on the controls themselves. If you want to change it you do so in one place.
You can do this:
<div style="text-align: center">
Get Started
</div>
You can use css like below;
Get Started
You can put in in a paragraph
<p style="text-align:center;">Get Started</p>
To align a div in the center, you have to do 2 things:
- Make the div a fixed width
- Set the left and right margin properties variable
<div class="container">
<div style="width:100px; margin:0 auto;">
<span>a centered div</span>
</div>
</div>
I don't know why but for me text-align:center; only works with:
text-align: grid;
OR
display: inline-grid;
I checked and no one style is overriding.
My structure:
<ul>
<li>
<a>ElementToCenter</a>
</li>
</ul>
You can use the code below:
a {
display: block;
width: 113px;
margin: auto;
}
By setting, in my case, the link to display:block, it is easier
to position the link.
This works the same when you use a <div> tag/class.
You can pick any width you want.
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
</head>
<body>
<h4 align="center">
Center
</h4>
</body>
</html>
There's also a handy tag... whatever you put in between, gets centered.
Like so:
<center>
<a href..... whatever>
</center>
you can try this
display inline-block to make it fit width,
margin-left to make it move 50% away from left,
and transform translateX to make it center his position
display: inline-block;
margin-left: 50%;
transform: translateX(-50%);
In your html file:
Get Started
In your css file:
.hpbottom{
text-align: center;
}