HTML
<div id="nav">
<div id="nav_wrapper">
<ul>
<li>Home</li><li>
Licensing</li><li>
About us</li><li>
Testimonials</li><li>
Contact Us</li><li>
Social <img src="image/arrow.png" width="8" height="4" />
<ul>
<li><img src="image/social/YouTube.png" width="32" height="32" title="Youtube" /></li>
<li><img src="image/social/Twitter.png" width="32" height="32" title="Twitter"></li>
<li><img src="image/social/Facebook.png" width="32" height="32" title="Facebook"></li>
</ul>
</li>
</ul>
</div>
</div>
<div id="content">
<img src="image/placeholderimg.png">
<h2>Overview</h2>
<p>Filler Text</p>
</div>
</div>
CSS3
#content
{
margin-left: auto;
font-family: Arial, Helvetica, sans-serif;
resize: both;
}
#content p
{
max-width: 1100px;
margin: 0;
color: #ccc;
min-width: 960px;
}
#content h2
{
margin: 0;
color: #ccc;
min-width: 960px;
}
#content img
{
float: left;
padding-right: 20px;
padding-bottom: 20px;
}
#wrapper
{
min-width: 960px;
width: 50%;
margin: auto;
}
Fixed CSS3 Code
#content
{
padding-top: 10px;
font-family: Arial, Helvetica, sans-serif;
resize: both;
}
#content p
{
max-width: 1100px;
margin: 0;
color: #ccc;
min-width: 960px;
}
#content h2
{
margin: 0;
color: #ccc;
min-width: 960px;
}
#content img
{
float: left;
padding-right: 20px;
padding-bottom: 20px;
}
#wrapper
{
min-width: 960px;
width: 50%;
margin: auto;
}
So I've been going around looking for a fix to this, but it seems like i can't find one... So I've come to ask the more seasoned programmers here at Stack-overflow. My Problem i have is need need the content div to re-size along with the rest of the elements, but i cant seem to do it properly. I don't want to completely cut it out using overflow, I want it to shrink along with the page re-size. Is there anyway of doing it? Provided above is the css3 code along with the html divs I'm trying to re-size. The main divs I'm trying to re-size is the content, or the wrapper as an over all if possible.
Edit: For some reason or the other I did something I cant explain that fixed the code, could some be so kindly and explain to me what I did?
width:auto;
Once try applying this to your code along with "min-width".. i don't know whether it works or not, but once give it a try..
The CCS3 property for "resize" allows the user to drag and resize the content div. You should use;
width: auto;
or you could use;
width: 100%;
Check out the fiddle. You do not need to set the widths of p or h tags. They usually take up the full space.
Setting the containers to width: 100% should do it.
http://jsfiddle.net/92gnt7qt/4/
#nav {width: 100%;min-width: 960px;}
#nav_wrapper {width: 100%;}
#content
{
width: 100%;
min-width: 960px;
}
If your parent has a min-width of 960px and the children have widths of 100%, the children will still only go to 960px.
It seems by removing
margin: auto;
It some how auto configured it to what I wanted it to do. Would anyone be able to help me understand this?
Related
I've been having an issue with every single CSS exercise so far where the first element inside my body tag, whether it's an img or an h1 is simply stuck at the top left corner of the page (where the body tag starts, I assume) and it's just impossible to move it in any way, regardless of margin size or element width. I even tried adding a background color to it just to see if it would work and it didn't, so i guess that for some reasons, no modifications can be made to this element.
Here's my HTML
<body>
<header class="Top">
<img src="img/logo.png" alt="NeoDance Logo" width="356" height="48" class="logo">
<nav class="NavBar">
Home
About
Class schedules
Performances
Blog
Contact
</nav>
<div class="ClearFix"></div>
</header>
Here's my CSS. Note that before this displayed line, I'm using a completely unedited version of the Meyer css reset
header.Top{
width: 1440px;
margin: auto;
background-color: #303030;
overflow: hidden
}
div.wrapper
img.Logo{
margin-top: 35px;
margin-bottom: 35px;
margin-left: 250px;
margin: auto;
background-color: #303030;
}
nav.NavBar{
float: right;
width: 490px;
background-color: #303030;
list-style: none;
margin: auto;
margin-right: 250px
}
a.links{
float: right;
font-size: 15pt;
font-family: 'Muli', sans-serif;
color: #8c8c8c;
margin-top: 50px;
margin-right: 18px;
}
div.container 1{
width: 490px;
clear: both
}
img.dancers{
float: right;
}
div.ClearFix{
clear: both;
}
That img.logo should have margins applied, as specified in the css. However it's just stuck there, shown in the image below
Problem
I'm guessing you're talking about your logo, and not the actual header element.
For one, your css selector is wrong. It should be img.logo instead of img.Logo
Also, remove that div.wrapper code from your css. What's that doing there? Then remove the margin: auto from your img.logo style and you're good to go.
The order of declaration in CSS is important (hence the "Cascading").
Therefore, when you do :
img.Logo{
margin-top: 35px;
margin-bottom: 35px;
margin-left: 250px;
margin: auto;
background-color: #303030;
}
margin:auto overrides all of the margins above.
You should try to put margin:auto before the other margins and it should work.
I am new to HTML5 & CSS and New since HTML when it first came to life
Anyhow I am working on learning how to code in HTML5 & CSS3 at the moment.. but have ran into a road block...
I want to get my Copy right information on the left of the footer background and my browser icons to the right of my footer background.... I have been playing with the problem for 9 hours I don't give up easily even tried some suggestions I found here which did not work...
If you would like to see actual page you can goto
http://cowboy0629.ddns.net/test
.mainFooter {
width: 97%;
float: left;
height: 40px;
border-radius: 5px;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
background-color: #141476;
margin: 2% 1.5% 2% 1.5%;
}
.footerIcons img.chrome {
width: auto;
height: 20px;
}
.footerIcons img.firefox {
width: auto;
height: 23px;
}
.footerIcons img.safari {
width: auto;
height: 23px;
}
.footerIcons {
float: right;
height: 9px;
}
.footerIcons ul {
float: right;
padding: 0;
margin: 0 auto;
}
.footerIcons li {
float: right;
list-style:none;
margin-left:5px;
}
.footerIcons span p {
height: 20px;
float: left;
color: #3399FF;
width: 97%;
margin: 9px;
}
<footer class="mainFooter">
<div class="footerIcons">
<span>
<p>Copyright © 2017 cowboyDesigns.com</p>
</span>
<ul>
<li>
<img class="chrome" src="images/icons/black-chrome-icon.png" alt="">
</li>
<li>
<img class="firefox" src="images/icons/black-firefox-icon.png" alt="">
</li>
<li>
<img class="safari" src="images/icons/black-safari-icon2.png" alt="">
</li>
</ul>
</div>
</footer>
You could use relative positioning on the <ul> element.
.footerIcons ul {
position: relative;
top: -47px;
}
This might be a sloppy solve than doing something like setting the container size to 30% and getting div alignment.
The solutions above will fix the issue but they seem more likely to be hacks,
p and ul are block elements and they won't be in the same line by default.
you need to replace the existing CSS rules with the set the CSS as below
.mainFooter p {
color: #3399FF;
display: inline-block;
margin: 9px;
}
.mainFooter ul {
display: inline-block;
float: right;
list-style: none;
margin: 0 auto;
}
.mainFooter img {
width: 30px;
height: 30px;
margin: 5px;
}
there is no need for separate rules for each browser icon and use icons of same width and height.
Just change the float setting to left in .floatericons in the css file for the copyright part.
.footerIcons {
float: left;
height: 9px; }
Add this part:
.footerIcons ul {
position: relative;
top: -47px;
left:600px;
float:right;}
There's multiple ways I can think of to accomplish this.
This works:
<footer class="mainFooter">
<ul>
<li style="float:left">Copyright © 2017 cowboyDesigns.com</li>
<li style="float:right"><img class="chrome" src="images/icons/black-chrome-icon.png" alt=""></li>
<li style="float:right"><img class="firefox" src="images/icons/black-firefox-icon.png" alt=""></li>
<li style="float:right"><img class="safari" src="images/icons/black-safari-icon2.png" alt=""></li>
</ul>
</footer>
It could use a little love with regards to vertical alignment, but it works.
I wouldn't set links in navigation bars to display:inline because it makes them harder to click (since they don't fill up the block around them)...I also use utility CSS float classes, not inline styles.
Floats and positioning are one of the hardest things to learn in CSS but there's an easy and fast way to get it sorted out.
Check out this video on using Chrome DevTools as an IDE
Not only can you see the changes in real time, you can even map them back to your source files so changes you make are saved.
Or you could just use a framework that has solutions for things like this baked right in. I'm a big fan on Foundation and the grid and alignment classes would be well-suited to this problem.
It seems you're doing this for school so maybe you can't use a framework but you can look at how they solved the problem and what code they used.
Just building on top what you have created you will have something similar to this:
footer {
width: 97%;
height: 40px;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
background-color: #141476;
margin: 2% 1.5%;
}
footer p,
.footerIcons{
line-height: 20px;
margin: 9px;
}
footer p{
float: left;
color: #3399FF;
}
.footerIcons {
float: right;
}
.footerIcons img.firefox,
.footerIcons img.safari,
.footerIcons img.chrome{
width: auto;
height: 23px;
}
<footer>
<p>Copyright © 2017 cowboyDesigns.com</p>
<div class="footerIcons">
<img class="chrome" src="images/icons/black-chrome-icon.png" alt="">
<img class="firefox" src="images/icons/black-firefox-icon.png" alt="">
<img class="safari" src="images/icons/black-safari-icon2.png" alt="">
</div>
</footer>
I have the following html:
<div id="img_holder">
<img id="image" src="../../images/img1.jpg" />
</div>
It has the following css:
#img_holder {
background-color:#EC0610;
min-height: 500px;
float:left;
width: 550px;
}
#image {
width: 300px;
height: 450px;
margin: auto;
padding-top: 20px;
}
The image's margins aren't being set but its padding is. Also, when I set the margin to a specific value, the margins work. When I use the element inspector in Google Chrome, that line in the styles window doesn't have a line through it so I'm assuming it's valid css. I just can't figure out why it won't get set to auto.
You need to set the image to display:block;
demo http://jsfiddle.net/mCen7/
#image {
width: 300px;
height: 450px;
margin: auto;
padding-top: 20px;
display: block;
}
I would appreciate you give us your actual objective.
As far as I understand, you simply want the img to be centered in your div.
img tags are inline tags, that is, share the behavior of a text or a letter. It's not a block, such as a div.
inline tags are horizontally centered like text, with a text-align: center style, as follows:
#img_holder {
background-color:#EC0610;
min-height: 500px;
float:left;
width: 550px;
text-align: center;
}
#image {
width: 300px;
height: 450px;
padding-top: 20px;
}
<div id="img_holder">
<img id="image" src="../../images/img1.jpg" />
</div>
I have a logo and text on the page and my items are floated left but this causes the bottom of the logo to cut off. No minus margins or paddings are used. Looking with XRAY and webdeveloper style finder I see that the img is getting cut short with no other elements around it, (it is just floated left). If I remove the float from the .logo the image appears whole, but larger and out of position
Here is the jsfiddle http://jsfiddle.net/9LGRx/ It seems to be a FF bug, works ok in Chrome and Safari.
html > body > header > div.wrapper > a.logo > img
HTML code
<header>
<div class="wrapper">
<a href="/" class="logo">
<img src="images/logo.png" alt="Showhouse logo">
</a>
<h1>Welcome to ShowHouse</h1>
<p class="text">
Show off your property management skills with ShowHouse - the only online property
management software that will effortlessly handle and help to improve every aspect of
your <strong>residential</strong> and <strong>commercial lettings</strong>, <strong>sales</strong> and <strong>block management</strong>.
</p>
</div>
</header>
SCSS Code
h1{
color: #fff;
float: left;
clear: both;
}
img{
max-width: 100%;
float: left;
}
header{
background-image: url('../images/header-bg.jpg');
float: left;
width: 100%;
/*height: 417px;*/
.logo{
float: left;
width: 60%;
margin: 20px 0 20px 0;
}
.logo img{
max-width: 100%;
}
.text{
float: left;
clear: both;
color: $color-white;
font-size: 1.2em;
margin-top: -10px;
}
}
Try adding this to your css:
.logo img{
max-width: 100%;
display: block;
height: 150px;
}
(put the real height of your image or the height you want to display)
I am trying to center an image that is located within a div, which is then located inside of another div. Not to worry, I will post some code so you can all see what the heck I'm talking about here.
HTML:
<div id="container">
<div id="featureimage" style="width: 845px">
<img src="Stylesheets/images/globkey.jpg" alt="" />
</div>
</div>
CSS:
body {
background-color: #383838;
margin: 0; padding: 0;
font-size: small;
color: #383838;
font-family: Verdana, Arial, Helvetica, sans-serif;
}
* html body {
font-size: x-small; /* for IE5/Win */
font-size: small; /* for other IE versions */
}
img {
border-style: none;
}
/* Conatiner */
#container {
background-color: #fff;
width: 845px;
margin: 0 auto;
overflow: hidden;
}
#featureimage{
width: 620px;
padding: 0 0 0 15px;
margin: 20px 0;
/* I have also tried without padding and no margin!*/
}
#featureimage img{
margin-left:50%;
margin-right:50%;
width:360px;
height:360px;
}
I am fresh out of ideas here! Been at this for ever!
Thank you for any help,
Evan
Images are inline elements, to center them, you can use text-align: center; or set them to display: block and set margin: 0 auto;
just for sure add text-align: center to your #container, and then add margin: 20px auto; to your featureImage. If you want img to be centered within featureImage should work (featureImage will inherit text-align: center).
According your provided markup structure it is enough to following way:
img {
display: block;
margin: 0 auto;
}
But above approach will work if container contain single image. Bu if container contain multiple image then above technique will not work anymore then following way would be ideal:
#featureimage {
text-align: center;
}
img {
display: inline-block;
vertical-align:top; // It is recommended when you use css property vertical-align
}
Use:
margin: auto !important;
display: block;
Also try going to Play Store download the app HTML code it will come in handy for you.
#featureimage{
width: 620px;
padding: 0 0 0 15px;
margin: 20px 0;
text-align:center;
}
I would try this css:
#featureimage{
width: 620px;
padding: 0 0 0 15px;
margin: 20px auto 0px auto;
text-align: center;
}
I may be totally off on this one, as I haven't tested it out.
i would use this for sure,, the absolute; will keep it in that spot if you want it to move with the page put fixed; but other than that boom
#featureimage {
width: "change this code to whatever expample..." 555px;
height: "change this code to whatever example..." 96px;
position: absolute;
top: "change this to where ever it centers , you just have to mess with it.. example..." 960px;
right: "same with this i had to put - to get it right as far as i could just play with it..." -945px;
}
It can also be solved by simple put a <center> tag:
<center>
<img src="abc.gif">
</center>
But the best way and html5-like is as mentioned next:
define in the header:
<style>
img {
display: block;
margin-left: auto;
margin-right: auto;
}
</style>
To make use of this class in the body:
<img src="abc.gif" alt="abc" style="width: 90%; max-width: 300px;>
That's all. The last method is that recomended by w3c.