Hey guy's I've been trying out something different with my CSS backgrounds in order to make a header line. I want to have it set up so the line is made up of 5 equally sized portions with each portion being a different color. Here is an example
I have the code set up but I can't get the background to show up properly I have my code down below. Any help would be appreciated, thanks!
HTML:
<div id="div-line">
<div class="blockOne"></div>
<div class="blockTwo"></div>
<div class="blockThree"></div>
<div class="blockFour"></div>
<div class="blockFive"></div>
</div>
CSS:
#div-line {
width:100%;
height:5px;
}
.blockOne {
width:20%;
background-image:url(../images/orangeBlock.png);
background-repeat:repeat-x;
}
.blockTwo {
width:20%;
background-image:url(../images/blueBlock.png);
background-repeat:repeat-x;
}
.blockThree {
width:20%;
background-image:url(../images/darkOrangeBlock.png);
background-repeat:repeat-x;
}
.blockFour {
width:20%;
background-image:url(../images/orangeBlock.png);
background-repeat:repeat-x;
}
.blockFive {
width:20%;
background-image:url(../images/BlueBlock.png);
background-repeat:repeat-x;
}
You need to float the DIV elements and add height.
Working DEMO
Added a generic CSS class block in HTML:
<div id="div-line">
<div class="block blockOne"></div>
<div class="block blockTwo"></div>
<div class="block blockThree"></div>
<div class="block blockFour"></div>
<div class="block blockFive"></div>
</div>
and tweaked CSS:
#div-line {
width:100%;
height:5px;
}
.block {
height:100%;
float:left;
width:20%;
}
.blockOne {
background-color:red;
}
.blockTwo {
background-color:black;
}
.blockThree {
background-color:red;
}
.blockFour {
background-color:black;
}
.blockFive {
background-color:red;
}
You could achieve this by using background for color. And the reason why your divs are not showing up is because you need to give them a height and also you need to float them to the left.
#div-line div {
float:left;
}
#div-line {
width:100%;
height:5px;
}
.blockOne {
width:20%;
height:100%;
background:#00FFFF;
}
.blockTwo {
width:20%;
height:100%;
background:#FFA500;
}
.blockThree {
width:20%;
height:100%;
background:#00FFFF;
}
.blockFour {
width:20%;
height:100%;
background:#FFA500;
}
.blockFive {
width:20%;
height:100%;
background:#00FFFF;
}
Working sample here.
Why do you want to use background images where you can use background-color ?
You can offload the server atleast if you use background color.
.blockN {
width: 20%;
background-color: #0094ff; // or your color
}
Do something like this
.blockOne {
width:20%;
background-image:url(images/orangeBlock.png);
background-repeat:repeat-x;
}
.blockTwo {
width:20%;
background-image:url(images/blueBlock.png);
background-repeat:repeat-x;
}
.blockThree {
width:20%;
background-image:url(images/darkOrangeBlock.png);
background-repeat:repeat-x;
}
.blockFour {
width:20%;
background-image:url(images/orangeBlock.png);
background-repeat:repeat-x;
}
.blockFive {
width:20%;
background-image:url(images/BlueBlock.png);
background-repeat:repeat-x;
}
OR
.blockOne {
width:20%;
background-image:url(./images/orangeBlock.png);
background-repeat:repeat-x;
}
.blockTwo {
width:20%;
background-image:url(./images/blueBlock.png);
background-repeat:repeat-x;
}
.blockThree {
width:20%;
background-image:url(./images/darkOrangeBlock.png);
background-repeat:repeat-x;
}
.blockFour {
width:20%;
background-image:url(./images/orangeBlock.png);
background-repeat:repeat-x;
}
.blockFive {
width:20%;
background-image:url(./images/BlueBlock.png);
background-repeat:repeat-x;
}
The thing you are trying to do ie, background-image:url(images/orangeBlock.png) is used in linux.
Related
I am working on some side buttons for a project and would like the link the hover styles for both elements, but am not sure how to go about this. In the example below if I highlight the link name (search) it rolls over and changes to a red text and if I highlight the image, it changes to the rollover image as expected. However what I would like to achieve is to link both so when I hover over the icon the link changes to red as well and vice versa.
#linkchoice{
width:100px;
height:100px;
}
#image{
height:75px;
background-image:url(https://i.postimg.cc/P5nvVtPt/search-icon.png);
background-repeat:no-repeat;
background-size:75px 75px;
background-position:center;
}
#linkname{
font-size:15px;
text-align:center;
}
#image:hover{
background-image:url(https://i.postimg.cc/0jmDrrbB/search-icon-white.png);
}
#linkname:hover{
color:#EB0307;
}
<div id='linkchoice'>
<div id='image'></div>
<div id='linkname'>Search</div>
</div>
I have made a JSFiddle as well here
https://jsfiddle.net/bzsvgwp8/
Thanks
Just update your css from
#image:hover {
background-image: url(https://i.postimg.cc/0jmDrrbB/search-icon-white.png);
}
#linkname:hover {
color: #EB0307;
}
to
#linkchoice:hover #image {
background-image: url(https://i.postimg.cc/0jmDrrbB/search-icon-white.png);
}
#linkchoice:hover #linkname {
color: #EB0307;
}
You will see the combined hover effect !
The first solution could be to use the hover on the parent div:
#linkchoice {
width:100px;
height:100px;
}
#image{
height:75px;
background-image:url(https://i.postimg.cc/P5nvVtPt/search-icon.png);
background-repeat:no-repeat;
background-size:75px 75px;
background-position:center;
}
#linkname{
font-size:15px;
text-align:center;
}
#linkchoice:hover #image {
background-image:url(https://i.postimg.cc/0jmDrrbB/search-icon-white.png);
}
#linkchoice:hover #linkname {
color:#EB0307;
}
<div id='linkchoice'>
<div id='image'></div>
<div id='linkname'>Search</div>
</div>
in the second solution you can simplify the html using a single div, in this way:
#linkchoice{
width:100px;
height:100px;
}
#linkname{
height:75px;
background-image:url(https://i.postimg.cc/P5nvVtPt/search-icon.png);
background-repeat:no-repeat;
background-size:75px 75px;
background-position:top;
padding-top:75px;
font-size:15px;
text-align:center;
}
#linkname:hover{
background-image:url(https://i.postimg.cc/0jmDrrbB/search-icon-white.png);
color:#EB0307;
}
<div id='linkchoice'>
<div id='linkname'>Search</div>
</div>
I have a responsive site with a slideshow. I have set the slideshow to be 100% the width of the browser window, and that is working fine. The problem is, the slideshow is shifted a bit to the right, almost as if there is padding to the left of the image. The result is the user having to scroll to the right to see the entire slideshow. I have tried playing around with the attributes of the div and the slideshow itself, but with no luck. Any help with this issue is appreciated. Here is my CSS and HTML code:
CSS
html
{
background-color:#000000;
}
body
{
margin:0auto;
padding:0;
width:100%;
}
#header
{
margin:0auto;
padding-top:0.5%;
text-align:center;
}
#logo
{
margin:0auto;
max-width:186px;
max-height:123px;
padding-top:1%;
padding-bottom:15%;
text-align:center;
}
#banner
{
width:100%;
}
#home_content
{
width:100%;
padding-top:0.25%;
}
#history_content
{
width:100%;
padding-top:0%;
}
#home_slideshow
{
padding-top:1%;
display:flex;
justify-content:center;
}
#home_slideshow
{
padding-top:1%;
display:flex;
justify-content:center;
}
hr
{
border-color:#1BB7F2;
width:100%;
padding:0%;
}
#home_footer
{
width:100%;
margin-top:60%;
}
#history_footer
{
width:100%;
margin-top:155%;
}
.crossfadeHome>figure
{
animation:imageAnimation24slinearinfinite0s;
backface-visibility:hidden;
color:transparent;
opacity:0;
position:absolute;
text-alin:center;
width:100%;
z-index:0;
margin:0auto;
}
.crossfadeHome>figure:nth-child(1)
{
background-image:url('../photos/img_1.jpg');
background-repeat:no-repeat;
}
.crossfadeHome>figure:nth-child(2)
{
animation-delay:6s;
background-image:url('../photos/img_2.jpg');
background-repeat:no-repeat;
}
.crossfadeHome>figure:nth-child(3)
{
animation-delay:12s;
background-image:url('../photos/img_3.jpg');
background-repeat:no-repeat;
}
.crossfadeHome>figure:nth-child(4)
{
animation-delay:18s;
background-image:url('../photos/img_4.jpg');
background-repeat:no-repeat;
}
#keyframesimageAnimation
{
0%
{
animation-timing-function:ease-in;
opacity:0;
}
8%
{
animation-timing-function:ease-out;
opacity:1;
}
17%
{
opacity:1
}
25%
{
opacity:0
}
100%
{
opacity:0
}
}
.crossfadeHistory>figure
{
backface-visibility:hidden;
color:transparent;
opacity:0;
position:absolute;
text-alin:center;
width:100%;
z-index:0;
margin:0auto;
}
.crossfadeHistory>figure:nth-child(1)
{
background-image:url('../photos/history_1.jpg');
background-repeat:no-repeat;
}
.crossfadeHistory>figure:nth-child(2)
{
animation-delay:7s;
background-image:url('../photos/history_2.jpg');
background-repeat:no-repeat;
}
.crossfadeHistory>figure:nth-child(3)
{
animation-delay:14s;
background-image:url('../photos/history_3.jpg');
background-repeat:no-repeat;
}
.crossfadeHistory>figure:nth-child(4)
{
animation-delay:21s;
background-image:url('../photos/history_4.jpg');
background-repeat:no-repeat;
}
#keyframesimageAnimation
{
0%
{
animation-timing-function:ease-in;
opacity:0;
}
8%
{
animation-timing-function:ease-out;
opacity:1;
}
17%
{
opacity:1
}
25%
{
opacity:0
}
100%
{
opacity:0
}
}
HTML
<!DOCTYPEhtml>
<html>
<head></head>
<body id="body">
<!--HeaderSection-->
<div id="logo">
<img class="logo"src="graphics/logo.jpg"style="display:block;margin:0auto;width:100%;height:auto;max-width:225px;max-height:196px;vertical-align:top;"alt=""title="">
</div>
<div id="header">
<p id="contact_info">
<imgsrc="graphics/icon_phone.png"style="width:11px;height:15px;vertical-align:middle;"alt="PhoneIcon"title="Call Us!!">(518)459-9843
</p>
<pid="contact_info">
 
</p>
<p id="contact_info">
<img src="graphics/icon_clock.png"style="width:17px;height:17px;vertical-align:middle;"alt="ClockIcon"title="Our Hours">
</p>
</div>
<div id="banner">
<hr/>
<p id="page_home_header">
</p>
</div>
<div id="page_home_main">
<p id="home_content">
</p>
<p id="page_home_link">
link
<br/>
<br/>
site
</p>
</div>
<div id="home_slideshow"class="crossfadeHome">
<figure>
<img src="photos/img_1.jpg"style="width:100%;height:auto;"alt=""/>
</figure>
<figure>
<img src="photos/img_2.jpg"style="width:100%;height:auto;"alt=""/>
</figure>
<figure>
<img src="photos/img_3.jpg"style="width:100%;height:auto;"alt=""/>
</figure>
<figure>
<img src="photos/img_4.jpg"style="width:100%;height:auto;"alt=""/>
</figure>
</div>
<!--FooterSection-->
<footer id="home_footer">
<hr/>
<p id="footer_copyright">©<script>document.write(newDate().getFullYear())</script>mysite</p>
</footer>
</body>
</html>
Make sure you check typos in your code.
Change margin:0auto; to margin:0 auto; and text-alin:center; to text-align:center;.
If you want to know more about margin, click here.
To check errors in your css you can visit CSSLint.
I have this problem, I can't seem to figure out how do I make this red DIV not past through the div on the right side, I want to make it stay between the right and the left div menu.
Website Screenshot
HTML Code:
<body>
<div class="navigationBar_default">
<div class="facetubeLogo_default"></div>
<div class="facetubeText_container_default"><center><strong class="facetubeText_default"></strong></center></div>
</div>
<div class="content_default">
<div class="leftMenu_onProfile">
<button class="leftMenu_buttonOnProfile"><img class="leftMenu_buttonImage" src="images/myProfileButton_onLeftMenu_onProfile.png" /><br>MY PROFILE</button>
<button class="leftMenu_buttonOnProfile"><img class="leftMenu_buttonImage" src="images/optionsButton_onLeftMenu_onProfile.png" /><br>GENERAL</button>
<button class="leftMenu_buttonOnProfile"><img class="leftMenu_buttonImage" src="images/generalButton_onLeftMenu_onProfile.png" /><br>OPTIONS</button>
<button class="leftMenu_buttonOnProfile"><img class="leftMenu_buttonImage" src="images/supportUsButton_onLeftMenu_onProfile.png" /><br>SUPPORT US</button>
<button class="leftMenu_buttonOnProfile"><img class="leftMenu_buttonImage" src="images/logOutButton_onLeftMenu_onProfile.png" /><br>LOG OUT</button>
</div>
<!-- there must be some stuff here, otherwise leftMenu_onProfile will glitch out. -->
<div class="contentCenter_onProfile">
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAaaaaaaaaaaaaaaAAAAAAAAAAAAAAAAAA
</div>
<!-- there must be some stuff here, otherwise leftMenu_onProfile will glitch out. -->
<div class="rightMenu_onProfile">user1<br>user2<br>user3<br>user4<br>user5</div>
</div>
CSS Code:
.navigationBar_default {
background-color:#202020;
width:100%;
height:32px;
margin-left:-8px;
margin-right:-8px;
border:0;
top:0;
position:fixed;
}
.facetubeLogo_default {
background-image:url("../images/facetube_icon_30x30_png.png");
width:30px;
height:30px;
margin-top:1px;
margin-left:1px;
float:left;
}
.facetubeText_container_default {
margin-top:6px;
}
.content_default {
width:100%;
height:100%;
margin-top:32px;
margin-left:-8px;
margin-right:-8px;
margin-bottom:-8px;
}
.leftMenu_onProfile {
background-color:#0d0d0d;
margin-top:0px;
margin-left:-8px;
width:240px;
float:left;
}
.leftMenu_buttonOnProfile {
background-color:#0d0d0d;
border:0;
border-bottom:1px solid #ffffff;
width:240px;
height:48px;
color:#ffffff;
}
.leftMenu_buttonImage {
float:left;
margin-top:-2px;
margin-right:-6px;
}
.contentCenter_onProfile {
background-color:red;
padding:2px; /* padding is originally removed */
margin:0px;
top:0px;
}
.rightMenu_onProfile {
background-color:#0d0d0d;
margin-top:-20px;
margin-right:-16px;
width:300px;
color:#ffffff;
float:right;
}
I have feeling it has to do something with content_default and the width:100% but I don't know. I tried everything and I couldn't figure it out.
:/
Try this:
.contentCenter_onProfile {
background-color:red;
padding:2px; /* padding is originally removed */
margin:0 300px;
top:0px;
width: 50%; /* SET THIS */
white-space: pre-wrap;
word-break: break-all;
}
By setting the width, you can ensure the div does not overlap the right hand side div.
Setting float: left or float: right causes the elements to overlap.
I'm trying to make a div appear when the user hovers over another div. The problem is that the appearing div is neither a child nor a sibling of div the user should hover over. I made a jsfiddle to show what I mean here.
How do I make the #showMe appear when the user hovers over the #button?
#parent{
height:200px;
width:200px;
background-color:yellow;
}
#button{
height:100px;
width:100px;
background-color:blue;
}
#child, #sibling, #showMe{
height:50px;
width:50px;
background-color:red;
display:none;
}
#button:hover #child{
display:block;
}
#button:hover + #sibling{
display:block;
}
<div id="parent">parent
<div id="button">button<div id="child">child</div></div>
<div id="sibling">sibling</div>
</div>
<div id="showMe">showMe</div>
Well, your only option is to do it via Javascript
Javascript:
function showShowMe() {
document.getElementById("showMe").style.display = "block";
}
function hideShowMe() {
document.getElementById("showMe").style.display = "none";
}
#parent{
height:200px;
width:200px;
background-color:yellow;
}
#button{
height:100px;
width:100px;
background-color:blue;
}
#child, #sibling, #showMe{
height:50px;
width:50px;
background-color:red;
display:none;
}
#button:hover #child{
display:block;
}
#button:hover + #sibling{
display:block;
}
<div id="parent">parent
**<div id="button" onmouseover="showShowMe()" onmouseout="hideShowMe()">button<div id="child">child</div></div>**
<div id="sibling">sibling</div>
</div>
<div id="showMe">showMe</div>
Well, actually it is not possible to achieve that that by pure CSS and you'd use JavaScript.
But in this particular case we can somehow fake the effect by using adjacent sibling combinator + over the #parent instead, and giving a pointer-events of none to the parent and then re-setting the value of pointer-events to initial on the #button itself.
It's worth mentioning that pointer-events on HTML/XML elements is not supported in IE<=10.
Updated example
#parent{
height:200px;
width:200px;
background-color:yellow;
pointer-events: none;
}
#parent:hover + #showMe {
display: block;
}
#button{
height:100px;
width:100px;
background-color:blue;
pointer-events: initial;
}
#child, #sibling, #showMe{
height:50px;
width:50px;
background-color:red;
display:none;
}
#button:hover #child{
display:block;
}
#button:hover + #sibling{
display:block;
}
<div id="parent">parent
<div id="button">button<div id="child">child</div></div>
<div id="sibling">sibling</div>
</div>
<div id="showMe">showMe</div>
I just hit sth that appears to be a bug or at least a really weird feature of CSS/HTML.
Now, the problem is that i got three divs in a row, all inside a parent div.
The first and the second one are supposed to be text containers in a chat-like matter. The last one is supposed to be excluded and be a paging navigation.
On the very first page, that works fine. On every other page, the last text container div expands over the navigation. When using the Chrome developer tools, it shows me that the second div is only having its real size, while the background still expands over the navigation. But if i delete the navigation, the second text container resizes to its real size.
Also, when using
position:absolute;
it doesn't expand. Setting the position to relative explicitly didn't fix the problem and setting the background-color to sth else didn't change the white background.
I made you a quick demonstration under jsfiddle.net.
So the final question is: Why does the second text div expand? Or doesn't it but it looks like it does?
//edit: As suggested in the comments, here is the raw CSS/HTML outside jsfiddle. I still don't think that's a good idea, but if you say so..
<div class="decoded_chat" pagenr="1" style="display: block;">
<div class="decoded_user decoded_user_first" isme="0">
<a href="https://www.facebook.com/4" target="_new" title="Profil aufrufen">
<img class="decoded_user_avatar" src="http://graph.facebook.com/4/picture?type=square">
<div class="decoded_user_name">
Zuckerberg
</div>
</a>
<div class="decoded_msg_date">
02.02.2014, 01:36 Uhr
</div>
<div class="decoded_msg">
I will listen to the songs when I'm not so tired
</div>
<div class="decoded_msg">
I don't know.. Possibly
</div>
<div class="decoded_user decoded_user_last" isme="0">
<a href="https://www.facebook.com/4" target="_new" title="Profil aufrufen">
<img class="decoded_user_avatar" src="http://graph.facebook.com/4/picture?type=square">
<div class="decoded_user_name">
Zuckerberg
</div>
</a>
<div class="decoded_msg_date">
02.02.2014, 01:33 Uhr
</div>
<div class="decoded_msg">
I've been ill all week.. Just haven't had time for much
</div>
<div class="decoded_chat_pager">
<a href="javascript:void(0);" pagenr="0" class="cloudview_msg_prev">
« Vorherige Seite
</a>
<a href="javascript:void(0);" pagenr="2" class="cloudview_msg_next">
Nächste Seite »
</a>
</div>
</div>
a {
text-decoration: none;
color: white;
}
.chat_list {
width:100%;
}
.decoded_chat {
text-align:left;
width:100%;
margin:auto;
background-color:white;
color:black;
border-radius:10px;
}
.cloudview_msg_next {
float:right;
}
.decoded_chat_pager {
margin:auto;
margin-top:5px;
text-align:left;
width:95%;
}
.decoded_msg {
margin-bottom:3px;
}
.decoded_user {
padding:15px 10px;
min-height:50px;
}
.decoded_user_last {
border-bottom-left-radius:10px;
border-bottom-right-radius:10px;
}
.decoded_user_first {
border-top-left-radius:10px;
border-top-right-radius:10px;
}
.decoded_user_name {
color:black;
margin-bottom:5px;
}
.mychatmessage {
background-color:#BFF2BF;
}
.decoded_msg_date {
float:right;
color:grey;
margin-top:-30px;
}
.decoded_user_avatar {
position:absolute;
}
.decoded_user_name {
font-weight:bold;
}
.decoded_user_name, .decoded_msg {
margin-left:64px;
}
table {
text-align:center;
}
.flipped-180 {
-moz-transform: scaleX(-1);
-o-transform: scaleX(-1);
-webkit-transform: scaleX(-1);
transform: scaleX(-1);
filter: FlipH;
-ms-filter:"FlipH";
}
#detailopener, #return_to_msg, #return_to_cloud, #cloudview_delete {
display:none;
}
.chat_list_names {
color:grey;
}
.invi {
position:fixed;
width:1px;
height:1px;
top:-2000px;
left:-2000px;
}
.next_page_chat_list {
text-align:right;
padding-right:5px;
}
.last_page_chat_list {
padding-left:5px;
text-align:left;
}
.loadingtext {
margin-top:7px;
}
#opener {
position:fixed;
left:25px;
bottom:25px;
cursor:pointer;
display:none;
}
.dontdroponme {
opacity:0.3;
}
#dropper {
position:fixed;
right:25px;
bottom:25px;
cursor:pointer;
display:none;
}
.dropinfo {
border-radius:7px;
color:white;
padding:5px 25px;
}
.dorpinfo img {
width:48px;
}
.chatlist_button img, .decoded_user_avatar {
box-shadow:0 0 5px #888;
border-radius:5px;
}
.chatlist_button {
background-color:white;
border-radius:5px;
box-shadow:0 0 5px #888;
padding:5px;
cursor:move;
max-width:200px;
margin:auto;
}
.ui-draggable-dragging {
position:absolute;
z-index:5;
}
body {
height:100%;
margin:0;
background-color:#3B5998;
color:white;
font-size:12px;
font-family:Calibri;
}
#innerbody {
margin:auto;
width:55%;
text-align:center;
}
#innerbody_floater {
height:50%;
width:100%;
margin:0;
}
Copy from http://www.w3schools.com/css/css_positioning.asp
An absolute position element is positioned relative to the first parent element that has a position other than static. If no such element is found, the containing block is html: