如何将文本放在div标签下面?

时间:2015-05-30 20:44:39

标签: html css

我已经使用div在表格的两边制作了两个图像,但是一旦div结束,我输入<p>的文本出现在div上方,尽管后面的代码。我希望文本显示在表格下方。 这是我的代码。

<!Doctype html>
<html>
<head>
<link rel = "stylesheet" type = "text/css" href="website.css"/>
<title> Stoge Guitars </title>
</head>
<body>
<div id = "container">
    <div id = "X">
        <img src= "images/workshop.png" id = "guitar">
    </div>
    <div id = "C">  
        <img src= "images/workshop.png" id = "guitar2">
    </div>
    <div id = "V">  
        <table>
        <tr>
            <th colspan = "5" id = "STOGEGUITARS"> STOGE GUITARS </th>
        </tr>
        <tr>
            <th>Home</th>
            <th>Our Custom Guitars</th>
            <th>Forum</th>
            <th>Workshop Gallery</th>
            <th>Contact Us</th>
        </tr>
        </table>
    </div>
    </div>
<p> This should be below the table </p> 
</body>

CSS

body
{
Background-image:     url("http://images.epiphone.com.s3.amazonaws.com/Products/Les-Paul/Les-Paul- Standard-Plustop-PRO/Gallery/POP_LPSTDPLUSPRO-HB.jpg");
background-size: 100% 100%;
background-repeat: no-repeat;
background-size: cover;
}
#STOGEGUITARS
{
font-size: 20pt;
font-family: "Times New Roman", Times, serif;
font-style: italic;
}
table, th, td
{
border: 1px solid black;
}
table
{
width: 60%;
margin-left: 20%;
margin-right: 20%;
position: fixed;
}
#guitar
{
float: left;
 }
#guitar2
 {
float: right;   
}
 #guitar
{
width: 19%;
height: 100%;
position: fixed;
 }
 #guitar2
{
width: 19%;
height: 100%;
position: fixed;
 right: 0px;
}
p
{
border: 0px;
text-align: left;
}

非常感谢帮助谢谢。对不起,如果我犯了一个愚蠢的错误,我只有16岁,不熟悉HTML和CSS。

2 个答案:

答案 0 :(得分:1)

检查此fiddle

position: relative;

是您正在寻找的,固定位置使其他元素忽略元素的位置

答案 1 :(得分:0)

我修改了你的HTML和CSS代码:

JSFiddle

<强> HTML

<center>
<div id = "container">
    <div id = "X">
        <img src= "https://fedoraproject.org/w/uploads/6/66/Artwork_F9Themes_Shoowa_shoowa-horizontal.png" id = "guitar" />
    </div>
    <div id = "V">  
        <table>
        <tr>
            <th colspan = "5" id = "STOGEGUITARS"> STOGE GUITARS </th>
        </tr>
        <tr>
            <th>Home</th>
            <th>Our Custom Guitars</th>
            <th>Forum</th>
            <th>Workshop Gallery</th>
            <th>Contact Us</th>
        </tr>
        </table>
        <p> This should be below the table </p>
    </div>
    <div id = "C">  
        <img src= "https://fedoraproject.org/w/uploads/6/66/Artwork_F9Themes_Shoowa_shoowa-horizontal.png" id = "guitar2" />
    </div>
    </div>
</center>

<强> CSS

body
{
Background-image:     url("http://images.epiphone.com.s3.amazonaws.com/Products/Les-Paul/Les-Paul- Standard-Plustop-PRO/Gallery/POP_LPSTDPLUSPRO-HB.jpg");
background-size: 100% 100%;
background-repeat: no-repeat;
background-size: cover;
margin:0;
}
#STOGEGUITARS
{
font-size: 20pt;
font-family: "Times New Roman", Times, serif;
font-style: italic;
}
table, th, td
{
border: 1px solid black;
}
table
{
width:100%;
}
#X
{
display:inline-block;
position: fixed;
left:0px;
top:0px;
width: 19%;
height: 100%;
}

#V
{
margin:0;
display:inline-block;
top:0px;
width: 62%;
height: 100%;   
border:1px solid red; /* Remove this line it's just for checking boundaries  */
}

#C
{
display:inline-block;
position: fixed;
right:0px;
top:0px;
width: 19%;
height: 100%;
}

img
{
    width:100%;
    height:100%;
}

p
{
position:relative;
text-align:left;
}