Problems with moving element CSS - html

I'd like to move element h1 a bit down but without moving the whole div block.
HTML code is here:
<div class="mainblock"></div>
<div class="under"><h1>Some text</h1></div>
CSS rules is here:
.mainblock {
margin: 40px auto 0 auto;
width: 40%;
height: 250px;
background-color: cadetblue;
}
.under {
margin: 0 auto;
width: 40%;
height: 250px;
background-color: coral;
}
h1 {
text-align: center;
font: 40px/30px Tahoma,sans-serif;
font-weight: 900;
color: azure;
/* Here I add some margin for H1 */
margin-top: 20px;
}
How can I move h1 tag only?
Using padding is not suitable because it adds some space and if it were a link it created some clickable space which I don't need.

Use position:relativeon the h1 element to move it without it affecting the position of any other elements.
h1 {
position:relative;
top:20px;
text-align: center;
font: 40px/30px Tahoma,sans-serif;
font-weight: 900;
color: azure;
/* Here I add some margin for H1 */
margin-top: 20px;
}

You can move it by adding line-height

Another possibility to achieve what you want is using positioning like so:
.under {
margin: 0 auto;
width: 40%;
height: 250px;
background-color: coral;
position:relative;
}
h1 {
text-align: center;
font: 40px/30px Tahoma,sans-serif;
font-weight: 900;
color: azure;
position:absolute;
top: 20px;
}

It looks like padding-top does what you want if the link is inside the h1 tag.
HTML
<div class="mainblock"></div>
<div class="under"><h1>Some text</h1></div>
CSS
.mainblock {
margin: 40px auto 0 auto;
width: 40%;
height: 250px;
background-color: cadetblue;
}
.under {
margin: 0 auto;
width: 40%;
height: 250px;
background-color: coral;
}
h1 {
text-align: center;
font: 40px/30px Tahoma,sans-serif;
font-weight: 900;
color: azure;
/* replace margin-top with padding-top */
padding-top: 20px;
}
Here's a fiddle...I changed the padding from 20px to 60px to make it easier to see that there's no clickable space above the text.
http://jsfiddle.net/htpb9bdk/

Provide the position:absolute to parent and child element
try this : http://jsfiddle.net/heuek2za/
.mainblock {
margin: 40px auto 0 auto;
width: 40%;
height: 250px;
background-color: cadetblue;
margin-left:28%;
}
.under {
margin: 0 auto;
position:absolute;
width: 40%;
height: 250px;
background-color: coral;
margin-left:27%;
margin-top:4%;
}
h1 {
text-align: center;
position:absolute;
font: 40px/30px Tahoma,sans-serif;
font-weight: 900;
color: azure;
/* Here I add some margin for H1 */
margin-top: 50%;
}

You can also apply float:left;width 100% to H1 which makes your margin to work.
The new CSS for h1 becomes:
h1 {
color: azure;
float: left;
font: 900 40px/30px Tahoma,sans-serif;
margin-top: 20px;
position: relative;
text-align: center;
width: 100%;
}

Related

Footer is not going doing with content (Vuejs)

Basically I created one component which has just a title and a color for background that should cover the whole page (but it's not, apparently there's a top margin and I don't know how to remove it) and also I created a componenent to be the footer. This component should stay at the botom of the page and it should go down with the addition of content, but it doesn't, the content overlaps it and even crosses it. How can I fix it?
Background CSS:
<style scoped>
*{
margin: 0%;
padding: 0%;
}
.background{
position: relative;
height: 88vh;
background-color: #3B3B3B;
}
.title{
border: 1px solid #707070;
border-left: none;
border-right: none;
}
.title h2{
text-align: left;
color: #B16DFF;
padding-top: 0.8em;
font-size: 2em;
padding-bottom: 0.5em;
margin-left: 1.5em;
font-weight: 600;
}
Footer CSS:
<style scoped>
.container{
width: 100%;
margin: 0%;
position: absolute;
bottom: 0%;
background-color: #232323;
}
.container h2{
font-weight: bold;
color: #B16DFF;
font-size: 1.5rem;
padding-top: 1.1em;
}
.container #text{
position: relative;
float: left;
padding-left: 5em;
text-align: justify;
padding-bottom: 2em;
}
.container p{
font-weight: 600;
font-size: 0.8rem;
color: white;
}
.container #title{
padding-bottom: 0.4em;
}
.container #description{
padding-bottom: 1.3rem;
}
.container #images{
position: relative;
padding-top: 3em;
float: left;
padding-left: 5em;
}
.container ul li{
display: inline-block;
padding-left: 2em;
}
On your background css, you have a scoped style so it doesn't apply to everything.
Also when you use 0 as value for a css property, you don't need to specify units.

Center 2 floating images

I want to center 2 images I've set display to block and margin 0 but nothing happens, I've tried the margin on the different divs but also no result. I can't seem to find out what I'm doing wrong,
this is the css:
#partners {
background-color: #FFF;
height: 500px;
margin: auto;
display: block;
}
#partners h2 {
color: #000000;
font-family: "helvetica";
font-size: 36px;
text-align: center;
padding-top: 110px;
}
.partner1 {
float: left;
padding: 0px, 50px, 0px, 50px;
margin-top: 125px;
}
.partner1 img {
width: 300px;
}
.partner2 {
float: left;
padding: 0px, 50px, 0px, 50px;
margin-top: 125px;
display: block;
}
.partner2 img {
width: 300px;
margin: auto;
}
Just assuming your markup here, but you want to add text-align: center to the parent, then make the child block elements display: inline-block, then those elements will be centered in the parent.
You also don't need commas between the padding amounts, and I consolidated some of your CSS.
#partners {
background-color: #FFF;
height: 500px;
margin: auto;
display: block;
text-align: center;
}
#partners h2 {
color: #000000;
font-family: "helvetica";
font-size: 36px;
text-align: center;
padding-top: 110px;
}
.partner1, .partner2 {
padding: 0px 50px 0px 50px;
margin-top: 125px;
display: inline-block;
}
.partner1 img, .partner2 img {
width: 300px;
}

CSS border styling fitting content

I've been having trouble fitting some content into a border. When entering more text, instead of extending to fit vertically it just continues past the border as shown in the attached screenshot:
And my CSS file is as follows:
body {
background-image:url(http://www.cs.aub.edu.lb/hsafa/cmps278/hw2/background.png);
background-repeat:repeat;
background-attachment:fixed;
margin: 0px;
padding: 0px;
font-family: Verdana, Tahoma, sans-serif;
}
h1 {
text-align: center;
font-family: Tahoma, Verdana, sans-serif;
font-size: 24pt;
text-shadow: 3px 3px #999999;
font-weight: bold;
}
p {
font-size: 8pt;
}
#content {
width: 800px;
margin: auto;
border: 4px solid gray;
border-radius: 20px;
background-color: #A2B964;
}
#banner {
height: 50px;
background-image:url(http://www.cs.aub.edu.lb/hsafa/cmps278/hw2/bannerbg.png);
background-repeat:repeat;
}
#banner img {
display: block;
margin:auto;
overflow: hidden;
}
#general {
float: right;
width: 250px;
border-radius: 0px 20px 0px 0px;
}
dl {
margin: 10pt;
font-size: 8pt;
font-family: Ariel, sans-serif;
}
dt {
font-weight: bold;
margin-top: 10pt;
}
ul {
list-style-type: none;
}
li {
margin-left:0px;
}
#leftsection {
width: 550px;
overflow:hidden;
background-image:url(http://www.cs.aub.edu.lb/hsafa/cmps278/hw2/background.png);
background-repeat:repeat;
background-attachment:fixed;
}
#rating {
height: 83px;
background-image:url(http://www.cs.aub.edu.lb/hsafa/cmps278/hw2/rbg.png);
background-repeat: repeat;
overflow: hidden;
border-radius: 20px 0px 0px 0px;
}
#rating img {
border-radius: 20px;
}
.special {
vertical-align: top;
font-size: 48pt;
font-weight: bold;
color: red;
}
.review {
font-size: 8pt;
font-family: Verdana, Tahoma, sans-serif;
font-weight: bold;
background-color: #E8DC9B;
border: 2px solid gray;
border-radius: 10px;
padding-left: 8px;
padding-right: 8px;
}
.personal {
margin-bottom: 20pt;
}
.italic {
font-style: italic;
margin-left: 40px;
}
img.review {
padding-right: 5px;
}
#leftcol {
margin-top: 2%;
margin-left: 2%;
margin-right: 2%;
float: left;
width: 47%;
}
#rightcol {
margin-top: 2%;
margin-right: 2%;
float: right;
width: 47%;
}
#pages {
text-align:center;
margin: 5px;
}
#validated {
position: fixed;
top: 90%;
left:80%;
width: 600px;
}
#validated img {
opacity: 0.5;
}
I've added the HTML code on CSSDeck: http://cssdeck.com/labs/full/bldwwaec
It would be better if you put the HTML codes too.
The right side element is either fixed (or absolute) or float. If it is float, you can simple fix it with adding a <br /> at the end of its parent element and set clear: both; on it. Like this:
<div id="parent">
<div>aaa</div>
<div class="float-right">bbbb</div>
<br style="clear: both;" />
</div>
Now, the div#parent fits with the content and if you set a border on it, your problem would fix.
In absolute case, however, it is not as easy as I explained and recommend revising the use of absolute (or fixed) for that part.
Good luck,
Mohammad Ali Sharpasand
Of course today, float is no longer needed, as the flexbox is available:
https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Flexbox
Also, grid is amazing:
https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Grids
you have to put one more div over the id=content and you can call the calss=pagewrapper.
.pagewrapper{
margin: 0 auto;
width: 800px;
}
put float:left in your ID
#content{
float: left;
}
The problem appears to be the floating right column.
#rightcol {
float: right;
}
It would appear you need to clear the float, since floating elements are removed from normal page flow, the parent element will not expand to match the height. A simple solution is to add a clearfix to your parent element or class (in our case ID)
#content:after {
visibility: hidden;
display: block;
font-size: 0;
content: " ";
clear: both;
height: 0;
}
This should solve your issue, if you have more questions about this I would suggest looking here.

CSS no background image, any ideas?

I'm trying to get my background image to show at the top center of the page. The image works fine if I do:
<style>
body {
background: #FFF url('img/top_logo_blank_small.png') no-repeat fixed;
}
</style>
I can't seem to work out where I've gone wrong. There must be something I've managed to mess up, I just can't see it. Here is the CSS:
body {
font-family: 'Quattrocento Sans', helvetica, sans-serif;
background: #EEE url('img/top_logo_blank_small.png') no-repeat fixed;
color: #fff;
margin: 0;
padding: 0;
}
a {
color: black;
text-decoration: none;
}
/* Typography */
.header h1 {
position: absolute;
width:100%;
top: 50%;
margin-top: -20px;
text-align: center;
letter-spacing: 4px;
}
.header h1 em {
font-size: 1.200em;
font-style: normal;
}
h1 {
font-size: 2.2em;
color: #fff;
}
.content h2 {
font-size: 1.75em;
color: #fff;
letter-spacing: 4px;
text-align: center;
}
.content h2 em {
font-size: 1.2em;
font-style: normal;
}
.content h3 {
text-align: center;
font-size: 1.0em;
font-weight: normal;
color: #ede0ed;
letter-spacing: 1px;
margin-bottom: 25px;
}
.content h4 {
margin-top: 0;
text-align: center;
font-size: 0.8em;
font-weight: normal;
color: #ede0ed;
letter-spacing: 1px;
}
#banner p {
text-align: center;
}
/* Navigation */
#nav {
margin: 4px 4px 40px;
}
#nav ul {
padding: 0;
margin: auto;
list-style: none;
}
#nav ul li {
width: 50%;
color: #BBB;
float: left;
font-family: 'Cabin Sketch';
font-size: 1.75em;
text-align: center;
background: url(img/scribble_dark.png);
}
#nav ul li a {
display: block;
/*padding: 5px 20px;*/
}
#nav ul li a:hover {
background: #e0d0e0;
}
/* Content */
.container{
max-width: 720px;
margin: 50px auto 0;
background: #FFF url('img/top_logo_blank_small.png') no-repeat fixed 0 0;
}
.header {
position: relative;
background-color: #b88fb8;
border-top: 5px solid #ede0ed;
height: 75px;
}
.content {
background-color: #000;
padding: 15px;
margin-bottom: 10px;
}
div#about {
padding:25px;
min-height: 255px;
}
img#portrait {
float: left;
margin-right: 25px;
width: 256px;
height: 256px;
}
div#footer {
width: 100%;
max-width: 720px;
margin: auto;
color: black;
text-align: right;
padding: 0 10px;
font-size: 0.850em;
}
#media screen and (max-width: 650px) {
.container {
width: 90%;
max-width: none;
}
div#footer {
width: 90%;
}
}
Try to change your path for example:
background: #EEE url('../img/top_logo_blank_small.png') no-repeat fixed top;
Because you are in a subfolder, you have to go up of a level I think
Most likely your css file is in a different folder and therefore needs another path to the image file.
The common way is to put css in a separate css/* folder, so the path should be:
url('../img/top_logo_blank_small.png')
This CSS seems to work fine, are you certain that the image exists?
http://jsfiddle.net/ghsNR/
I've just tried it here and it works fine with an image from http://placehold.it/
body {
font-family: 'Quattrocento Sans', helvetica, sans-serif;
background: #EEE url('http://placehold.it/500x500') no-repeat fixed top;
color: white;
margin: 0px;
padding: 0px;
}
The most likely cause after observing this is that your CSS isn't actually locating your image correctly. I suggest using tools like the Chrome dev tools, or Firebug to inspect the absolute path that the browser is trying to use to load the image and moving forward from there.
Is the css in the same folder as the page? If you have a different folders, you need to change the URL accordingly.
Maybe change the URL to
'../img/top_logo_blank_small.png'

sticky CSS footer broken

My footer is designed to stay at the bottom of the page even if the div above it only has a small amount of content. It worked until recently, and I seem to have broken it somehow.
Can you take a look?
Thanks in advance.
CSS:
body {
margin: 0;
padding: 0;
height: 100%;
font: 100% Helvetica, sans-serif, Arial, sans-serif;
color: #000;
background-color: #FFF;
background-image: url(images/BGmain.png);
background-repeat: repeat-x;
}
/*----------
Div styles
----------*/
#container {
min-height: 100%;
position: relative;
}
.header {
padding: 0 0 230px 0;
text-align: center;
background-image: url(images/BGlogo_55top.png);
background-repeat: no-repeat;
background-position: top;
}
.column1 {
padding-bottom: 50px;
width: 960px;
margin: 0 auto;
position: relative;
}
.footer {
position: absolute;
bottom: 0;
width: 100%;
height: 50px;
text-align: center;
}
/*----------
Other
----------*/
.plainimg {
border-style: none
}
/*----------
Text styles
----------*/
p {
font-size: 80%;
color: #333;
line-height: 150%;
text-align: left;
padding: 1px 15px 1px 15px;
}
h1 {
font-size: 100%;
color: #000;
padding: 0;
}
h2 {
font-size: 100%;
font-weight: 500;
color: #000;
padding: 0;
text-align: center;
}
/*----------
Links
----------*/
a.navlink:link, a.navlink:visited {
text-decoration: none;
display: inline-block;
color: #F1F1F1;
width: 120px;
text-align: center;
padding: 0 0 3px 0;
font-size: 80%;
}
a.navlink:hover, a.navlink:active {
text-decoration: none;
display: inline-block;
color: #FFF;
background-color: #000;
width: 120px;
text-align: centre;
padding: 0 0 3px 0;
font-size: 80%;
}
a:link, a:visited {
text-decoration: none;
color: #AEAEAE;
}
a:hover, a:active {
text-decoration: underline;
color: #999
}
The div arrangement is as follows:
<div id=container>
<div class=header></div>
<div class=column1></div>
<div class=footer></div>
</div>
As Jason McCreary said, you need to add height to the html CSS.
Use:
html
{
height: 100%;
margin: 0;
padding: 0;
}
On your pages this triggers an extraneous scrollbar for some reason.
UPDATE:
The scrollbar appears to be triggered by the overflow of the .footer h6.
Adding: bottom: 2.5ex; and line-height: 1; to the footer style appears to clears that.
But a better way is to use a CSS reset.
With no reset, at the minimum, add:
.footer h6 {
margin: 0;
padding: 0;
}
.
A CSS reset will also minimize cross-browser variation that busts the layout from platform to platform.
Take a look at this: http://matthewjamestaylor.com/blog/keeping-footers-at-the-bottom-of-the-page
When it has broken for me in the past I typically have something in the content that is the culprit - padding, invalid markup, etc. If you post a link to your page, you may find a more specific answer.
Here is your problem:
#container {
min-height:100%;
position:relative;
}
Here is the fix:
#container {
min-height:100%;
}
Good stuff:
http://www.w3schools.com/Css/pr_class_position.asp
Solved. Easy Solution Just put your Footer Division outside of your Container Division.
<div id=container>
<div class=header></div>
<div class=column1></div>
</div>
<div class=footer></div>