I am trying to create a base div where I can copy it as many times as I need for when I want to add new content to my website. So the Html looks like this:
<div class="post">
<p class="date">17/03/1014</p>
<h1>Hello World!</h1>
<p class="postText">djdfkjdfssdfldfskjldfskjldfskjldsfkjldsfjkldsjkldjkl
</p>
</div>
<div class="postImage"><img src="images/car.jpg" width="300" alt="car></div>
Then my css looks like this:
.post{
width:960px;
margin:0 auto;
color:#000;
background-color:#CCC;
font-family:Verdana, Geneva, sans-serif;
/*CSS3*/
-webkit-border-radius:10px;
-moz-border-radius:10px;
border-radius:10px;
-webkit-outline: 1px dashed #000000;
-moz-outline: 1px dashed #000000;
outline: 1px dashed #000000;
-webkit-outline-offset: -5px;
-moz-outline-offset: -5px;
outline-offset: -5px;
behavior:url(PIE.htc);
}
.post p.postText {
width:500px;
padding-left:10px;
padding-bottom:10px;
}
.post p.date{
font-family:Verdana, Geneva, sans-serif;
font-size:12px;
padding-top:10px;
padding-left:10px;
}
.postImage {
display:block;
float:left;
}
If you test it, the image doesn't float on the right of the text, but instead is below it. Any ideas on what is happening?
Try to start simple - get your positioning correct first, then add in the padding, borders, /CSS3/ stuff. http://jsfiddle.net/bEECn/
There are many ways to accomplish this, but I think wrapping your textual content in a container and floating that may be the most straight forward for you.
<div class="post">
<div class="content-wrap">
<p class="date">17/03/1014</p>
<h1>Hello World!</h1>
<p class="postText">djdfkjdfssdfldfskjldfskjldfskjldsfkjldsfjkldsjkldjkl</p>
</div>
<div class="postImage">
<img src="http://lorempixel.com/300/300" width="300" alt="car" />
</div>
</div>
Then, this simple CSS:
.content-wrap, .postImage {
float: left;
}
From there, you can add your additional styles.
If that is your exact HTML, you have several errors. Not sure if that will completely fix your problem, but you need to fix your HTML either way.
<div class="post">
<p class="date">17/03/1014</p> <!-- Was </div> -->
<h1>Hello World!</h1> <!-- Was </div> -->
<p class="postText">djdfkjdfssdfldfskjldfskjldfskjldsfkjldsfjkldsjkldjkl</p>
</div> <!-- Was missing -->
<div class="postImage">
<img src="images/car.jpg" width="300" alt="car>
</div>
I made a JSFiddle for you.
http://jsfiddle.net/FRDKL/
I found allot of HTML errors for example:
<img src="images/car.jpg" width="300" alt="car>
U forgot an " at the end of your ALT. I hope this helps:
http://jsfiddle.net/FRDKL/
Related
I'm a high school senior working on app development for an engineering senior project and I've run into a little block with the HTML/CSS. I created an initial prototype for the app using Adobe XD, and it looks a little like this:
https://i.stack.imgur.com/K4V3G.png
The initial dimensions for the header and footer elements in the prototype are 70px high, however, when I put this in my CSS and run a mobile emulator, it turns out looking more like this:
https://i.stack.imgur.com/1YcFe.png
I also tried converting to em/rem, but that didn't help. I know mobile screens have a higher pixel density than laptops/desktops but I don't know how much higher. Does anyone have any suggestions for getting the header and footer elements to be the proper height on the screen?
EDIT: Including HTML/CSS in question for reference
CSS:
body{
font-family: 'Roboto', sans-serif;
height:100vh;
width:100vw;
padding:0;
}
wrapper{
margin: 0 auto;
padding: 0;
clear:both;
}
#head{
width:100%;
height:4.313rem;
font-size:40pt;
background-color:#fafafa;
text-align:center;
color:#707070;
}
#divider{
width:100%;
height:0.063rem;
background-color:#e0e0e0;
}
#midcontainer{
width:100%;
height:calc(100% - 8.75rem);
background-color:#fafafa;
overflow:hidden;
margin:0;
padding:0;
}
#midscroll{
width:calc(100% + 20px);
height:calc(100% - 8.75rem);
overflow:auto;
margin:0;
padding:0;
}
#midbody{
width:100%;
min-height:calc(100% - 8.75rem);
font-size:12pt;
text-align:justify;
}
#foot{
width:100%;
height:4.375rem;
background-color:#e0e0e0;
}
HTML:
<template name="Home">
<div align="center" style="height:100vh;width:100vw;position:absolute;top:0;left:0;border:1px solid transparent;">
<div id="head">
<p style="position:relative;top:50%;transform:translateY(-50%);">Upcoming Tasks</p>
</div> <!--end head-->
<div id="divider">
</div> <!--end divider-->
<div id="midcontainer">
<div id="midscroll">
<div id="midbody">
<p style="padding-left:0.313rem;padding-right:0.313rem;">
*Body elements here*
</p>
</div> <!--end midbody-->
</div> <!--end midscroll-->
</div> <!--end midcontiner END OF MIDDLE CONTENT-->
<div id="foot">
<img id="Home" style="height:4.375rem;width:4.375rem;padding-right:1.125rem;" src="https://imgur.com/C5zD29C.png">
<img id="Create" style="height:4.375rem;width:4.375rem;padding-right:1.188rem;" src="https://imgur.com/5UhZ0e9.png">
<img id ="Calendar" style="height:4.375rem;width:4.375rem;padding-right:1.125rem;" src="https://imgur.com/nUTj5zs.png">
<img id="Achievements" style="height:4.375rem;width:4.375rem;" src="https://imgur.com/4WrWF7T.png">
</div> <!--end foot-->
</div>
</template>
Try adding this into the <head> of your HTML
<meta name="viewport" content="width=device-width, initial-scale=1.0">
I've have the horizontal line start a third way through the webpage, but getting the line to move down a bit (maybe 200-400px?) is giving me a real pain. And whenever i try to use "top:-200px;" within the style element (midline) it just makes half of the line disappear
<html>
<header>
<style>
.divider{
position:absolute;
left:33.3%;
top:0%;
bottom:0%;
border-left:5px solid black;
}
.divider2{
position:absolute;
left:66.6%;
top:0%;
bottom:0%;
border-left:5px solid black;
}
#left {
width:380px;
float:left;
margin-left: 100px
}
#middle {
width:380px;
float:right;
text-align:center;
margin-right: 300px
}
#right {
width:380px;
float:right;
margin-left: 40px
}
#midline{
position:relative;
left:530px;
width:1265px;
height:5px;
background: black;
}
</style>
</header>
<body style="background-image: url(https://www.planwallpaper.com/static/images/Cool-Wallpapers-Background-HD-Wallpaper.jpg);" >
<div id="left">
<font color="white">
<p>
<h1> Greetings!</h1>
</p>
<font size="6", color="white">
<h3>Welcome to my world ;D </h3>
<p>
Heres a little information about me
</p>
<p>
A photo of me VV
</p>
<div id="midline"></div>
<p>
<a href="https://www.facebook.com/shan.kulkarni.9">
<img src=file:///C:/Users/shank/Desktop/Website/02f8a12b-3edf-4a4f-981c-860f7c7c3b07.jpg Width="350" height="500" />
</a>
<p>
Click on it and you'll go to my Facebook
</p>
<p>
Follow me on instagram while you're at it ;o
</p>
</div>
<div class="divider2"></div>
<div id="right">
<h2> My Hobbies </h2>
</div>
<div class="divider"></div>
<div id="middle">
<h2> Favorite Quotes</h2>
</div>
</font>
</body>
</html>
Here is the code:
https://jsfiddle.net/fjzcwfyx/
Leave out the bottom setting and set top: 200px; (not minus, but plus - that's the distance to the top). BTW: top AND bottom in one rule is too much, one of them is sufficient.
I have a title with html code:
<div id="site-title">
<a rel="home" > book Journey</a>
</div>
No i want to insert a small pic infront of this book journey, how can i do it.
You can use <span> inline elements to work with text along with images
HTML
<div id="site-title">
<a rel="home" ><img src="imageurl"/><span>book Journey</span></a>
</div>
CSS
img,span{
vertical-align:middle;
}
Fiddle
Why don't you use an Image tag for the link.
<img src="/path_to_img"/><span>book journey</span>
Try this:
<div id="site-title">
<a rel="home" >
<img style="float:left;" src="path-of-your-image/image.jpg" />
book Journey
</a>
</div>
Here is the answer you asked for ,
http://jsfiddle.net/Manjuboyz/vJS4m/133/
<div id="first">
<div id="text"> Book Journey
</div>
<div id="img"><img src="~/Images/doctor-landing.png" style="height: 100%; width: 100%;" </div>
</div>
CSS for above
#first{
height:35px;
width:150px;
border:1px solid brown;
}
#text{
height:30px;
width:100px;
border:1px solid black;
float:left;
}
#img{
height:30px;
width:30px;
margin-left:110px;
border:1px solid teal;
}
NOTE:
Change the image to left or right as you needed
UPDATE
Responsive Screen
HTML/CSS newbie question for you.
I've been stuck on this for awhile. I'm looking to center my image gallery AND also make the padding between the images tighter. I'm thinking I need a container but, I've just been screwing it all up when I try. Any help would be great!
<div id="container" align="center">
<div class="img">
<a href="#">
<img src="#" alt="PIcture1" width="210" height="180">
</a>
<div class="desc">BLAH</div>
</div>
<div class="img">
<a href="#">
<img src="Images/9700_1915630577543_1314909545_n.jpg" alt="oldman" width="210" height="180">
</a>
<div class="desc">BLAH</div>
</div>
<div class="img">
<a href="#">
<img src="#" alt="Picture3" width="210" height="180">
</a>
<div class="desc">BLAH</div>
</div>
<div class="img">
<a href="#">
<img src="#" alt="Picture4" width="210" height="180">
</a>
<div class="desc">BLAH</div>
</div>
</div>
CSS:
#container{
}
div.img
{
margin:5px;
padding: 5px;
border:none;
height:auto;
width:auto;
float:left;
text-align:center;
}
div.img img
{
display:inline;
margin:5px;
border:none;
}
div.img a:hover img
{
border:none;
}
div.desc
{
text-align:center;
font-weight:normal;
width:120px;
margin:5px;
}
It depends on how you want to centre your gallery.
There's a few things that you need to bear in mind. In order to centralise some HTML you need to have a set width of the centralising element.
Here's some code for you to work with:
Create a "centre" class in CSS as follows:
div.centre{
margin:0px auto;
width:800px;
}
Then add it to your container as follows:
<div id="container" class="centre">
The secret to centralisation is in the margin:0px auto;, this is convention of modern web development to centralise content.
Have a look at this code
p.s. don't use align="center" it is depreciated in later versions of HTML. Better to not get into the habit of using it and stick to using CSS classes to centralising things for you.
You should not use align. It is a deprecated property. To center something with a container you need to specify a fixed width and add margin auto.
Ex:
#container {
width:970px;
margin: 0 auto;
}
You can remove the padding on div.img
What's the best way to add a caption below an image? The image and its caption will be floated right, and the text on the caption needs to wrap -- a 200x200px image shouldn't have a caption of width 800px.
I would strongly prefer a solution that allows me to update images (with different widths) without changing the CSS or markup.
For reasons beyond my control the image itself will also be floated right, but this should not be too problematic.
The image code is
<div class="floatright">
<img alt="foo" src="bar.png" height="490" border="0" width="800">
</div>
and I can wrap this with HTML/CSS as needed. No JS on this page.
figure {
display: table;
}
figcaption {
display: table-caption;
caption-side: bottom;
}
<figure>
<img src="https://picsum.photos/200/50" />
<figcaption>This is a caption of slightly longer length. It should wrap, regardless of the size of the image.</figcaption>
</figure>
You can substitute figure and figcaption for div and p, or whatever other containers float your semantic boat.
Shameless plug: I blogged about this problem and my solution here, if you're interested.
Something like this: http://jsfiddle.net/QLcRC/ ?
You may use also use the HTML5 figure and figcaption elements and style those as #Wasim suggested.
<figure>
<img src="/test.jpg" alt="a test-image">
<figcaption>Description</figcaption>
</figure>
Another (not-so-cross-browser-savvy) approach is to use the img title-attribute and insert it as a pseudo-element via CSS:
#content img[title]:after {
content: "[" counter(image) "] " attr(title);
counter-increment: image;
display: block;
text-align: center; }
The basic idea is to make one <div> with an <img> tag and <p> tag.
<div class="photo">
<img src="someimage.jpg">
<p>my caption
</div>
Now you simply set two styles. One for the img tag and the other for the p tag for the photo class.
Create a class name it photo:
.photo {float: right;width: 210px;margin: 0 10px 10px 10px;}
img.photo {float: right;margin-left: 10px;margin-bottom: 10px;border: 1px solid #666;
padding: 10px;}
Conclusion:
1. A div with an <img> tag and a <p> tag.
2. Div should have one class with different styles for <p> and <img> tag.
Pure HTML/CSS inline styled.
<div style="width:40%;
margin-right:6%;
float: left;">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/2/26/Papilio_machaon_Mitterbach_01.jpg/500px-Papilio_machaon_Mitterbach_01.jpg" width="100%">
<p style="color:gray;
background-color:#eee;
margin-top:-4px;
width:100%;
height:auto;
padding-top:10px;
padding-bottom:10px;
text-align:center;">
<span style="padding-right:10px;
padding-left:10px;"> Butterfly </span></p>
</div>
<!-- NEXT ONE -->
<div style="width:40%;
float: left;">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/2/26/Papilio_machaon_Mitterbach_01.jpg/500px-Papilio_machaon_Mitterbach_01.jpg" width="100%">
<p style="color:gray;
background-color:#eee;
margin-top:-4px;
width:100%;
height:auto;
padding-top:10px;
padding-bottom:10px;
text-align:center;">
<span style="padding-right:10px;
padding-left:10px;"> Butterfly </span></p>
</div>
<div style="clear:all;"></div>
<!-- NEXT ROW -->
<div style="width:40%;
margin-right:6%;
float: left;">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/2/26/Papilio_machaon_Mitterbach_01.jpg/500px-Papilio_machaon_Mitterbach_01.jpg" width="100%">
<p style="color:gray;
background-color:#eee;
margin-top:-4px;
width:100%;
height:auto;
padding-top:10px;
padding-bottom:10px;
text-align:center;">
<span style="margin-top:0px;
padding-right:10px;
padding-left:10px;"> Butterfly </span></p>
</div>
<!-- NEXT ONE -->
<div style="width:40%;
float: left;">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/2/26/Papilio_machaon_Mitterbach_01.jpg/500px-Papilio_machaon_Mitterbach_01.jpg" width="100%">
<p style="color:gray;
background-color:#eee;
margin-top:-4px;
width:100%;
height:auto;
padding-top:10px;
padding-bottom:10px;
text-align:center;">
<span style="padding-right:10px;
padding-left:10px;"> Butterfly </span></p>
</div>
<div style="clear:all; height:100px;"> </div>
This is a known problem with current browsers. atlavis solution is the most simple. Until all browsers implement figure tag, then Feeela's way would work. But even then it would not be backwards compatible. I searched this issue for 3 days straight and I really hate the guys that made CSS decided to strip tables which were backwards compatible.
You could use the display: table-cell property on the class. But that is not supported by IE 6 or 7.