What is the best way to position an element on the left side of the navbar without having it animated?

Could someone assist me in placing the Life's Good logo on the left side of the nav bar without applying the animation from the "btn" class? Below is a snippet of my code with an example where I want the logo highlighted in Yellow:

* {
padding:0;
margin: 0;
}

body {
  font-family: "Roboto";
  color: #fff;
  letter-spacing:1px;
}

a {
  text-decoration: none;
}

.nav-bar {
  padding-top: 18px;
  background: #ffffff;
  padding-bottom: 50px;
  position: relative;
  text-align: center;
  color: black;
}

#main {
  position: relative;
  margin-top: px;
  text-align: left;
}

.btn{
  display: inline-block;
  padding: 15px 40px;
  cursor: pointer;
  letter-spacing: 2px;
  position:relative;
  overflow:hidden;
  margin: 0 1px;
  outline: none;
}

.btn:before {
  content: "";
  position: absolute;
  width: 0;
  background : rgb(0, 0, 0);
  left: 45%;
  height: 2px;
  bottom: 0;
  transition: all .3s;
  opacity: 0.7;
}

.btn:hover:before {
  width: 100%;
  left:0;
}
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>Life's Good</title>
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" href="css/stylesheet.css">
        <link href='https://fonts.googleapis.com/css?family=Roboto' rel='stylesheet' type='text/css'>
        <link rel="icon" href="images/favicon.png">
    </head>
    <body>
        <div class="nav-bar">
                <div id="main"><img src="images/logos/8870080_sunny_sun_beach_cloud_icon (3).png" alt="">Life's Good</div>
                <div class="btn"><a href="index.html" title="">Home</a></div>
                <div class="btn"><a href="#" title="">News</a></div>
                <div class="btn"><a href="#" title="">Gaming</a></div>
                <div class="btn"><a href="#" title="">Books</a></div>
                <div class="btn"><a href="#" title="">Coding</a></div>
                <div class="btn"><a href="#" title="">Contact</a></div>
        </div>
    </body>
</html>

Click here to see the Yellow Area where I want the Logo ("Life's Good")

Answer №1

The issue here is that you forgot to add a number next to px in the margin-top property of #main. It might also be helpful to include a value for margin-left.

If you're looking to exclude the animation from a specific element, you can use the :not() CSS selector to deselect #main.

.btn:before:not(#main)

Answer №2

Ensure that you set position: absolute for the #main element. By doing so, #main will be positioned absolutely in relation to its parent container, which in this case is .nav-bar, as the position of .nav-bar is set to relative.

Afterwards, adjust the margin property of #main based on your requirements. For example, you can use a margin value like margin: 15px 0 15px 75px (top right bottom left).

* {
padding:0;
margin: 0;
}

body {
  font-family: "Roboto";
  color: #fff;
  letter-spacing:1px;
}

a {
  text-decoration: none;
}

.nav-bar {
  padding-top: 18px;
  background: #ffffff;
  padding-bottom: 50px;
  position: relative;
  text-align: center;
  color: black;
}

#main {
  position: absolute;
  margin: 15px 0 15px 75px;
  text-align: left;
}
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>Life's Good</title>
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" href="css/stylesheet.css">
        <link href='https://fonts.googleapis.com/css?family=Roboto' rel='stylesheet' type='text/css'>
        <link rel="icon" href="images/favicon.png">
    </head>
    <body>
        <div class="nav-bar">
                <div id="main"><img src="images/logos/8870080_sunny_sun_beach_cloud_icon (3).png" alt="">Life's Good</div>
                <div class="btn"><a href="index.html" title="">Home</a></div>
                <div class="btn"><a href="#" title="">News</a></div>
                <div class="btn"><a href="#" title="">Gaming</a></div>
                <div class="btn"><a href="#" title="">Books</a></div>
                <div class="btn"><a href="#" title="">Coding</a></div>
                <div class="btn"><a href="#" title="">Contact</a></div>
        </div>
    </body>
</html>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Show the "Splash" picture, then switch to a newly uploaded image and show it for a set amount of time

I am in the process of developing an HTML/JavaScript page that will showcase a splash image (splash.jpg) until it gets replaced by another image file called latest.jpg. Once this latest.jpg is displayed, I want it to remain on the screen for 90 seconds bef ...

What steps do I need to follow in order to utilize Express Generator to create a node skeleton with an HTML view

Is there a way to create a skeleton for Node.js using Express generator with an HTML view engine? For example, we typically do npm install -g express-generator express -v pug but it seems we cannot create a skeleton for express -v html ...

Setting a const value (true or false) based on the size of the window - a step-by-step guide

While studying, I encountered a challenge: In the code below, I need to dynamically set useState(false) based on the screen size. If the screen is larger than 947px, for instance, it should automatically be changed to true. The issue arises because sett ...

I am struggling to make php redirect work using onclick() function

My PHP button is not redirecting properly. Assuming the page destination is correct, is there anything else that could be causing this issue? echo "<button id=\"create\" onclick=\"location.href('/team/teams.php?op=create');&bso ...

I'm new to this, but can someone explain why I'm being redirected to the register_db.php page when I click on the register button?

Why when I click the register button, it redirects me to the register_db.php page instead of sending the data to the database and keeping me on the same register.php page? I want the data to be sent to the database without changing the webpage. register.p ...

Struggling to choose an element within $(this) despite being able to view it in the $(this) outerHTML

I have a question regarding jQuery 1.12. I am attempting to target an element within $(this). $(".select").bind('keydown', function(event) { elt = $(this)[0]; console.log(elt.outerHTML); elt = $(this)[0].search("li") console.log ...

CSS for leaving white space at the end of one third of a container

Currently developing a website and facing an issue with the layout: I am trying to create 3 columns of equal height with each column taking up one-third of the width. However, there seems to be a small white gap on the right side of the last column. Here ...

Utilize Jquery to locate and update the text of all div elements that have an empty id attribute

I need help with a task involving a list of divs, some with ids and some without. My goal is to identify all the divs within a specific class that have empty ids and change their inner text to say "no data available". Can this be done? My attempt using $( ...

Extracting Data from JSON Using Vue.js

I am facing an issue with extracting data from a JSON file using Vue.js. Below is the HTML and JSON data along with the script. Any help would be appreciated. <!DOCTYPE html> <html> <head> <title>Vu ...

Guidelines for calculating the CRC of binary data using JQuery, javascript, and HTML5

Can you please assist me with the following issue? Issue: I am currently reading file content using the HTML5 FileReaderAPI's ReadAsArrayBuffer function. After storing this buffer in a variable, I now need to compute the CRC (Cyclic Redundancy Check) ...

What is the best way to align an image underneath text?

I'm currently working on this design concept: https://i.stack.imgur.com/wJm0t.png Below the title, there is a particle image with half square images positioned on the top right and bottom left corners. My goal is to center the particle image below th ...

Displaying a submenu upon hovering within its designated CSS region

I'm encountering an issue with my submenu. It's supposed to appear when hovering over the parent menu li, but it also shows up when the mouse hovers over its area. Let's take a look at some images. First screenshot below shows that it works ...

Is there a way to pass locale data using props in VueJS Router?

To access hotel data, the URL path should be localhost:8080/hotel/:id (where id is equal to json.hoteID). For example, localhost:8080/hotel/101 This path should display the specific data for that hotel. In order to achieve this, we will utilize VueJS vu ...

The printing function for the window system can cause disruptions to the layout of the table

After creating a page with a simple table that can be filled in and printed, I noticed some issues with the table formatting after printing. The intended table design was supposed to look like this: https://i.stack.imgur.com/aAk89.png However, upon print ...

Challenges with line height in IE when adjusting font size in textarea

I'm facing an issue with adjusting the font size in a textarea using JavaScript. While it works perfectly in Firefox, there are some problems in IE. Specifically, the line-height does not change accordingly. This results in gaps between lines when the ...

Having trouble capturing a photo from webcam using HTML5 and getUserMedia() in Google Chrome upon initial page load

Using the information from an article on HTML5Rocks, I am attempting to create a tool that can capture photos from a webcam. Here is an excerpt of my HTML code: <button type="button" name="btnCapture" id="btnCapture">Start camera</button>< ...

Can one image impact other images through a wrapping function?

I am facing an issue with positioning 3 images independently from the window size using the position: relative declaration. When I try to define positions for the first 2 images and then insert the third one, it disrupts the position of the first two. Is ...

HTML5 footer element is the perfect way to add a

I'm currently working on creating a footer that stretches across the entire width of the screen. Originally, I had it nested within the body tag which was centered with a width of 825px. To remove this width constraint, I moved the footer under the ht ...

Submenu Positioning Problem Identified in Firefox Display

I am currently working on a menu design for a website and encountered an unusual issue while testing it in Firefox. In the provided fiddle link, you can view the menu layout where hovering over the information button should display a submenu directly below ...

divs aligned vertically on opposite edges of the webpage

Our web app is being embedded in a third party page as an iframe, but we need to add a bottom "toolbar" with 2 links. One link should be plain text and the other should display our company logo preceded by some text. We want the two links to be positioned ...