To can center a
fixed or absolute positioned element (Div or other block element), set the right and left CSS properties to 0, and then margin-left and margin-right to auto, as if you were centering a static positioned element.
- Example, centering a fixed Div:
<style type="text/css">
#divid {
position: fixed;
/* center the element */
right: 0;
left: 0;
margin-right: auto;
margin-left: auto;
/* give it dimensions */
min-height: 8em;
width: 90%;
background: #dafeda;
}
</style>
<div id="divid">https://CoursesWeb.net/</div>
- Example, centering an absolute positioned Div (the parent element must have:
position: relative):
<style type="text/css">
#parent{
position:relative;
height:8.5em;
}
#divid {
position: absolute;
/* center the element */
right: 0;
left: 0;
margin-right: auto;
margin-left: auto;
/* give it dimensions */
min-height: 8em;
width: 90%;
background: #dafeda;
}
</style>
<div id="parent">
<div id="divid">https://marplo.net/jocuri</div>
</div>
Demo:
Daily Test with Code Example
HTML
CSS
JavaScript
PHP-MySQL
Which tag adds a new line into a paragraph?
<b> <br> <p>First line ...<br>
Other line...
Which CSS property can be used to add space between letters?
text-size word-spacing letter-spacing#id {
letter-spacing: 2px;
}
What JavaScript function can be used to get access to HTML element with a specified ID?
getElementById() getElementsByTagName() createElement()var elm = document.getElementById("theID");
var content = elm.innerHTML;
alert(content);
Click on the "echo" correct instruction.
echo "CoursesWeb.net" echo "CoursesWeb.net"; echo ""CoursesWeb.net";echo "Address URL: http://CoursesWeb.net";