HTML 和 CSS 背景定位一个图标

标签 html css icons css-position

我正在我的网站上工作,问题是我想设置一个纯粹由 css 制作的图标作为 te div“pagewrap”的背景,我似乎不知道自己做,所以我想你帮我解决这个问题。我将发布链接以获得更清晰的 View :http://i60.tinypic.com/312bc0p.png

这是 HTML:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" type="text/css" href="css/style.css">
<link href="css/media-queries.css" rel="stylesheet" type="text/css">

<title>Insert title here</title>
</head>
<body>
<!-- ### Page Wrap ### -->
<div id="pagewrap"> 

        <!-- ### Logo Bar ### -->
        <div id="logoBar">  
            <div class="helper">        
                <div class="logo"></div>
            </div>
        </div>

        <div style="clear:both;"></div>  
        <!-- ### Home Icon ### -->
        <div class="icon">
        <div class="home"></div>
        <div class="chimney"></div>
        </div>

        <!-- ### Side Bar ### -->
        <div id="sidebar">
            <div class="widget">
                <ul> 
                  <li style="border-top:0 !important;"><a href="">Acceuil</a></li> 
                  <li><a href="">Identification</a></li> 
                  <li><a href="">Mon Parcours</a></li> 
                  <li><a href="">Ma Formation</a></li> 
                  <li><a href="">Mes Projets</a></li> 
                  <li><a href="">Dossier de Veille</a></li> 
                  <li><a href="">Contact Me</a></li> 
                </ul>   
            </div>                  
        </div>

        <!-- ### Content ### -->
        <div class="contenu">
            <div class="post clearfix">                     
                    <h1 class="post-title"><a href="#">Acceuil</a></h1>                         
                <br/><p>Ici vous trouverez toutes les informations conçernant moi, mes études, mes projets et ma formation.</p>         
        </div>
</div>      
</div>          
</body>
</html>

这是CSS:

/************************************************************************************
STRUCTURE
*************************************************************************************/
#pagewrap {
    width: 1000px;
    margin: 0 auto;
    background:#3c3c3c;
    height:100vh;
    min-height:610px;

    /*SHADOW*/
    -webkit-box-shadow: 0 3px 3px 0px rgba(0,0,0,.4);
    -moz-box-shadow: 0 3px 3px 0px rgba(0,0,0,.4);
    box-shadow: 0 3px 3px 0px rgba(0,0,0,.4);
}

/* Home */
div.icon div.home {
    height: 0px;
    width: 0px;
    border-width: 16px;
    border-style: solid;
    border-color: transparent transparent #333 transparent;
    position: absolute;
    bottom: 16px;
    left: 0;
}

div.icon div.home:after {
    content: '';
    width: 5px;
    height: 16px;
    background-color: transparent;
    position: absolute;
    top: 16px;
    right: -11px;
    border-left: 8px solid #333;
    border-right: 8px solid #333;
}

div.icon div.home:before {
    content: '';
    width: 9px;
    height: 6px;
    background-color: #333;
    position: absolute;
    top: 16px;
    right: -5px;
}

div.icon div.chimney {
    width: 4px;
    height: 10px;
    background: #333;
    position: absolute;
    right: 6px;
    top: 3px;
}


/************************************************************************************
MENU
*************************************************************************************/



/**Side Bar**/
#sidebar {
    width: 250px;
    margin: 10px 30px 0 24px;
}
.widget {
    background: #f5f5f5;
    margin: 0 0 30px;
    padding: 10px 20px;
    /* rounded corner */
    -webkit-border-radius: 8px;
    -moz-border-radius: 8px;
    border-radius: 8px;
    /* box shadow */
    -webkit-box-shadow: 0 1px 3px rgba(0,0,0,.4);
    -moz-box-shadow: 0 1px 3px rgba(0,0,0,.4);
    box-shadow: 0 1px 3px rgba(0,0,0,.4);
}
.widget ul {
    margin: 0;
    padding: 0;
}
.widget li {
    margin: 0;
    padding: 12px 0;
    list-style: none;
    clear: both;    
    border-top: solid 1px black;
}
.widget ul li a{
    font-family:stainy;
    font-size:21pt;
    color:#303438;
}
.widget ul li a:hover{
    text-decoration: none;
    outline: none;
    color:#30c9e0;
    font-size:22pt;
}
.widgettitle{
    font-family:stainy;
    font-size:20pt;

}

最佳答案

困难的部分是什么?只需为您的 #pagewrap 添加 background-image 并调整定位和重复就足够了。

#pagewrap {
  background-image: url('YOUR_ICON');
  ...
}

另请查看此文档:https://developer.mozilla.org/en-US/docs/Web/CSS/background

关于HTML 和 CSS 背景定位一个图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22582459/

相关文章:

javascript - 如何在没有白色闪烁的情况下在背景上创建全屏淡入淡出幻灯片?

html - 分区 : make a semi-circular disc

css - Div 发生在另一个 div 之上?

ios - 如何将应用程序图标包含到我的 Xcode 项目中

javascript - 如果页面上不存在 Div 类,则显示 SweetAlert 弹出窗口

javascript - 将 onclick() 函数添加到使用 DOM 操作创建的复选框并将其作为参数传递

javascript - 尝试从表单输入 JS 生成变量时未捕获 RangeError 超出最大调用堆栈

html - 我可以包含外部 SVG defs

windows - 如何使用 python 2.7 移动 Windows 桌面图标?

javascript - 调整 div 大小时的 Bootstrap 堆叠输入