Put div on bottom of div - html

I have a div with a margin containing an image. I want to put another div inside that div and position it to the bottom of the parent div (Like even to the margin). However I'm unable to do that.
.headermario {
background-image: url("resources/banner.png");
background-size: 600px;
background-repeat: no-repeat;
background-position: bottom;
background-color: red;
height: 200px;
width: 90%;
margin-bottom: 100px;
border-style: solid;
border-width: 10px;
}
.topnav {
overflow: hidden;
display: flex;
justify-content: center;
}
.topnav a {
float: left;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}
.topnav a:hover {
background-color: #ddd;
color: black;
}
<div class="marioHeader">
<h1 class="title">Super Mario</h1>
<div class="headermario">
<div class="topnav">
About
History
</div>
</div>
</div>
It looks like this:
But I want it to look like this:

css solution would be like:
.headermario {
background-image: url("resources/banner.png");
background-size: 600px;
background-repeat: no-repeat;
background-position: bottom;
background-color: red;
height: 200px;
width: 90%;
position: relative;
margin-bottom: 100px;
border-style: solid;
border-width: 10px;
}
.topnav {
overflow: hidden;
display: flex;
justify-content: center;
position: absolute;
bottom: -40px;
}
otherwise you also could place the .topnav in the .marioHeader (pull it out of the .headermario class) and adjust it there. But to write this I require styling information of the .marioHeader class

The easiest way I can think of is with flex
.headermario {
background-image: url("resources/banner.png");
background-size: 600px;
background-repeat: no-repeat;
background-position: bottom;
background-color: red;
height: 200px;
width: 90%;
margin-bottom: 100px;
border-style: solid;
border-width: 10px;
display: flex;
flex-direction: column-reverse
}

Related

how do i get this background image to be in the center of the header?

header {
background-image: url('tiredBOX.jpg');
border: solid 3px orange;
height: 200px;
width: 200px;
border-radius: 50%;
padding: 30px;
}
}
h1 {
text-align: center;
color: orange;
background-color: lightgrey;
border: dotted white 4px;
margin-right: 600px;
margin-left: 600px
}
body {
background-color: teal;
}
have i gone about this wrong or is there a simple bit of code to get the background image and border etc into the center of the header area?
You can use margin: auto; under the header.
To center background Image:
background-position: center;
header {
background: url(https://images.pexels.com/photos/210205/pexels-photo-210205.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1) center center no-repeat;
border: solid 3px orange;
height: 200px;
width: 200px;
border-radius: 50%;
padding: 30px;
}
h1 {
text-align: center;
color: orange;
background-color: lightgrey;
border: dotted white 4px;
/* margin-right: 600px;
margin-left: 600px;*/
}
body {
background-color: teal;
}
<header>
<h1>Answer</h1>
</header>
try:
background-size: contain; // or cover depending on your preference
background-repeat: no-repeat;
background-position: center center;

How can I bring my div to the foreground with its background color?

#Preface I am relatively new to HTML and CSS if this has been answered elsewhere I would appreciate direction to something that gives me a solution.
Below is the code I have, I want the .Divclass to appear infront of my backround element with it's red background.
* {
background-image: url(https://www.pixelstalk.net/wp-content/uploads/2016/05/Treugolnik-triangle-illuminati-Wallpapers-High-Resolution.jpg);
background-repeat: no-repeat;
background-attachment: fixed;
background-position: center;
background-size: 1960px 1080px;
}
.divclass {
height: 230px;
width: 300px;
margin: 0px;
padding: 0px;
color: red;
border: solid 1px rgb(253, 253, 253);
text-align: center;
font-size: x-large;
}
Check the below snippet. The div is in front of the background image with a red background.
Let me know if this is what your desired output is
section {
background-image: url(https://www.pixelstalk.net/wp-content/uploads/2016/05/Treugolnik-triangle-illuminati-Wallpapers-High-Resolution.jpg);
background-repeat: no-repeat;
background-attachment: fixed;
background-position: center;
background-size: 1960px 1080px;
padding: 10px;
}
.divclass {
height: 230px;
width: 300px;
margin: 0px;
padding: 0px;
background-color: red;
border: solid 1px rgb(253, 253, 253);
text-align: center;
font-size: x-large;
}
<section>
<div class="divclass">Hi</div>
</section>
*{
background-image: url('https://www.pixelstalk.net/wp-content/uploads/2016/05/Treugolnik-triangle-illuminati-Wallpapers-High-Resolution.jpg');
background-repeat: no-repeat;
background-attachment: fixed;
background-position: center;
background-size: 1960px 1080px;
}
.divclass {
height: 230px;
width: 300px;
/*color: red; This only makes the text color red */
background: #f00;
border: solid 1px rgb(253, 253, 253);
display: flex;
align-items: center;
justify-content: center;
font-size: x-large;
}
<div class=divclass> Hi </div>
Note the display: flex that was added to center the text, rather than using text: center which won't center it vertically.

Can't set up image in the div

I'd like to have a div, which contains:
Text on the top
Some image below it
How I may make it? Here's what I did so far
.container {
text-align: center;
display: inline-block;
width: 100%;
height: 180pt;
border: 1px solid red;
}
.text {
width: 12%;
height: 180px;
text-align: left;
background-color: yellow;
margin: 20px;
}
.text p {
font-size: 20px;
margin-left: 0 auto;
margin-right: 0 auto;
margin-top: 15px;
text-align: center;
}
.image {
width: 100%;
height: 100%;
display: inline-block;
background-image: url("url_to_img");
background-size: cover;
background-repeat: no-repeat;
}
<div class="container">
<div class="text">
<p>Lorem</p>
<div class="image"></div>
</div>
</div>
For now, the <p> is working just fine, but I have struggle with the image it's sticking out the borders of container div.
It's because you gave the test class too much margin. try not to mix up size units if possible.
add overflow:hidden; on .text class
.container {
text-align: center;
display: inline-block;
width: 100%;
height: 180pt;
border: 1px solid red;
}
.text {
width: 19%;
height: 180px;
text-align: left;
background-color: yellow;
margin: 10px;
overflow:hidden;
}
.text p {
font-size: 20px;
margin-left: 0 auto;
margin-right: 0 auto;
margin-top: 1px;
text-align: center;
}
.image {
width: 100%;
height: 100%;
display: inline-block;
background-image: url("https://avatars.mds.yandex.net/get-pdb/1380368/3e559dd1-32ad-4226-aac5-77ed3782a962/s1200");
background-size: cover;
background-position:center;
background-repeat: no-repeat;
}
<div class="container">
<div class="text">
<p>Lorem</p>
<div class="image"></div>
</div>
</div>
Here is a fiddle to get you started with, I didn't change much code because I didn't new your requirements Just did workaround around same code
https://jsfiddle.net/junaidmasoodi/vctwu2g5/11/
.text {
width: 100%;
height: 180px;
text-align: left;
background-color: yellow;
margin: 20px;
}
.text p {
font-size: 20px;
margin-left: 0 auto;
margin-right: 0 auto;
margin-top: 15px;
text-align: center;
}
.image {
width: 100%;
height: 100%;
display: block;
background-image: url("https://309w5s255371fs4df2vftgbl-wpengine.netdna-ssl.com/wp-content/uploads/2017/09/placeholder.jpg");
background-size: cover;
background-repeat: no-repeat;
}
for your .image block you could try background-size: contain; instead of cover

One div with input and other div inside

how can I get the input aligned with the div #submitKeyword ?
FIDDLE
HTML:
<div class="searchKeywords">
<input id="inputKeyword" type="text" name="keywords" placeholder="What are you looking for?">
<div id="submitKeyword"></div>
</div>
CSS:
.searchKeywords {
height: 100%;
width: 100%;
margin-top: 70px;
text-align: center;
}
.searchKeywords #inputKeyword {
display: inline-block;
height: 45px;
width: 150px;
border: 2px solid;
}
.searchKeywords #submitKeyword {
display: inline-block;
width: 115px;
height: 45px;
border: 1px solid #000;
background-image: url('/www/assets/newImages/gallery/Lupa.png');
background-repeat: no-repeat;
background-position: center;
}
Use vertical-align: middle;
.searchKeywords {
display: inline-block;
height: 100%;
width: 100%;
margin-top: 70px;
text-align: center;
vertical-align: middle;
}
.searchKeywords #inputKeyword {
height: 45px;
width: 150px;
border: 2px solid;
}
.searchKeywords #submitKeyword {
display: inline-block;
width: 115px;
height: 45px;
border: 1px solid #000;
background-image: url('/www/assets/newImages/gallery/Lupa.png');
background-repeat: no-repeat;
background-position: center;
vertical-align: middle;
}
Check this link http://jsfiddle.net/amoljawale/B45P5/1/
I suggest to go with display:table. Also use margin: auto instead of text-align:center to align your elements in the middle.
css
.searchKeywords {
height: 100%;
display: table;
margin: auto;
position: relative;
top: 70px;
}
.searchKeywords #inputKeyword {
display: table-cell;
height: 45px;
width: 150px;
border: 2px solid;
}
.searchKeywords #submitKeyword {
display: table-cell;
width: 115px;
height: 45px;
border: 1px solid #000;
background-image: url('/www/assets/newImages/gallery/Lupa.png');
background-repeat: no-repeat;
background-position: center;
}
fiddle

How to exclude an element from css?

Note:
I've looked around at other threads, but I can't seem to get the answers there to work.
I've been trying to exclude "#menu" from the margin property in "body{}" so that it doesn't overlap the text.
My code:
body {
text-align: center;
background: black;
background: url("http://tuxlink.files.wordpress.com/2010/04/snow-leopard-server-wallpaper.jpg");
font-family: Helvetica;
background-size: 100%;
background-position: center center;
background-repeat: no-repeat;
color: black;
background-attachment: fixed;
background-size: cover;
font-size: 20px;
margin: 15%;
}
#menu{
position: absolute;
color: white;
position: fixed;
background-attachment: fixed;
border: 5px;
background-color: grey;
background-size: contain;
border-style: ridge;
border-color: grey;
width: 150px;
text-align: left;
float: left;
}
Override the CSS from the body with the CSS for the menu:
#menu { border: none; border-width: 5px; }
Add anything else you might need in there.
If you are trying to make the margin on #menu be reset to the default value, you can add margin: none; to your CSS, so that it looks something like this:
body {
text-align: center;
background: black;
background: url("http://tuxlink.files.wordpress.com/2010/04/snow-leopard-server-wallpaper.jpg");
font-family: Helvetica;
background-size: 100%;
background-position: center center;
background-repeat: no-repeat;
color: black;
background-attachment: fixed;
background-size: cover;
font-size: 20px;
margin: 15%;
}
#menu{
position: absolute;
color: white;
position: fixed;
background-attachment: fixed;
border: 5px;
background-color: grey;
background-size: contain;
border-style: ridge;
border-color: grey;
width: 150px;
text-align: left;
float: left;
margin: none;
}
That should do the trick!
probably it was what inside your #menu
#menu{
position:absolute; <-- this are interfering with your margins
color:white;
position:fixed; <-- this are interfering with your margins
float:left; <-- this are interfering with your margins
margin: none; <-- remove that and try set the margin here (eg: margin: 10px;)
}